From 6badc540234386ca7a27d3c90b22c565472475f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 11 Sep 2009 22:46:00 +0200 Subject: Add sdist3 command. --HG-- branch : distribute extra : rebase_source : 47f2fee9a8361cabc8160df8dd30dacc67f0f42b --- setuptools/command/__init__.py | 2 +- setuptools/command/sdist3.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 setuptools/command/sdist3.py (limited to 'setuptools/command') diff --git a/setuptools/command/__init__.py b/setuptools/command/__init__.py index f898822b..8f5ba21c 100644 --- a/setuptools/command/__init__.py +++ b/setuptools/command/__init__.py @@ -1,7 +1,7 @@ __all__ = [ 'alias', 'bdist_egg', 'bdist_rpm', 'build_ext', 'build_py', 'develop', 'easy_install', 'egg_info', 'install', 'install_lib', 'rotate', 'saveopts', - 'sdist', 'setopt', 'test', 'upload', 'install_egg_info', 'install_scripts', + 'sdist', 'sdist3', 'setopt', 'test', 'upload', 'install_egg_info', 'install_scripts', 'register', 'bdist_wininst', ] diff --git a/setuptools/command/sdist3.py b/setuptools/command/sdist3.py new file mode 100644 index 00000000..4fbfa8db --- /dev/null +++ b/setuptools/command/sdist3.py @@ -0,0 +1,34 @@ +from distutils import log +from sdist import sdist +from lib2to3.refactor import RefactoringTool, get_fixers_from_package + + +class _RefactoringTool(RefactoringTool): + def log_error(self, msg, *args, **kw): + log.error(msg, *args) + + def log_message(self, msg, *args): + log.info(msg, *args) + + def log_debug(self, msg, *args): + log.debug(msg, *args) + + +class sdist3(sdist): + description = "sdist version that runs 2to3 on all sources before packaging" + fixer_names = None + + def copy_file(self, file, dest, link=None): + # We ignore the link parameter, always demanding a copy, so that + # 2to3 won't overwrite the original file. + sdist.copy_file(self, file, dest) + + def make_release_tree(self, base_dir, files): + sdist.make_release_tree(self, base_dir, files) + + # run 2to3 on all files + fixer_names = self.fixer_names + if fixer_names is None: + fixer_names = get_fixers_from_package('lib2to3.fixes') + r = _RefactoringTool(fixer_names) + r.refactor([f for f in files if f.endswith(".py")], write=True) -- cgit v1.2.3 From 7ee68f0c5fe9122442c3f44aa94ebd1dfcc7b47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 11 Sep 2009 23:23:25 +0200 Subject: Use types.ModuleType instead of new.module. --HG-- branch : distribute extra : rebase_source : 3327441a867ad2878553ed1d42418a7e68ee3067 --- setuptools/command/install_egg_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/install_egg_info.py b/setuptools/command/install_egg_info.py index 939340c5..00c81221 100755 --- a/setuptools/command/install_egg_info.py +++ b/setuptools/command/install_egg_info.py @@ -97,12 +97,12 @@ class install_egg_info(Command): % ('.'.join(pth[:-1]), pth[-1]) ) f.write( - "import sys,new,os; " + "import sys,types,os; " "p = os.path.join(sys._getframe(1).f_locals['sitedir'], " "*%(pth)r); " "ie = os.path.exists(os.path.join(p,'__init__.py')); " "m = not ie and " - "sys.modules.setdefault(%(pkg)r,new.module(%(pkg)r)); " + "sys.modules.setdefault(%(pkg)r,types.ModuleType(%(pkg)r)); " "mp = (m or []) and m.__dict__.setdefault('__path__',[]); " "(p not in mp) and mp.append(p)%(trailer)s" % locals() -- cgit v1.2.3 From c4ea358c7cdcd76dc9bf35b54e22cc9be05dc62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 11 Sep 2009 23:47:38 +0200 Subject: Correct path names for fixed files. --HG-- branch : distribute extra : rebase_source : d5bd9c6fdb8cf2208eca9e0e5f37cb7fea1d14a5 --- setuptools/command/sdist3.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/sdist3.py b/setuptools/command/sdist3.py index 4fbfa8db..fc7ebb97 100644 --- a/setuptools/command/sdist3.py +++ b/setuptools/command/sdist3.py @@ -1,3 +1,4 @@ +import os from distutils import log from sdist import sdist from lib2to3.refactor import RefactoringTool, get_fixers_from_package @@ -31,4 +32,4 @@ class sdist3(sdist): if fixer_names is None: fixer_names = get_fixers_from_package('lib2to3.fixes') r = _RefactoringTool(fixer_names) - r.refactor([f for f in files if f.endswith(".py")], write=True) + r.refactor([os.path.join(base_dir, f) for f in files if f.endswith(".py")], write=True) -- cgit v1.2.3 From c8fafe39c39a6814741b3f2825320c565c02058c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 11 Sep 2009 23:48:25 +0200 Subject: Work around apparent 3.x limitation wrt. variables in list comprehensions. --HG-- branch : distribute extra : rebase_source : 214eb64288ef1955fd06ba1cf594b6a780cccde8 --- setuptools/command/install.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/install.py b/setuptools/command/install.py index a150c435..247c4f25 100644 --- a/setuptools/command/install.py +++ b/setuptools/command/install.py @@ -18,9 +18,6 @@ class install(_install): ('install_scripts', lambda self: True), ] _nc = dict(new_commands) - sub_commands = [ - cmd for cmd in _install.sub_commands if cmd[0] not in _nc - ] + new_commands def initialize_options(self): _install.initialize_options(self) @@ -104,6 +101,10 @@ class install(_install): cmd.run() setuptools.bootstrap_install_from = None +# XXX Python 3.1 doesn't see _nc if this is inside the class +install.sub_commands = [ + cmd for cmd in _install.sub_commands if cmd[0] not in install._nc + ] + install.new_commands -- cgit v1.2.3 From 41854a0e9535b9142811e7815937d15c1a7c5b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 12 Sep 2009 12:36:46 +0200 Subject: Add src_root attribute to support installing from a copy. --HG-- branch : distribute extra : rebase_source : 95242b20ab228862aeef205f399869f79e342f0e --- setuptools/command/build_py.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 79570bc2..3fce7693 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -157,9 +157,11 @@ class build_py(_build_py): _build_py.initialize_options(self) - - - + def get_package_dir(self, package): + res = _build_py.get_package_dir(self, package) + if self.distribution.src_root is not None: + return os.path.join(self.distribution.src_root, res) + return res def exclude_data_files(self, package, src_dir, files): -- cgit v1.2.3 From 0fb87f9bdf3dd85bc4a0e2f17f2a7c98d0d0cf53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 12 Sep 2009 12:38:35 +0200 Subject: Explicitly encode data as UTF-8 before writing to a binary file. --HG-- branch : distribute extra : rebase_source : c9de4f92e3e50dd88fd1d29e2a9b2f3288fd4b88 --- setuptools/command/egg_info.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index a8315d23..46cdf4e0 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -3,7 +3,7 @@ Create a distribution's .egg-info directory and contents""" # This module should be kept compatible with Python 2.3 -import os, re +import os, re, sys from setuptools import Command from distutils.errors import * from distutils import log @@ -148,6 +148,8 @@ class egg_info(Command): to the file. """ log.info("writing %s to %s", what, filename) + if sys.version_info >= (3,): + data = data.encode("utf-8") if not self.dry_run: f = open(filename, 'wb') f.write(data) @@ -351,8 +353,11 @@ def write_file (filename, contents): """Create a file with the specified name and write 'contents' (a sequence of strings without line terminators) to it. """ + contents = "\n".join(contents) + if sys.version_info >= (3,): + contents = contents.encode("utf-8") f = open(filename, "wb") # always write POSIX-style manifest - f.write("\n".join(contents)) + f.write(contents) f.close() -- cgit v1.2.3 From c1098e903f4eab3c673089fb60d3540e28fe0778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 12 Sep 2009 16:58:06 +0200 Subject: Replace os.path.walk with os.walk. --HG-- branch : distribute extra : rebase_source : 9bc223da3173d759f3c59eb72138e7405b4384ed --- setuptools/command/bdist_egg.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 9e852a3f..32cebe9d 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -525,9 +525,11 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, compression = [zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED][bool(compress)] if not dry_run: z = zipfile.ZipFile(zip_filename, mode, compression=compression) - os.path.walk(base_dir, visit, z) + for dirname, dirs, files in os.walk(base_dir): + visit(z, dirname, files) z.close() else: - os.path.walk(base_dir, visit, None) + for dirname, dirs, files in os.walk(base_dir): + visit(None, dirname, file) return zip_filename # -- cgit v1.2.3 From a3efc4cae6bfa2e8a03a7b75380f29c660b876cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 12 Sep 2009 17:05:03 +0200 Subject: Port writing text files to 3.x. --HG-- branch : distribute extra : rebase_source : 767d047dae23d5123bf412b5838d150091eea078 --- setuptools/command/easy_install.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 0fa07845..7ed467f0 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -39,6 +39,13 @@ def samefile(p1,p2): os.path.normpath(os.path.normcase(p2)) ) +if sys.version_info <= (3,): + def _to_ascii(s): + return s +else: + def _to_ascii(s): + return s.encode('ascii') + class easy_install(Command): """Manage a download/build/install process""" description = "Find/get/install Python packages" @@ -599,7 +606,7 @@ Please make the appropriate changes for your system and try again. "import pkg_resources\n" "pkg_resources.run_script(%(spec)r, %(script_name)r)\n" ) % locals() - self.write_script(script_name, script_text, 'b') + self.write_script(script_name, _to_ascii(script_text), 'b') def write_script(self, script_name, contents, mode="t", blockers=()): """Write an executable file to the scripts directory""" @@ -1381,7 +1388,7 @@ class PthDistributions(Environment): if os.path.islink(self.filename): os.unlink(self.filename) - f = open(self.filename,'wb') + f = open(self.filename,'wt') f.write(data); f.close() elif os.path.exists(self.filename): -- cgit v1.2.3 From 63ad9ff720754e36a2b0299f2c857228f32b0c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 12 Sep 2009 17:16:22 +0200 Subject: Implement isascii. --HG-- branch : distribute extra : rebase_source : 6805617a1673859320ae278cfbb6f7136d20a0a8 --- setuptools/command/easy_install.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 7ed467f0..9e1f8711 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -42,9 +42,21 @@ def samefile(p1,p2): if sys.version_info <= (3,): def _to_ascii(s): return s + def isascii(s): + try: + unicode(s, 'ascii') + return True + except UnicodeError: + return False else: def _to_ascii(s): return s.encode('ascii') + def isascii(s): + try: + s.encode('ascii') + return True + except UnicodeError: + return False class easy_install(Command): """Manage a download/build/install process""" @@ -1439,7 +1451,7 @@ def get_script_header(script_text, executable=sys_executable, wininst=False): else: executable = nt_quote_arg(executable) hdr = "#!%(executable)s%(options)s\n" % locals() - if unicode(hdr,'ascii','ignore').encode('ascii') != hdr: + if not isascii(hdr): # Non-ascii path to sys.executable, use -x to prevent warnings if options: if options.strip().startswith('-'): -- cgit v1.2.3 From ea27f15b0cfa0908704fc73611d42f6efae8e14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 12 Sep 2009 18:02:40 +0200 Subject: Remove sdist3 command again. --HG-- branch : distribute extra : rebase_source : b2ae4e75c758eafa83057002ece9fb5dbc7aba92 --- setuptools/command/__init__.py | 2 +- setuptools/command/sdist3.py | 35 ----------------------------------- 2 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 setuptools/command/sdist3.py (limited to 'setuptools/command') diff --git a/setuptools/command/__init__.py b/setuptools/command/__init__.py index 8f5ba21c..f898822b 100644 --- a/setuptools/command/__init__.py +++ b/setuptools/command/__init__.py @@ -1,7 +1,7 @@ __all__ = [ 'alias', 'bdist_egg', 'bdist_rpm', 'build_ext', 'build_py', 'develop', 'easy_install', 'egg_info', 'install', 'install_lib', 'rotate', 'saveopts', - 'sdist', 'sdist3', 'setopt', 'test', 'upload', 'install_egg_info', 'install_scripts', + 'sdist', 'setopt', 'test', 'upload', 'install_egg_info', 'install_scripts', 'register', 'bdist_wininst', ] diff --git a/setuptools/command/sdist3.py b/setuptools/command/sdist3.py deleted file mode 100644 index fc7ebb97..00000000 --- a/setuptools/command/sdist3.py +++ /dev/null @@ -1,35 +0,0 @@ -import os -from distutils import log -from sdist import sdist -from lib2to3.refactor import RefactoringTool, get_fixers_from_package - - -class _RefactoringTool(RefactoringTool): - def log_error(self, msg, *args, **kw): - log.error(msg, *args) - - def log_message(self, msg, *args): - log.info(msg, *args) - - def log_debug(self, msg, *args): - log.debug(msg, *args) - - -class sdist3(sdist): - description = "sdist version that runs 2to3 on all sources before packaging" - fixer_names = None - - def copy_file(self, file, dest, link=None): - # We ignore the link parameter, always demanding a copy, so that - # 2to3 won't overwrite the original file. - sdist.copy_file(self, file, dest) - - def make_release_tree(self, base_dir, files): - sdist.make_release_tree(self, base_dir, files) - - # run 2to3 on all files - fixer_names = self.fixer_names - if fixer_names is None: - fixer_names = get_fixers_from_package('lib2to3.fixes') - r = _RefactoringTool(fixer_names) - r.refactor([os.path.join(base_dir, f) for f in files if f.endswith(".py")], write=True) -- cgit v1.2.3 From 709275f058fc9062b7a10db5123bd1ef91500832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 12 Sep 2009 23:22:28 +0200 Subject: Open zipsafe file in text mode. --HG-- branch : distribute extra : rebase_source : 3215e6d146816dc96a2cb23b6a6fb16fd63e1648 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 32cebe9d..43589c23 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -401,7 +401,7 @@ def write_safety_flag(egg_dir, safe): if safe is None or bool(safe)<>flag: os.unlink(fn) elif safe is not None and bool(safe)==flag: - f=open(fn,'wb'); f.write('\n'); f.close() + f=open(fn,'wt'); f.write('\n'); f.close() safety_flags = { True: 'zip-safe', -- cgit v1.2.3 From 99ab2076b4e84718f9b034ab4e1394fd06d468f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 13 Sep 2009 00:08:20 +0200 Subject: Open svn externals file in text mode. --HG-- branch : distribute extra : rebase_source : 0eec0f04099a978136350d3546c579bbd61ea6ec --- setuptools/command/sdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index 50c4c009..3442fe4b 100755 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -60,7 +60,7 @@ def _default_revctrl(dirname=''): def externals_finder(dirname, filename): """Find any 'svn:externals' directories""" found = False - f = open(filename,'rb') + f = open(filename,'rt') for line in iter(f.readline, ''): # can't use direct iter! parts = line.split() if len(parts)==2: -- cgit v1.2.3 From 5bf298f0e8b30f236b76997c66eee38de798f710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 13 Sep 2009 00:15:41 +0200 Subject: Work around distutils 3.1 breaking ext_map. --HG-- branch : distribute extra : rebase_source : 47da1d81d1923e23aa70949c2a69000c01f8f81f --- setuptools/command/build_ext.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index c0aaa8e8..b837375b 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -111,6 +111,11 @@ class build_ext(_build_ext): for ext in self.extensions: fullname = ext._full_name self.ext_map[fullname] = ext + + # distutils 3.1 will also ask for module names + # XXX what to do with conflicts? + self.ext_map[fullname.split('.')[-1]] = ext + ltd = ext._links_to_dynamic = \ self.shlibs and self.links_to_dynamic(ext) or False ext._needs_stub = ltd and use_stubs and not isinstance(ext,Library) -- cgit v1.2.3 From 5b568886e649fad8811f81484dc88fa5111faa94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 13 Sep 2009 00:17:03 +0200 Subject: Support running 2to3 on build_py. --HG-- branch : distribute extra : rebase_source : 7b3f06bc7b7745a7292e729c04053821340b6f49 --- setuptools/command/build_py.py | 45 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 3fce7693..b27574a4 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -3,7 +3,41 @@ from distutils.command.build_py import build_py as _build_py from distutils.util import convert_path from glob import glob -class build_py(_build_py): +try: + from distutils.util import Mixin2to3 as _Mixin2to3 + # add support for converting doctests that is missing in 3.1 distutils + from lib2to3.refactor import RefactoringTool, get_fixers_from_package + import setuptools + class DistutilsRefactoringTool(RefactoringTool): + def log_error(self, msg, *args, **kw): + log.error(msg, *args) + + def log_message(self, msg, *args): + log.info(msg, *args) + + def log_debug(self, msg, *args): + log.debug(msg, *args) + + class Mixin2to3(_Mixin2to3): + def run_2to3(self, files): + if not setuptools.run_2to3: + return files + files = _Mixin2to3.run_2to3(files) + if setuptools.run_2to3_on_doctests: + fixer_names = self.fixer_names + if fixer_names is None: + fixer_names = get_fixers_from_package('lib2to3.fixes') + r = DistutilsRefactoringTool(fixer_names) + r.refactor(files, write=True, doctests_only=True) + return files + +except ImportError: + class Mixin2to3: + def run_2to3(self, files): + # Nothing done in 2.x + pass + +class build_py(_build_py, Mixin2to3): """Enhanced 'build_py' command that includes data files with packages The data files are specified via a 'package_data' argument to 'setup()'. @@ -23,6 +57,7 @@ class build_py(_build_py): if not self.py_modules and not self.packages: return + self.__updated_files = [] if self.py_modules: self.build_modules() @@ -30,6 +65,8 @@ class build_py(_build_py): self.build_packages() self.build_package_data() + self.run_2to3(self.__updated_files) + # Only compile actual .py files, using our base class' idea of what our # output files are. self.byte_compile(_build_py.get_outputs(self, include_bytecode=0)) @@ -39,6 +76,12 @@ class build_py(_build_py): self.data_files = files = self._get_data_files(); return files return _build_py.__getattr__(self,attr) + def build_module(self, module, module_file, package): + outfile, copied = _build_py.build_module(self, module, module_file, package) + if copied: + self.__updated_files.append(outfile) + return outfile, copied + def _get_data_files(self): """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" self.analyze_manifest() -- cgit v1.2.3 From b712de5a1170ddb843b1f8a5bff111286dc0fc36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 13 Sep 2009 00:30:44 +0200 Subject: Move initialization of updated_files into finalize_options --HG-- branch : distribute extra : rebase_source : 9961dacb889d0707d3d0fa67168f71eb6b577373 --- setuptools/command/build_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index b27574a4..a80572fd 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -51,13 +51,13 @@ class build_py(_build_py, Mixin2to3): self.package_data = self.distribution.package_data self.exclude_package_data = self.distribution.exclude_package_data or {} if 'data_files' in self.__dict__: del self.__dict__['data_files'] + self.__updated_files = [] def run(self): """Build modules, packages, and copy data files to build directory""" if not self.py_modules and not self.packages: return - self.__updated_files = [] if self.py_modules: self.build_modules() -- cgit v1.2.3 From f5adca61c9cb6797eaf9da2029c9132ec486b552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 13 Sep 2009 00:36:04 +0200 Subject: Fix running 2to3. --HG-- branch : distribute extra : rebase_source : 2594ae17c6468d98288339c89cecd745f4dc181f --- setuptools/command/build_py.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index a80572fd..d5890afe 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -6,6 +6,7 @@ from glob import glob try: from distutils.util import Mixin2to3 as _Mixin2to3 # add support for converting doctests that is missing in 3.1 distutils + from distutils import log from lib2to3.refactor import RefactoringTool, get_fixers_from_package import setuptools class DistutilsRefactoringTool(RefactoringTool): @@ -21,15 +22,14 @@ try: class Mixin2to3(_Mixin2to3): def run_2to3(self, files): if not setuptools.run_2to3: - return files - files = _Mixin2to3.run_2to3(files) + return + _Mixin2to3.run_2to3(self, files) if setuptools.run_2to3_on_doctests: fixer_names = self.fixer_names if fixer_names is None: fixer_names = get_fixers_from_package('lib2to3.fixes') r = DistutilsRefactoringTool(fixer_names) r.refactor(files, write=True, doctests_only=True) - return files except ImportError: class Mixin2to3: -- cgit v1.2.3 From 536c9838f3bd703c97b3816bb8b723e41cec7d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 13 Sep 2009 10:19:07 +0200 Subject: Provide registry for fixer packages. --HG-- branch : distribute extra : rebase_source : 6a1259914751bdc18a32b98bd87680fb5fe94e70 --- setuptools/command/build_py.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index d5890afe..b570ddb5 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -23,12 +23,13 @@ try: def run_2to3(self, files): if not setuptools.run_2to3: return + if not self.fixer_names: + self.fixer_names = [] + for p in setuptools.lib2to3_fixer_packages: + self.fixer_names.extend(get_fixers_from_package(p)) _Mixin2to3.run_2to3(self, files) if setuptools.run_2to3_on_doctests: - fixer_names = self.fixer_names - if fixer_names is None: - fixer_names = get_fixers_from_package('lib2to3.fixes') - r = DistutilsRefactoringTool(fixer_names) + r = DistutilsRefactoringTool(self.fixer_names) r.refactor(files, write=True, doctests_only=True) except ImportError: -- cgit v1.2.3 From 26f4380b49c0e50f3782a2edbb9ba5ddd340a1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 13 Sep 2009 12:53:58 +0200 Subject: Add convert_doctests_2to3. --HG-- branch : distribute extra : rebase_source : 38832a69542ff3b96c403b32ec5b3663b08a61d0 --- setuptools/command/build_py.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index b570ddb5..dd99b9d6 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -20,21 +20,23 @@ try: log.debug(msg, *args) class Mixin2to3(_Mixin2to3): - def run_2to3(self, files): + def run_2to3(self, files, doctests = False): if not setuptools.run_2to3: return if not self.fixer_names: self.fixer_names = [] for p in setuptools.lib2to3_fixer_packages: self.fixer_names.extend(get_fixers_from_package(p)) - _Mixin2to3.run_2to3(self, files) - if setuptools.run_2to3_on_doctests: - r = DistutilsRefactoringTool(self.fixer_names) - r.refactor(files, write=True, doctests_only=True) + if doctests: + if setuptools.run_2to3_on_doctests: + r = DistutilsRefactoringTool(self.fixer_names) + r.refactor(files, write=True, doctests_only=True) + else: + _Mixin2to3.run_2to3(self, files) except ImportError: class Mixin2to3: - def run_2to3(self, files): + def run_2to3(self, files, doctests=True): # Nothing done in 2.x pass @@ -53,6 +55,7 @@ class build_py(_build_py, Mixin2to3): self.exclude_package_data = self.distribution.exclude_package_data or {} if 'data_files' in self.__dict__: del self.__dict__['data_files'] self.__updated_files = [] + self.__doctests_2to3 = [] def run(self): """Build modules, packages, and copy data files to build directory""" @@ -66,7 +69,9 @@ class build_py(_build_py, Mixin2to3): self.build_packages() self.build_package_data() - self.run_2to3(self.__updated_files) + self.run_2to3(self.__updated_files, False) + self.run_2to3(self.__updated_files, True) + self.run_2to3(self.__doctests_2to3, True) # Only compile actual .py files, using our base class' idea of what our # output files are. @@ -121,7 +126,9 @@ class build_py(_build_py, Mixin2to3): for filename in filenames: target = os.path.join(build_dir, filename) self.mkpath(os.path.dirname(target)) - self.copy_file(os.path.join(src_dir, filename), target) + outf, copied = self.copy_file(os.path.join(src_dir, filename), target) + if copied and filename in setuptools.convert_doctests_2to3: + self.__doctests_2to3.append(outf) def analyze_manifest(self): -- cgit v1.2.3 From 1a8b650faf34b6205a8a26168ab7ef886833f85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 13 Sep 2009 13:50:29 +0200 Subject: Fix processing of convert_doctests_2to3. --HG-- branch : distribute extra : rebase_source : 101f51e5f7c364407e27b742aec5e02336936d8c --- setuptools/command/build_py.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index dd99b9d6..2413b420 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -23,6 +23,9 @@ try: def run_2to3(self, files, doctests = False): if not setuptools.run_2to3: return + if not files: + return + log.info("Fixing "+" ".join(files)) if not self.fixer_names: self.fixer_names = [] for p in setuptools.lib2to3_fixer_packages: @@ -126,8 +129,10 @@ class build_py(_build_py, Mixin2to3): for filename in filenames: target = os.path.join(build_dir, filename) self.mkpath(os.path.dirname(target)) - outf, copied = self.copy_file(os.path.join(src_dir, filename), target) - if copied and filename in setuptools.convert_doctests_2to3: + srcfile = os.path.join(src_dir, filename) + outf, copied = self.copy_file(srcfile, target) + srcfile = os.path.abspath(srcfile) + if copied and srcfile in self.distribution.convert_doctests_2to3: self.__doctests_2to3.append(outf) -- cgit v1.2.3 From 3736fee0faddbbc93fa6b7a1b233d4c2dcf11d76 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Fri, 18 Sep 2009 17:22:17 +0200 Subject: Works with zope.interface now. --HG-- branch : distribute extra : rebase_source : c8cd9fd837bbac96c8949f0015d84051bd8ab5c7 --- setuptools/command/build_py.py | 6 +++++- setuptools/command/test.py | 28 ++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 2413b420..94f66741 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -21,7 +21,9 @@ try: class Mixin2to3(_Mixin2to3): def run_2to3(self, files, doctests = False): - if not setuptools.run_2to3: + # See of the distribution option has been set, otherwise check the + # setuptools default. + if self.distribution.run_2to3 is not True and setuptools.run_2to3 is False: return if not files: return @@ -30,6 +32,8 @@ try: self.fixer_names = [] for p in setuptools.lib2to3_fixer_packages: self.fixer_names.extend(get_fixers_from_package(p)) + for p in self.distribution.additional_2to3_fixers: + self.fixer_names.extend(get_fixers_from_package(p)) if doctests: if setuptools.run_2to3_on_doctests: r = DistutilsRefactoringTool(self.fixer_names) diff --git a/setuptools/command/test.py b/setuptools/command/test.py index db918dae..0f96e83a 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,4 +1,4 @@ -from setuptools import Command +from setuptools import Command, run_2to3 from distutils.errors import DistutilsOptionError import sys from pkg_resources import * @@ -81,12 +81,28 @@ class test(Command): def with_project_on_sys_path(self, func): - # Ensure metadata is up-to-date - self.run_command('egg_info') + if getattr(self.distribution, 'run_2to3', run_2to3): + # If we run 2to3 we can not do this inplace: - # Build extensions in-place - self.reinitialize_command('build_ext', inplace=1) - self.run_command('build_ext') + # Ensure metadata is up-to-date + self.reinitialize_command('build_py', inplace=0) + self.run_command('build_py') + bpy_cmd = self.get_finalized_command("build_py") + build_path = normalize_path(bpy_cmd.build_lib) + + # Build extensions + self.reinitialize_command('egg_info', egg_base=build_path) + self.run_command('egg_info') + + self.reinitialize_command('build_ext', inplace=0) + self.run_command('build_ext') + else: + # Without 2to3 inplace works fine: + self.run_command('egg_info') + + # Build extensions in-place + self.reinitialize_command('build_ext', inplace=1) + self.run_command('build_ext') ei_cmd = self.get_finalized_command("egg_info") -- cgit v1.2.3 From 95159c09e5bb2d1dc1f0ccf89ccbe90ecc6871a0 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Sat, 19 Sep 2009 22:39:32 +0200 Subject: Fixed a daft bug (my fault). --HG-- branch : distribute extra : rebase_source : 82e1e503282ced638da32690291923613a74e930 --- setuptools/command/build_py.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 94f66741..910d67c8 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -32,8 +32,9 @@ try: self.fixer_names = [] for p in setuptools.lib2to3_fixer_packages: self.fixer_names.extend(get_fixers_from_package(p)) - for p in self.distribution.additional_2to3_fixers: - self.fixer_names.extend(get_fixers_from_package(p)) + if self.distribution.additional_2to3_fixers is not None: + for p in self.distribution.additional_2to3_fixers: + self.fixer_names.extend(get_fixers_from_package(p)) if doctests: if setuptools.run_2to3_on_doctests: r = DistutilsRefactoringTool(self.fixer_names) -- cgit v1.2.3