From: W. Trevor King Date: Thu, 25 Oct 2012 21:02:25 +0000 (-0400) Subject: Upgrade to Python 3.2 X-Git-Tag: v0.5~14 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=89a0d1e54f4ee7a11e08c1df53dd5197b0bbe246;p=update-copyright.git Upgrade to Python 3.2 bzrlib and mercurial aren't Python 3 compatible yet (and seem unlikely to become compatible in the near future), so if you're using them, you should stick with an older version of update-copyright. Note that the version of Python used by update-copyright has nothing to do with the version of Python you use in your project. You project doesn't even have to use Python at all. --- diff --git a/update_copyright/project.py b/update_copyright/project.py index 2a2c33a..c7814a8 100644 --- a/update_copyright/project.py +++ b/update_copyright/project.py @@ -17,7 +17,7 @@ """Project-specific configuration.""" -import ConfigParser as _configparser +import configparser as _configparser import fnmatch as _fnmatch import os.path as _os_path import sys @@ -55,7 +55,7 @@ class Project (object): self._width = 79 # unlikely to occur in the wild :p - self._copyright_tag = u'-xyz-COPY' + u'-RIGHT-zyx-' + self._copyright_tag = '-xyz-COPY' + '-RIGHT-zyx-' def load_config(self, stream): parser = _configparser.RawConfigParser() @@ -175,8 +175,8 @@ class Project (object): def update_authors(self, dry_run=False): _LOG.info('update AUTHORS') authors = self._vcs.authors() - new_contents = u'{} was written by:\n{}\n'.format( - self._name, u'\n'.join(authors)) + new_contents = '{} was written by:\n{}\n'.format( + self._name, '\n'.join(authors)) _utils.set_contents( _os_path.join(self._root, 'AUTHORS'), new_contents, unicode=True, encoding=self._encoding, @@ -222,35 +222,35 @@ class Project (object): _utils.copyright_string( original_year=original_year, final_year=current_year, authors=authors, text=self._copyright, info=self._info(), - prefix=u'# ', width=self._width), - u'', u'import textwrap as _textwrap', u'', u'', - u'LICENSE = """', + prefix='# ', width=self._width), + '', 'import textwrap as _textwrap', '', '', + 'LICENSE = """', _utils.copyright_string( original_year=original_year, final_year=current_year, authors=authors, text=self._copyright, info=self._info(), - prefix=u'', width=self._width), - u'""".strip()', - u'', - u'def short_license(info, wrap=True, **kwargs):', - u' paragraphs = [', + prefix='', width=self._width), + '""".strip()', + '', + 'def short_license(info, wrap=True, **kwargs):', + ' paragraphs = [', ] paragraphs = _utils.copyright_string( original_year=original_year, final_year=current_year, authors=authors, text=self._short_copyright, info=self._info(), author_format_fn=_utils.short_author_formatter, wrap=False, - ).split(u'\n\n') + ).split('\n\n') for p in paragraphs: - lines.append(u" '{}' % info,".format( - p.replace(u"'", ur"\'"))) + lines.append(" '{}'.format(info),".format( + p.replace("'", r"\'"))) lines.extend([ - u' ]', - u' if wrap:', - u' for i,p in enumerate(paragraphs):', - u' paragraphs[i] = _textwrap.fill(p, **kwargs)', - ur" return '\n\n'.join(paragraphs)", - u'', # for terminal endline + ' ]', + ' if wrap:', + ' for i,p in enumerate(paragraphs):', + ' paragraphs[i] = _textwrap.fill(p, **kwargs)', + r" return '\n\n'.join(paragraphs)", + '', # for terminal endline ]) - new_contents = u'\n'.join(lines) + new_contents = '\n'.join(lines) _utils.set_contents( filename=self._pyfile, contents=new_contents, unicode=True, encoding=self._encoding, dry_run=dry_run) diff --git a/update_copyright/utils.py b/update_copyright/utils.py index 1172351..b8b4df9 100644 --- a/update_copyright/utils.py +++ b/update_copyright/utils.py @@ -32,9 +32,9 @@ ENCODING = _locale.getpreferredencoding() or _sys.getdefaultencoding() def long_author_formatter(copyright_year_string, authors): """ - >>> print '\\n'.join(long_author_formatter( + >>> print('\\n'.join(long_author_formatter( ... copyright_year_string='Copyright (C) 1990-2010', - ... authors=['Jack', 'Jill', 'John'])) + ... authors=['Jack', 'Jill', 'John']))) Copyright (C) 1990-2010 Jack Jill John @@ -46,9 +46,9 @@ def long_author_formatter(copyright_year_string, authors): def short_author_formatter(copyright_year_string, authors): """ - >>> print '\\n'.join(short_author_formatter( + >>> print('\\n'.join(short_author_formatter( ... copyright_year_string='Copyright (C) 1990-2010', - ... authors=['Jack', 'Jill', 'John']*5)) + ... authors=['Jack', 'Jill', 'John']*5))) Copyright (C) 1990-2010 Jack, Jill, John, Jack, Jill, John, Jack, Jill, John, Jack, Jill, John, Jack, Jill, John """ blurb = '%s %s' % (copyright_year_string, ', '.join(authors)) @@ -159,7 +159,7 @@ def tag_copyright(contents, prefix=('# ', '# ', None), tag=None): ... (copyright ends) ... bla bla bla ... ''' - >>> print tag_copyright(contents, tag='-xyz-CR-zyx-') + >>> print(tag_copyright(contents, tag='-xyz-CR-zyx-')) Some file bla bla -xyz-CR-zyx- @@ -176,8 +176,8 @@ def tag_copyright(contents, prefix=('# ', '# ', None), tag=None): ... (copyright ends) ... bla bla bla ... ''' - >>> print tag_copyright( - ... contents, prefix=('/* ', ' * ', ' */'), tag='-xyz-CR-zyx-') + >>> print(tag_copyright( + ... contents, prefix=('/* ', ' * ', ' */'), tag='-xyz-CR-zyx-')) Some file bla bla -xyz-CR-zyx- @@ -214,10 +214,10 @@ def update_copyright(contents, prefix=('# ', '# ', None), tag=None, **kwargs): ... (copyright ends) ... bla bla bla ... ''' - >>> print update_copyright( + >>> print(update_copyright( ... contents, original_year=2008, authors=['Jack', 'Jill'], ... text=['BLURB',], prefix=('# ', '# ', None), tag='--tag--' - ... ) # doctest: +ELLIPSIS, +REPORT_UDIFF + ... )) # doctest: +ELLIPSIS, +REPORT_UDIFF Some file bla bla # Copyright (C) 2008-... Jack @@ -257,7 +257,7 @@ def set_contents(filename, contents, original_contents=None, unicode=False, _LOG.info('creating {}'.format(filename)) else: _LOG.info('updating {}'.format(filename)) - _LOG.debug(u'\n'.join( + _LOG.debug('\n'.join( _difflib.unified_diff( original_contents.splitlines(), contents.splitlines(), fromfile=_os_path.normpath( diff --git a/update_copyright/vcs/bazaar.py b/update_copyright/vcs/bazaar.py index 27aac6a..e9ad75f 100644 --- a/update_copyright/vcs/bazaar.py +++ b/update_copyright/vcs/bazaar.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License along with # update-copyright. If not, see . -import StringIO as _StringIO +import io as _io import os as _os import bzrlib as _bzrlib @@ -66,7 +66,7 @@ class BazaarBackend (_VCSBackend): def _years(self, filename=None): cmd = _bzrlib_builtins.cmd_log() - cmd.outf = _StringIO.StringIO() + cmd.outf = _io.StringIO() kwargs = {'log_format':_YearLogFormatter, 'levels':0} if filename is not None: kwargs['file_list'] = [filename] @@ -76,7 +76,7 @@ class BazaarBackend (_VCSBackend): def _authors(self, filename=None): cmd = _bzrlib_builtins.cmd_log() - cmd.outf = _StringIO.StringIO() + cmd.outf = _io.StringIO() kwargs = {'log_format':_AuthorLogFormatter, 'levels':0} if filename is not None: kwargs['file_list'] = [filename] @@ -86,6 +86,6 @@ class BazaarBackend (_VCSBackend): def is_versioned(self, filename): cmd = _bzrlib_builtins.cmd_log() - cmd.outf = StringIO.StringIO() + cmd.outf = _io.StringIO() self._bzr_cmd(cmd=cmd, file_list=[filename]) return True diff --git a/update_copyright/vcs/mercurial.py b/update_copyright/vcs/mercurial.py index b2810b2..c3492d2 100644 --- a/update_copyright/vcs/mercurial.py +++ b/update_copyright/vcs/mercurial.py @@ -17,7 +17,7 @@ from __future__ import absolute_import -import StringIO as _StringIO +import io as _io import os as _os import sys as _sys @@ -40,8 +40,8 @@ class MercurialBackend (_VCSBackend): cwd = _os.getcwd() stdout = _sys.stdout stderr = _sys.stderr - tmp_stdout = _StringIO.StringIO() - tmp_stderr = _StringIO.StringIO() + tmp_stdout = _io.StringIO() + tmp_stderr = _io.StringIO() _sys.stdout = tmp_stdout _sys.stderr = tmp_stderr _os.chdir(self._root) diff --git a/update_copyright/vcs/utils.py b/update_copyright/vcs/utils.py index bafc1da..b1537c6 100644 --- a/update_copyright/vcs/utils.py +++ b/update_copyright/vcs/utils.py @@ -127,7 +127,7 @@ def reverse_aliases(aliases): ... } >>> r = reverse_aliases(aliases) >>> for item in sorted(r.items()): - ... print item + ... print(item) ('Anonymous ', None) ('J', 'J Doe ') ('Jingly ', 'JJJ Smith ') @@ -166,9 +166,12 @@ def replace_aliases(authors, with_email=True, aliases=None): for i,author in enumerate(authors): if author in rev_aliases: authors[i] = rev_aliases[author] - authors = sorted(list(set(authors))) - if None in authors: + authors = set(authors) + try: authors.remove(None) + except KeyError: + pass + authors = sorted(authors) if with_email == False: authors = strip_email(*authors) return authors