First time here? Check out the FAQ!
-1

Automatic python module header

is there a way with new file to automatically setup a header __author__ = "One solo developer" __authors__ = ["One developer", "And another one", "etc"] __contact__ = "mail@example.com" __copyright__ = "Copyright $YEAR, $COMPANY_NAME" __credits__ = ["One developer", "And another one", "etc"] __date__ = "YYYY/MM/DD" __deprecated__ = False __email__ = "mail@example.com" __license__ = "GPLv3" __maintainer__ = "developer" __status__ = "Production" __version__ = "0.0.1"

catchthemonster's avatar
1
catchthemonster
asked 2023-11-28 08:24:55 -0500
Wingware Support's avatar
4.1k
Wingware Support
updated 2024-01-08 09:02:46 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

5 Answers

1

Thanks for the answer but this is kind of confusing. """In Wing Pro the Snippets tool includes a 'file' snippet that can be edited to adjust to your local form. That should appear in the auto-completer so you can create a new file, type 'file' and select the completion, and get your standard header."""

First, if we are going to be precise, In Wing Pro the Snippets tool includes a 'file' snippet that can be edited to adjust to your local form - i kind of figured it out to go to .wingpro9/scripts and create a script in Python that could be used to inject a header. """That should appear in the auto-completer so you can create a new file, type 'file' and select the completion, and get your standard header. """ First auto-compreter does not exist! Ether is auto-completion or it does not exist! you can't type anywhere in the window and there is no reference to file or script or anything like that.

I think that you folks are assuming that I am experienced with wingpro, but I am not! I am very good with Python and I used for god knows how long PyCharm with which I am disappointed and want to switch. I am ok to learn, but honestly, I need to work on AI and ML and I cannot learn up and down IDE. Is it possible for anyone to give me a simple example that I can easily extend? I need to know how to wire any template Python or any template library to wherever and when I click on the new Python module an create file I have pre pre-populated header ...

answered 2023-12-03 12:26:12 -0500
This post is a wiki. Anyone with karma >75 is welcome to improve it.
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
1

I think what you're looking for is "every time I create a new python file, populate it with a standard template." That doesn't exist in Wing (AFAICT), but you can get very close.

I'm going to assume you are using Wing Pro, as this does not work on Wing 101 or Wing Personal.

Let's make sure you are set up first.

  1. File->Preferences
  2. in the left column find the "Editor" section, and under there, click on Auto-Completer
  3. Make sure that "show auto completer" is set to True.

Now let's use the auto-completer with a snippet

  1. File->New
  2. Start typing the word "file"
  3. The auto-completer should pop up. About five entries down, you'll see a picture of scissors and the words "file (snippet)". Pick that.
  4. The standard file snippet will be pasted into your file.

To edit the snippet

  1. Click on the "snippets" tab/tool. (It is in the upper right toolbox by default. If you don't see it, look for instructions below on how to add it.)
  2. The system will show you a list of available snippets. One of those snippets will be named "file". Right-click on that.
  3. Choose "Edit Snippet"
  4. Now you can customize the "file" snippet to be whatever you want. (For bonus points, create your own module snippet and use that instead! You have the power!)

If you can't see the snippets tool:

  1. Right click in the blank space on any toolbox window (next to the tabs that say "search", "search in files", etc
  2. Choose "insert tool"
  3. Choose snippets from the list of tools
Chris Curvey's avatar
246
Chris Curvey
answered 2023-12-04 06:22:19 -0500
edit flag offensive 0 remove flag delete link

Comments

1

Chris thank you this helped. I am using wingpro 9.x

File->Preferences in the left column find the "Editor" section, and under there, click on Auto-Completer Make sure that "show auto completer" is set to True. --This part doe snot exist, but auto-complete does ... in the section of options there is nothing that signifies True. file and snippets section worked and that was great... I can edit snippet... So variables like $AUTHOR come from? is it unix env that vars are picked up. What I mean if I edit .bahsrc and add bunch of exports like AUTHOR AUTHOR_EMAIL this will be picked up and subed in template? @purpose I guess is an array ... I am trying to figure out where these attributes are defined so that I can add mine and customize it ... If I create my own module to pick up the stuff from env, I coudl ... (more)

catchthemonster's avatar catchthemonster (2023-12-04 06:58:38 -0500) edit

The preference is actually Editor > Auto-completion > Auto-show Completer and should be set to Always, at least for now. The default behavior of Wing out of the box is that setting and a completer should show whenever you type in the editor. If that's not happening, it's a problem we should diagnose.

Wingware Support's avatar Wingware Support (2023-12-04 10:35:35 -0500) edit

AUTHOR and AUTHOR_EMAIL are environment variables intended to be set in the environment, either outside of Wing so it inherits those at startup or you can also set or override these values in Environment in Wing's Project Properties. These names are arbitrary and can be changed to anything.

Wingware Support's avatar Wingware Support (2023-12-04 10:39:33 -0500) edit

The somewhat odd %(author|string|$(AUTHOR))s syntax for specifying values to insert into snippets is explained in https://wingware.com/doc/edit/snippet-s… -- It's %() with up to three | separated things in it, the first is the name of the value which is arbitrary, the second the type, and the third the default value, often an environment variable reference in the form $(VALUE). There are some additional annotations like @ to tell Wing to auto-wrap the value and other marks to control auto-indentation of snippets when inserted.

Wingware Support's avatar Wingware Support (2023-12-04 10:42:56 -0500) edit

One other note: To create a new file and populate it with the 'file' snippet, you can execute the command snippet-file(snippet_name='file'). This can either be done with Edit > Command by Name (inconvenient but a way to test it out) or by binding that command to a key in the User Interface > Keyboard > Custom Key Bindings preference, or by adding a custom toolbar item with that command. That'll create a Python file. To select another file type it's snippet-file(snippet_name='file', mime_type='text/html', context='content') where the mime type is the one shown in the tool tip above the tabs in the Snippets tool and the context is what's in the Context column below those.

Wingware Support's avatar Wingware Support (2023-12-04 10:58:53 -0500) edit
add a comment see more comments
1

let's see...

If I make my snippet look like this:

__author__ = "%(MYNAME||$(USERNAME))s"

I can't quite figure out where the MYNAME variable can be set...but if I default it to $(USERNAME) (after the double-pipe), I get the value of the USERNAME environment variable.

Chris Curvey's avatar
246
Chris Curvey
answered 2023-12-04 07:19:48 -0500
edit flag offensive 0 remove flag delete link

Comments

MYNAME is just an arbitrary name for the field and would be shown if collecting the value from the user, which in this case isn't done because a default value is specified so it's basically just a name to make it clear what the snippet field is. The snippet syntax is a bit weird from a long time ago before we realized that any more complex sort of text insertion would be better done by writing Python code that calls the scripting API. So there are aspects of it that were designed with more advanced features in mind that we never ended up adding because scripting is just a better model for more than basic things.

Wingware Support's avatar Wingware Support (2023-12-04 10:46:24 -0500) edit
add a comment see more comments
0

In Wing Pro the Snippets tool includes a 'file' snippet that can be edited to adjust to your local form. That should appear in the auto-completer so you can create a new file, type 'file' and select the completion, and get your standard header. Or you can right-click on the 'file' snippet in the Snippets tool and select Paste Into New File.

There are ways to fill in dates, the contents of environment variables, etc. The tool and snippets syntax is documented here:

https://wingware.com/doc/edit/snippets

Note that if you have more complex use cases, you could also write an extension script to do this to either paste in some text or create a new file with text already in it. Extension scripts are written in Python so are more flexible and powerful. Details on that are here:

https://wingware.com/doc/scripting

Wingware Support's avatar
4.1k
Wingware Support
answered 2023-11-28 08:35:50 -0500
edit flag offensive 0 remove flag delete link

Comments

Folks, this is a project in its own! Not cool and not working... I followed scripting guide, and nothing is working... saving a test.py script to ~/.winpro9/scripts directory and following edit menu reload and command by name does not show anything anywhere. No offence to devs, but explaining something via text without any image is hard to follow. Messages window displays all missing or loaded script and there is no test.py script.

bellow just does not work Executing the Script

Try executing the script by selecting Command by Name in the Edit menu. This displays an entry area at the bottom of the window, where you can type test-script and then press the Enter key. Since the script has an argument without a default value, Wing will collect that in the same entry area at the bottom of the IDE window. Type a string and then press Enter. The script ...

(more)
catchthemonster's avatar catchthemonster (2023-12-11 08:04:25 -0500) edit

When you Reload All Scripts, is there an error shown in the Scripts channel of the Messages tool, which is in the Tools menu?

Wingware Support's avatar Wingware Support (2023-12-11 08:58:04 -0500) edit

Also, how are you launching Wing? It's odd that it does not inherit the env set in .profile or .bashrc.

Wingware Support's avatar Wingware Support (2023-12-11 08:59:37 -0500) edit

And finally, we do offer refunds for anyone that purchases and finds out Wing doesn't meet their needs. Just email sales@wingware.com.

Wingware Support's avatar Wingware Support (2023-12-11 09:00:55 -0500) edit
add a comment see more comments
0

Hello and happy 2024! Snippet's do work for Python headers with project-> ProjectProperties and env variables in key=value format

That works Now could someone explain how to add for example FileName variable to snippet to actually pick up a file name of just created python module that has applies file snippet.

Eample:

""" Project: %(project|string|$(PROJECT))s Coding: utf-8 Author: %(author|string|$(AUTHOR))s --<%(email||$(AUTHOREMAIL))s> FileName: %(@FileName) Purpose: %(@purpose|string(512))s Created: %(created|date)s """

wingpro does show that property option but when applied I get blank string or FileName FileName: %(@FileName)

maybe I am doing something wrong again? Thanks

catchthemonster's avatar
1
catchthemonster
answered 2024-01-02 10:50:53 -0500, updated 2024-01-03 08:03:30 -0500
edit flag offensive 0 remove flag delete link

Comments

$(WING:FILENAME) will be replaced with the name of the current file. This only works if pasting the snippet into the current file and not if creating a new file with the snippet, since then it doesn't know the filename yet.

Wingware Support's avatar Wingware Support (2024-01-02 14:28:20 -0500) edit

Thank for the help. FileName: %(filename|string|$(WING:FILENAME))s

worked essentially as a full path It would be nice to know what other WING variables are in existence that could be added to headers...?

wingpro10 is great with Python 3.12.1 Amazing feature of winpro is how fast this application is ... Bootstrapping takes like milliseconds... Comparing to other Python IDE's winpro flies ... Thank you for being patient and kind ...

Regards,

catchthemonster's avatar catchthemonster (2024-01-02 16:00:48 -0500) edit

Yes, I forgot to add the link to the docs for the WING:* special envs: https://wingware.com/doc/proj/variable-…

It sounds like we should add WING:FILENAME_BASE or something like that for just the filename...

Glad to hear it's running well for you. Yes, it's nice to have it start quickly, which it does for most people although I think it can be slower on Windows due to more difficult to optimize Windows-specific issues mostly, I think, in Qt and/or I/O subsystems.

Wingware Support's avatar Wingware Support (2024-01-02 18:58:28 -0500) edit

Special env WING:FILENAME_BASE will be in the next Wing 10 release (10.0.0.4+). Thanks for pointing out the need for that.

Wingware Support's avatar Wingware Support (2024-01-08 09:29:24 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer