spyder icon indicating copy to clipboard operation
spyder copied to clipboard

template.py editing is cumbersome and underdocumented

Open nerdoc opened this issue 9 years ago • 14 comments

Currently, only the %(date)s and %(username)s variables in template.py are replaced. There should be some generic other variables like %(projectname)s and others. AND - the documentation for that is missing.

What I would do here: Let the user edit this file (template.py) in the settings (instead of this button "edit template for new modules") and put some explanations there, what the variables are for etc.

nerdoc avatar Dec 27 '15 21:12 nerdoc

It's an interesting idea. I'm marking it as doable for a future Spyder version.

ccordoba12 avatar Dec 28 '15 04:12 ccordoba12

I got the idea from Eclipse. This concept is really good I think. There are more generic templates, for code, and for comments too, depending on which context. PyDev comments of new modules look like

"""
Created on ${date}

@author: ${user}
"""
${cursor}

But this is completely configurable within the preferences dialog.

And furthermore, you could add optional default LICENSE headers, that are added to each file at the top.

nerdoc avatar Dec 29 '15 01:12 nerdoc

If we are going in this direction let's use jinja2. It is already a (indirect) dependency for spyder and is a well defined and documented templating language.

goanpeca avatar Dec 29 '15 02:12 goanpeca

Ok - isn't that a bit overkill, using a whole template language with loops etc, for just having a few variables? It could be done by just replacing ${.*} with the variables?

nerdoc avatar Dec 29 '15 23:12 nerdoc

We start with few variables and after some months we end up having to maintain and document a "simple home made template language"... not a chance.

I prefer having an "overkill" (well defined proven stable and maintained) template language, that already is included when spyder is installed, than having to put a burden (however minimal) on the developer team

goanpeca avatar Dec 29 '15 23:12 goanpeca

Eclipse did it like that and that probably makes sense for Eclipse, (which is coded in Java)

@ccordoba12 I am :-1: on implementing things like ${user} for Spyder (Python based), if we can use a well known standard like {{user}}, even more if it is already a dependency.

goanpeca avatar Dec 29 '15 23:12 goanpeca

Ok, FULL ACK. Seems really comprehensible.

nerdoc avatar Dec 29 '15 23:12 nerdoc

Python has a string template, which is proven stable and maintained, and is not overkill. Using jinja to replace a few variables is really overkill, it's better to keep it as an indirect dependency rather than a hard one. But the main point of the issue is to be able to edit the template directly in the preferences.

Nodd avatar Mar 04 '16 15:03 Nodd

Agree with @nodd, we can use string template ;-)

goanpeca avatar Mar 04 '16 22:03 goanpeca

Hi, has there any work done on this? I would love to contribute with this.

manmartgarc avatar Jun 08 '19 18:06 manmartgarc

Nop, you're welcome to work on it. Please read our Contributing guide before starting:

https://github.com/spyder-ide/spyder/blob/master/CONTRIBUTING.md

ccordoba12 avatar Jun 10 '19 18:06 ccordoba12

File Name: ${file} would be a nice addition, as well.

myidealab avatar Aug 30 '19 00:08 myidealab

Having usable variables like PyCharm's would be good, especially the configurable ones. For instance, my group anaconda's python in a standardized location, but can be changed based on an environment variable, or is updated (and renamed to reflect) when new features are added, so having the ability to read an environment variable to generate the shebang would be nice.

TheReverendWilson avatar Dec 17 '21 15:12 TheReverendWilson

bump!

  • It is good to be able to edit template.py in in the settings (instead of this button "edit template for new modules") as @nerdoc proposed.
  • allow format the date
  • all add other plcaeholder just like %(date) for filename, projectname, ...

kookma avatar Feb 09 '24 05:02 kookma