Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way %(date)s and %(username)s are dealt with in template.py #6379

Open
chengtian5huang opened this issue Feb 4, 2018 · 5 comments · May be fixed by #21706
Open

Change the way %(date)s and %(username)s are dealt with in template.py #6379

chengtian5huang opened this issue Feb 4, 2018 · 5 comments · May be fixed by #21706

Comments

@chengtian5huang
Copy link

maybe we should only replace placeholder between the tripe-double-quotes(“”“...”“”)

if u use this template.py

# -*- coding: utf-8 -*-
"""
Created on %(date)s

Creator: yourname
"""
from logging import debug as LD
from logging import info as LI
import logging as log
log.basicConfig(level=log.DEBUG,
               format='%(levelname)s|%(funcName)s|line:%(lineno)d - %(message)s')
log.disable(log.DEBUG)
#log.disable(log.CRITICAL)

u will get this

# -*- coding: utf-8 -*-
"""
Created on %(date)s

Creator: yourname
"""
from logging import debug as LD
from logging import info as LI
import logging as log
log.basicConfig(level=log.DEBUG,
               format='%(levelname)s|%(funcName)s|line:%(lineno)d - %(message)s')
log.disable(log.DEBUG)
#log.disable(log.CRITICAL)

but of course we r expecting this

# -*- coding: utf-8 -*-
"""
Created on 2018-2-4

Creator: yourname
"""
from logging import debug as LD
from logging import info as LI
import logging as log
log.basicConfig(level=log.DEBUG,
               format='%(levelname)s|%(funcName)s|line:%(lineno)d - %(message)s')
log.disable(log.DEBUG)
#log.disable(log.CRITICAL)

the %(date)s has not been replaced properly because there is more placeholder

format='%(levelname)s|%(funcName)s|line:%(lineno)d - %(message)s')

in this template.py

in the code dealing with template.py

spyder

if we take the part between tripe-double-quotes seperately and deal with it seperately we can replace %(date)s properly no matter what a man add in template.py

i edit the edior.py as following,and it worked.

        if text is None:
            default_content = True
            text, enc = encoding.read(self.TEMPLATE_PATH)
            enc_match = re.search('-*- coding: ?([a-z0-9A-Z\-]*) -*-', text)
            annotation_match = re.search('"""(?:(?!""").|[\n\r])*"""', text)
            if enc_match:
                enc = enc_match.group(1)
            # Initialize template variables
            # Windows
            username = encoding.to_unicode_from_fs(os.environ.get('USERNAME',
                                                                  ''))
            # Linux, Mac OS X
            if not username:
                username = encoding.to_unicode_from_fs(os.environ.get('USER',
                                                                      '-'))
            VARS = {
                'date': time.strftime("%Y-%m-%d %H:%M"),
                'username': username,
            }
            try:
                #text = text % VARS
                text = re.sub('"""(?:(?!""").|[\n\r])*"""',
                              annotation_match[0] % VARS,
                              text,
                              count=1)
            except:
                pass
chengtian5huang added a commit to chengtian5huang/spyder that referenced this issue Feb 4, 2018
take the part between tripe-double-quotes seperately and deal with it seperately we can replace %(date)s properly no matter what a man add in template.py
chengtian5huang added a commit to chengtian5huang/spyder that referenced this issue Feb 5, 2018
@CAM-Gerlach CAM-Gerlach changed the title change the way dealing with %(date)s and %(username)s in the template.py Change the way %(date)s and %(username)s are dealt with in template.py Feb 9, 2018
chengtian5huang added a commit to chengtian5huang/spyder that referenced this issue Feb 9, 2018
chengtian5huang added a commit to chengtian5huang/spyder that referenced this issue Feb 9, 2018
chengtian5huang added a commit to chengtian5huang/spyder that referenced this issue Feb 9, 2018
if there are invaild placeholders in template.py, check line by line to replace vaild placeholders and ignore the invailds.
@CAM-Gerlach CAM-Gerlach added this to the v3.2.x milestone Mar 11, 2018
@Hailprob
Copy link

does anyone know how to change the date format in template.py to ,say, 2018-07-11 22:22:22?

@bcolsen
Copy link
Member

bcolsen commented Jul 13, 2018

@Hailprob It looks like it's hard coded in editor.py so you would have to change spyder code:

'date': time.ctime(),

@ccordoba12 ccordoba12 modified the milestones: v3.x, Not sorted Oct 11, 2018
@hrishikeshrt
Copy link

is this going to be added to the next version of spyder?

@ccordoba12
Copy link
Member

No.

@kookma
Copy link

kookma commented Feb 9, 2024

bump!
The current %(date)s on windows insert something like Fri Feb 9 09:05:58 2024 and this is a bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants