From 8423e1ed14ac1691c2863c6e8cac9230cf558d7b Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 19 Mar 2004 20:53:14 +0000 Subject: Initial checkin of setuptools 0.0.1. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040869 --- setuptools/command/build_py.py | 123 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 setuptools/command/build_py.py (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py new file mode 100644 index 00000000..7d5b6ffd --- /dev/null +++ b/setuptools/command/build_py.py @@ -0,0 +1,123 @@ +from distutils.command.build_py import build_py as _build_py +from distutils.util import convert_path +from glob import glob +import os.path + +class build_py(_build_py): + + """Enhanced 'build_py' command that includes data files with packages + + The data files are specified via a 'package_data' argument to 'setup()'. + See 'setuptools.dist.Distribution' for more details. + + Also, this version of the 'build_py' command allows you to specify both + 'py_modules' and 'packages' in the same setup operation. + """ + + def finalize_options(self): + _build_py.finalize_options(self) + self.package_data = self.distribution.package_data + self.data_files = self.get_data_files() + + + def run(self): + + """Build modules, packages, and copy data files to build directory""" + + if not self.py_modules and not self.packages: + return + + if self.py_modules: + self.build_modules() + + if self.packages: + self.build_packages() + self.build_package_data() + + # 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)) + + + def get_data_files(self): + + """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" + + data = [] + + for package in self.packages: + # Locate package source directory + src_dir = self.get_package_dir(package) + + # Compute package build directory + build_dir = os.path.join(*([self.build_lib]+package.split('.'))) + + # Length of path to strip from found files + plen = len(src_dir)+1 + + # Strip directory from globbed filenames + filenames = [ + file[plen:] for file in self.find_data_files(package, src_dir) + ] + + data.append( (package, src_dir, build_dir, filenames) ) + + return data + + + def find_data_files(self, package, src_dir): + + """Return filenames for package's data files in 'src_dir'""" + + globs = self.package_data.get('',[])+self.package_data.get(package,[]) + files = [] + + for pattern in globs: + # Each pattern has to be converted to a platform-specific path + files.extend(glob(os.path.join(src_dir, convert_path(pattern)))) + + return files + + + + def build_package_data(self): + + """Copy data files into build directory""" + + lastdir = None + + for package, src_dir, build_dir, filenames in self.data_files: + + 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) + + + def get_outputs(self, include_bytecode=1): + + """Return complete list of files copied to the build directory + + This includes both '.py' files and data files, as well as '.pyc' and + '.pyo' files if 'include_bytecode' is true. (This method is needed for + the 'install_lib' command to do its job properly, and to generate a + correct installation manifest.) + """ + + return _build_py.get_outputs(self,include_bytecode) + [ + os.path.join(build_dir,filename) + for package,src_dir,build_dir,filenames in self.data_files + for filename in filenames + ] + + + + + + + + + + + + -- cgit v1.2.1 From 9274fa3cfbecf55ebc38a95719f899b8f3ebd273 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Mon, 5 Apr 2004 20:21:53 +0000 Subject: remove excess blank lines, and apply whitespace more in line with the Python style guidelines in PEP 8 --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040896 --- setuptools/command/build_py.py | 65 +++++++++++------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 7d5b6ffd..95e83c30 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -1,10 +1,11 @@ +import os.path + from distutils.command.build_py import build_py as _build_py from distutils.util import convert_path from glob import glob -import os.path -class build_py(_build_py): +class build_py(_build_py): """Enhanced 'build_py' command that includes data files with packages The data files are specified via a 'package_data' argument to 'setup()'. @@ -17,13 +18,10 @@ class build_py(_build_py): def finalize_options(self): _build_py.finalize_options(self) self.package_data = self.distribution.package_data - self.data_files = self.get_data_files() - + self.data_files = self.get_data_files() def run(self): - """Build modules, packages, and copy data files to build directory""" - if not self.py_modules and not self.packages: return @@ -36,21 +34,17 @@ class build_py(_build_py): # 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)) - + self.byte_compile(_build_py.get_outputs(self, include_bytecode=0)) def get_data_files(self): - """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" - data = [] - for package in self.packages: # Locate package source directory src_dir = self.get_package_dir(package) # Compute package build directory - build_dir = os.path.join(*([self.build_lib]+package.split('.'))) + build_dir = os.path.join(*([self.build_lib] + package.split('.'))) # Length of path to strip from found files plen = len(src_dir)+1 @@ -58,44 +52,30 @@ class build_py(_build_py): # Strip directory from globbed filenames filenames = [ file[plen:] for file in self.find_data_files(package, src_dir) - ] - + ] data.append( (package, src_dir, build_dir, filenames) ) - return data - def find_data_files(self, package, src_dir): - """Return filenames for package's data files in 'src_dir'""" - - globs = self.package_data.get('',[])+self.package_data.get(package,[]) + globs = (self.package_data.get('', []) + + self.package_data.get(package, [])) files = [] - for pattern in globs: # Each pattern has to be converted to a platform-specific path files.extend(glob(os.path.join(src_dir, convert_path(pattern)))) - return files - - def build_package_data(self): - """Copy data files into build directory""" - lastdir = None - for package, src_dir, build_dir, filenames in self.data_files: - for filename in filenames: - target = os.path.join(build_dir,filename) + target = os.path.join(build_dir, filename) self.mkpath(os.path.dirname(target)) - self.copy_file(os.path.join(src_dir,filename), target) - + self.copy_file(os.path.join(src_dir, filename), target) def get_outputs(self, include_bytecode=1): - """Return complete list of files copied to the build directory This includes both '.py' files and data files, as well as '.pyc' and @@ -103,21 +83,8 @@ class build_py(_build_py): the 'install_lib' command to do its job properly, and to generate a correct installation manifest.) """ - - return _build_py.get_outputs(self,include_bytecode) + [ - os.path.join(build_dir,filename) - for package,src_dir,build_dir,filenames in self.data_files - for filename in filenames - ] - - - - - - - - - - - - + return _build_py.get_outputs(self, include_bytecode) + [ + os.path.join(build_dir, filename) + for package, src_dir, build_dir,filenames in self.data_files + for filename in filenames + ] -- cgit v1.2.1 From 8cc0d5c27e393605ac2c729143b8730aa973a128 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Thu, 11 Aug 2005 00:37:37 +0000 Subject: Fix bugs reported by Ian Bicking, Walter Doerwald, and Vincenzo Di Massa. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041189 --- setuptools/command/build_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 95e83c30..9db49080 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -39,7 +39,7 @@ class build_py(_build_py): def get_data_files(self): """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" data = [] - for package in self.packages: + for package in self.packages or (): # Locate package source directory src_dir = self.get_package_dir(package) -- cgit v1.2.1 From 25d3d2a756deba20be559ff5f46e8621779ad226 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 2 Nov 2005 23:55:34 +0000 Subject: 0.6a7 bugfix release --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041377 --- setuptools/command/build_py.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 9db49080..d13c46f2 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -1,5 +1,4 @@ -import os.path - +import os.path, sys from distutils.command.build_py import build_py as _build_py from distutils.util import convert_path from glob import glob @@ -36,6 +35,10 @@ class build_py(_build_py): # output files are. self.byte_compile(_build_py.get_outputs(self, include_bytecode=0)) + + + + def get_data_files(self): """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" data = [] @@ -75,6 +78,8 @@ class build_py(_build_py): self.mkpath(os.path.dirname(target)) self.copy_file(os.path.join(src_dir, filename), target) + + def get_outputs(self, include_bytecode=1): """Return complete list of files copied to the build directory @@ -88,3 +93,31 @@ class build_py(_build_py): for package, src_dir, build_dir,filenames in self.data_files for filename in filenames ] + + +if sys.version>="2.4": + # Python 2.4 already has the above code + build_py = _build_py + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.1 From 4cd66c4147bef3ee8096f7161d407fb37582f1c9 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 18 Nov 2005 04:37:31 +0000 Subject: Added the ``include_package_data`` keyword to ``setup()``, allowing you to automatically include any package data listed in revision control or ``MANIFEST.in``. Now projects can manage their data files and source manifests without having to maintain two ways to express the same file list. Yay! --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041473 --- setuptools/command/build_py.py | 90 +++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index d13c46f2..fd09514f 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -3,7 +3,6 @@ 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): """Enhanced 'build_py' command that includes data files with packages @@ -17,7 +16,7 @@ class build_py(_build_py): def finalize_options(self): _build_py.finalize_options(self) self.package_data = self.distribution.package_data - self.data_files = self.get_data_files() + if 'data_files' in self.__dict__: del self.__dict__['data_files'] def run(self): """Build modules, packages, and copy data files to build directory""" @@ -35,12 +34,14 @@ class build_py(_build_py): # output files are. self.byte_compile(_build_py.get_outputs(self, include_bytecode=0)) + def __getattr__(self,attr): + if attr=='data_files': # lazily compute data files + self.data_files = files = self._get_data_files(); return files + return _build_py.__getattr__(self,attr) - - - - def get_data_files(self): + def _get_data_files(self): """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" + self.analyze_manifest() data = [] for package in self.packages or (): # Locate package source directory @@ -63,7 +64,7 @@ class build_py(_build_py): """Return filenames for package's data files in 'src_dir'""" globs = (self.package_data.get('', []) + self.package_data.get(package, [])) - files = [] + files = self.manifest_files.get(package, [])[:] for pattern in globs: # Each pattern has to be converted to a platform-specific path files.extend(glob(os.path.join(src_dir, convert_path(pattern)))) @@ -79,45 +80,44 @@ class build_py(_build_py): self.copy_file(os.path.join(src_dir, filename), target) + def analyze_manifest(self): + self.manifest_files = mf = {} + if not self.distribution.include_package_data: + return - def get_outputs(self, include_bytecode=1): - """Return complete list of files copied to the build directory - - This includes both '.py' files and data files, as well as '.pyc' and - '.pyo' files if 'include_bytecode' is true. (This method is needed for - the 'install_lib' command to do its job properly, and to generate a - correct installation manifest.) - """ - return _build_py.get_outputs(self, include_bytecode) + [ - os.path.join(build_dir, filename) - for package, src_dir, build_dir,filenames in self.data_files - for filename in filenames - ] - - -if sys.version>="2.4": - # Python 2.4 already has the above code - build_py = _build_py - - - - - - - - - - - - - - - - - - - - + src_dirs = {} + for package in self.packages or (): + # Locate package source directory + src_dirs[self.get_package_dir(package)] = package + + self.run_command('egg_info') + ei_cmd = self.get_finalized_command('egg_info') + for path in ei_cmd.filelist.files: + if path.endswith('.py'): continue + d,f = os.path.split(path) + while d and d not in src_dirs: + d, df = os.path.split(d) + f = os.path.join(df, f) + if d in src_dirs: + mf.setdefault(src_dirs[d],[]).append(path) + + + def get_data_files(self): pass # kludge 2.4 for lazy computation + + if sys.version<"2.4": # Python 2.4 already has this code + def get_outputs(self, include_bytecode=1): + """Return complete list of files copied to the build directory + + This includes both '.py' files and data files, as well as '.pyc' + and '.pyo' files if 'include_bytecode' is true. (This method is + needed for the 'install_lib' command to do its job properly, and to + generate a correct installation manifest.) + """ + return _build_py.get_outputs(self, include_bytecode) + [ + os.path.join(build_dir, filename) + for package, src_dir, build_dir,filenames in self.data_files + for filename in filenames + ] -- cgit v1.2.1 From e218cf0c77bcd66bfd5b9e30aee73f4787ed5b21 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 18 Nov 2005 17:29:47 +0000 Subject: Added warning for namespace packages with missing ``declare_namespace()``, updated docs for new policy/implementation, and explain the reasons for the change and what to do about it. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041479 --- setuptools/command/build_py.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index fd09514f..35b9c57e 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -121,3 +121,44 @@ class build_py(_build_py): + def check_package(self, package, package_dir): + """Check namespace packages' __init__ for declare_namespace""" + try: + return self.packages_checked[package] + except KeyError: + pass + + init_py = _build_py.check_package(self, package, package_dir) + self.packages_checked[package] = init_py + + if not init_py or not self.distribution.namespace_packages: + return init_py + + for pkg in self.distribution.namespace_packages: + if pkg==package or pkg.startswith(package+'.'): + break + else: + return init_py + + f = open(init_py,'rU') + if 'declare_namespace' not in f.read(): + from distutils import log + log.warn( + "WARNING: %s is a namespace package, but its __init__.py does\n" + "not declare_namespace(); setuptools 0.7 will REQUIRE this!\n" + '(See the setuptools manual under "Namespace Packages" for ' + "details.)\n", package + ) + f.close() + return init_py + + def initialize_options(self): + self.packages_checked={} + _build_py.initialize_options(self) + + + + + + + -- cgit v1.2.1 From d989230127c6e16c505096f6150db977e61478b3 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Thu, 15 Dec 2005 02:45:03 +0000 Subject: Added the ``exclude_package_data`` keyword to ``setup()``, allowing you to trim back files included via the ``package_data`` and ``include_package_data`` options. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041693 --- setuptools/command/build_py.py | 47 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 35b9c57e..4d779f57 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -1,4 +1,4 @@ -import os.path, sys +import os.path, sys, fnmatch from distutils.command.build_py import build_py as _build_py from distutils.util import convert_path from glob import glob @@ -12,10 +12,10 @@ class build_py(_build_py): Also, this version of the 'build_py' command allows you to specify both 'py_modules' and 'packages' in the same setup operation. """ - def finalize_options(self): _build_py.finalize_options(self) 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'] def run(self): @@ -68,7 +68,7 @@ class build_py(_build_py): for pattern in globs: # Each pattern has to be converted to a platform-specific path files.extend(glob(os.path.join(src_dir, convert_path(pattern)))) - return files + return self.exclude_data_files(package, src_dir, files) def build_package_data(self): """Copy data files into build directory""" @@ -155,6 +155,47 @@ class build_py(_build_py): def initialize_options(self): self.packages_checked={} _build_py.initialize_options(self) + + + + + + + + def exclude_data_files(self, package, src_dir, files): + """Filter filenames for package's data files in 'src_dir'""" + globs = (self.exclude_package_data.get('', []) + + self.exclude_package_data.get(package, [])) + bad = [] + for pattern in globs: + bad.extend( + fnmatch.filter( + files, os.path.join(src_dir, convert_path(pattern)) + ) + ) + bad = dict.fromkeys(bad) + return [f for f in files if f not in bad] + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.1 From 150889dedfa7345ef5681224415d313cc01fa101 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sat, 15 Apr 2006 05:33:00 +0000 Subject: Backport absolute path trapping to the 0.6 branch. --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4045416 --- setuptools/command/build_py.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 4d779f57..373930ac 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -84,18 +84,20 @@ class build_py(_build_py): self.manifest_files = mf = {} if not self.distribution.include_package_data: return - src_dirs = {} for package in self.packages or (): # Locate package source directory - src_dirs[self.get_package_dir(package)] = package + src_dirs[assert_relative(self.get_package_dir(package))] = package self.run_command('egg_info') ei_cmd = self.get_finalized_command('egg_info') for path in ei_cmd.filelist.files: - if path.endswith('.py'): continue - d,f = os.path.split(path) - while d and d not in src_dirs: + if path.endswith('.py'): + continue + d,f = os.path.split(assert_relative(path)) + prev = None + while d and d!=prev and d not in src_dirs: + prev = d d, df = os.path.split(d) f = os.path.join(df, f) if d in src_dirs: @@ -119,8 +121,6 @@ class build_py(_build_py): for filename in filenames ] - - def check_package(self, package, package_dir): """Check namespace packages' __init__ for declare_namespace""" try: @@ -177,19 +177,19 @@ class build_py(_build_py): return [f for f in files if f not in bad] +def assert_relative(path): + if not os.path.isabs(path): + return path + from distutils.errors import DistutilsSetupError + raise DistutilsSetupError( +"""Error: setup script specifies an absolute path: + %s - - - - - - - - - - - +setup() arguments must *always* be /-separated paths relative to the +setup.py directory, *never* absolute paths. +""" % path + ) -- cgit v1.2.1 From f01c17e9e6301a72c54a0b3a5b9d1e21449e4e51 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 9 Jun 2006 18:26:45 +0000 Subject: Allow .py files found by the include_package_data option to be automatically included. Remove duplicate data file matches if both include_package_data and package_data are used to refer to the same files. (merge from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4046791 --- setuptools/command/build_py.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 373930ac..79570bc2 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -92,18 +92,18 @@ class build_py(_build_py): self.run_command('egg_info') ei_cmd = self.get_finalized_command('egg_info') for path in ei_cmd.filelist.files: - if path.endswith('.py'): - continue d,f = os.path.split(assert_relative(path)) prev = None + oldf = f while d and d!=prev and d not in src_dirs: prev = d d, df = os.path.split(d) f = os.path.join(df, f) if d in src_dirs: + if path.endswith('.py') and f==oldf: + continue # it's a module, not data mf.setdefault(src_dirs[d],[]).append(path) - def get_data_files(self): pass # kludge 2.4 for lazy computation if sys.version<"2.4": # Python 2.4 already has this code @@ -167,14 +167,18 @@ class build_py(_build_py): globs = (self.exclude_package_data.get('', []) + self.exclude_package_data.get(package, [])) bad = [] - for pattern in globs: + for pattern in globs: bad.extend( fnmatch.filter( files, os.path.join(src_dir, convert_path(pattern)) ) ) bad = dict.fromkeys(bad) - return [f for f in files if f not in bad] + seen = {} + return [ + f for f in files if f not in bad + and f not in seen and seen.setdefault(f,1) # ditch dupes + ] def assert_relative(path): @@ -199,7 +203,3 @@ setup.py directory, *never* absolute paths. - - - - -- cgit v1.2.1 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/build_py.py') 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.1 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/build_py.py') 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.1 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/build_py.py') 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.1 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/build_py.py') 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.1 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/build_py.py') 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.1 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/build_py.py') 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.1 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/build_py.py') 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.1 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 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') 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) -- cgit v1.2.1 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/build_py.py') 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.1 From 7596dc0cf93965df85e36dcbca683270f5e9ded2 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Tue, 22 Sep 2009 17:25:53 +0200 Subject: Name changes of the parameters. --HG-- branch : distribute extra : rebase_source : fc921b526cda13b02a4bb0215f91ee04d03dca57 --- setuptools/command/build_py.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 910d67c8..a01e2843 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -23,7 +23,7 @@ try: def run_2to3(self, files, doctests = False): # 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: + if self.distribution.use_2to3 is not True: return if not files: return @@ -32,8 +32,8 @@ try: self.fixer_names = [] for p in setuptools.lib2to3_fixer_packages: 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: + if self.distribution.use_2to3_fixers is not None: + for p in self.distribution.use_2to3_fixers: self.fixer_names.extend(get_fixers_from_package(p)) if doctests: if setuptools.run_2to3_on_doctests: @@ -137,7 +137,7 @@ class build_py(_build_py, Mixin2to3): 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: + if copied and srcfile in self.distribution.convert_2to3_doctests: self.__doctests_2to3.append(outf) -- cgit v1.2.1 From 694a9231f495a82cf62340f9b98eb4fd7272ecf3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 4 Oct 2011 11:01:49 -0400 Subject: Added options to exclude 2to3 fixers. Fixes #249 --HG-- branch : distribute extra : rebase_source : 2033bcdd4c2e78e0e03796f1f9cf6d6e9a59fc21 --- setuptools/command/build_py.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index a01e2843..d53960fe 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -28,13 +28,8 @@ try: if not files: return log.info("Fixing "+" ".join(files)) - if not self.fixer_names: - self.fixer_names = [] - for p in setuptools.lib2to3_fixer_packages: - self.fixer_names.extend(get_fixers_from_package(p)) - if self.distribution.use_2to3_fixers is not None: - for p in self.distribution.use_2to3_fixers: - self.fixer_names.extend(get_fixers_from_package(p)) + self.__build_fixer_names() + self.__exclude_fixers() if doctests: if setuptools.run_2to3_on_doctests: r = DistutilsRefactoringTool(self.fixer_names) @@ -42,6 +37,25 @@ try: else: _Mixin2to3.run_2to3(self, files) + def __build_fixer_names(self): + if self.fixer_names: return + self.fixer_names = [] + for p in setuptools.lib2to3_fixer_packages: + self.fixer_names.extend(get_fixers_from_package(p)) + if self.distribution.use_2to3_fixers is not None: + for p in self.distribution.use_2to3_fixers: + self.fixer_names.extend(get_fixers_from_package(p)) + + def __exclude_fixers(self): + excluded_fixers = getattr(self, 'exclude_fixers', []) + if self.distribution.use_2to3_exclude_fixers is not None: + excluded_fixers.extend(self.distribution.use_2to3_exclude_fixers) + for fixer_name in excluded_fixers: + if fixer_name not in self.fixer_names: + log.warn("Excluded fixer %s not found", fixer_name) + continue + self.fixer_names.remove(fixer_name) + except ImportError: class Mixin2to3: def run_2to3(self, files, doctests=True): -- cgit v1.2.1 From 0d962727403be73b0b1eac234ed81b941dd7cae9 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Wed, 22 Aug 2012 18:01:49 +0200 Subject: Issue #310: Non-ascii characters in a namespace __init__.py causes errors. --HG-- branch : distribute extra : rebase_source : 668e1c79a2bcc314bcf1f7213b317766bb8511ab --- setuptools/command/build_py.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index d53960fe..505dd4f3 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -215,8 +215,8 @@ class build_py(_build_py, Mixin2to3): else: return init_py - f = open(init_py,'rU') - if 'declare_namespace' not in f.read(): + f = open(init_py,'rbU') + if 'declare_namespace'.encode() not in f.read(): from distutils import log log.warn( "WARNING: %s is a namespace package, but its __init__.py does\n" -- cgit v1.2.1 From 645b5b084aa46696b490344a038875f105793308 Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Mon, 8 Oct 2012 20:37:54 +0200 Subject: Remove a missing fixer warning which showed during normal operations. Fixes #305. --HG-- branch : distribute extra : rebase_source : 3e5912a80758abf1e198d400c29ab03112eb68d6 --- setuptools/command/build_py.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 505dd4f3..8751acd4 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -51,10 +51,8 @@ try: if self.distribution.use_2to3_exclude_fixers is not None: excluded_fixers.extend(self.distribution.use_2to3_exclude_fixers) for fixer_name in excluded_fixers: - if fixer_name not in self.fixer_names: - log.warn("Excluded fixer %s not found", fixer_name) - continue - self.fixer_names.remove(fixer_name) + if fixer_name in self.fixer_names: + self.fixer_names.remove(fixer_name) except ImportError: class Mixin2to3: -- cgit v1.2.1 From 9c5b87a057da48d44457021e2dcb843eb7122977 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 27 Nov 2013 15:08:41 -0500 Subject: Reorganize imports --- setuptools/command/build_py.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 8751acd4..c9aa07ed 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -1,4 +1,6 @@ -import os.path, sys, fnmatch +import os +import sys +import fnmatch from distutils.command.build_py import build_py as _build_py from distutils.util import convert_path from glob import glob -- cgit v1.2.1 From 9ccef555dd1f257fd9fa15bdecdbf4c19196a180 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 27 Nov 2013 15:20:38 -0500 Subject: Extracted module for lib2to3 Mixin customization. --- setuptools/command/build_py.py | 54 ++---------------------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index c9aa07ed..0d8e8757 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -6,61 +6,11 @@ from distutils.util import convert_path 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): - 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, doctests = False): - # See of the distribution option has been set, otherwise check the - # setuptools default. - if self.distribution.use_2to3 is not True: - return - if not files: - return - log.info("Fixing "+" ".join(files)) - self.__build_fixer_names() - self.__exclude_fixers() - 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) - - def __build_fixer_names(self): - if self.fixer_names: return - self.fixer_names = [] - for p in setuptools.lib2to3_fixer_packages: - self.fixer_names.extend(get_fixers_from_package(p)) - if self.distribution.use_2to3_fixers is not None: - for p in self.distribution.use_2to3_fixers: - self.fixer_names.extend(get_fixers_from_package(p)) - - def __exclude_fixers(self): - excluded_fixers = getattr(self, 'exclude_fixers', []) - if self.distribution.use_2to3_exclude_fixers is not None: - excluded_fixers.extend(self.distribution.use_2to3_exclude_fixers) - for fixer_name in excluded_fixers: - if fixer_name in self.fixer_names: - self.fixer_names.remove(fixer_name) - + from setuptools.lib2to3_ex import Mixin2to3 except ImportError: class Mixin2to3: def run_2to3(self, files, doctests=True): - # Nothing done in 2.x - pass + "do nothing" class build_py(_build_py, Mixin2to3): """Enhanced 'build_py' command that includes data files with packages -- cgit v1.2.1 From a193991b4b347ecc403be76005e098d4abeef2b3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 27 Nov 2013 15:25:35 -0500 Subject: Delint build_py --- setuptools/command/build_py.py | 43 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 0d8e8757..090b44d2 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -1,6 +1,7 @@ import os import sys import fnmatch +import textwrap from distutils.command.build_py import build_py as _build_py from distutils.util import convert_path from glob import glob @@ -49,9 +50,10 @@ class build_py(_build_py, Mixin2to3): # output files are. self.byte_compile(_build_py.get_outputs(self, include_bytecode=0)) - def __getattr__(self,attr): + def __getattr__(self, attr): if attr=='data_files': # lazily compute data files - self.data_files = files = self._get_data_files(); return files + self.data_files = files = self._get_data_files() + return files return _build_py.__getattr__(self,attr) def build_module(self, module, module_file, package): @@ -78,7 +80,7 @@ class build_py(_build_py, Mixin2to3): filenames = [ file[plen:] for file in self.find_data_files(package, src_dir) ] - data.append( (package, src_dir, build_dir, filenames) ) + data.append((package, src_dir, build_dir, filenames)) return data def find_data_files(self, package, src_dir): @@ -93,7 +95,6 @@ class build_py(_build_py, Mixin2to3): def build_package_data(self): """Copy data files into build directory""" - lastdir = None for package, src_dir, build_dir, filenames in self.data_files: for filename in filenames: target = os.path.join(build_dir, filename) @@ -104,7 +105,6 @@ class build_py(_build_py, Mixin2to3): if copied and srcfile in self.distribution.convert_2to3_doctests: self.__doctests_2to3.append(outf) - def analyze_manifest(self): self.manifest_files = mf = {} if not self.distribution.include_package_data: @@ -169,10 +169,10 @@ class build_py(_build_py, Mixin2to3): if 'declare_namespace'.encode() not in f.read(): from distutils import log log.warn( - "WARNING: %s is a namespace package, but its __init__.py does\n" - "not declare_namespace(); setuptools 0.7 will REQUIRE this!\n" - '(See the setuptools manual under "Namespace Packages" for ' - "details.)\n", package + "WARNING: %s is a namespace package, but its __init__.py does\n" + "not declare_namespace(); setuptools 0.7 will REQUIRE this!\n" + '(See the setuptools manual under "Namespace Packages" for ' + "details.)\n", package ) f.close() return init_py @@ -181,14 +181,12 @@ class build_py(_build_py, Mixin2to3): self.packages_checked={} _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): """Filter filenames for package's data files in 'src_dir'""" globs = (self.exclude_package_data.get('', []) @@ -212,21 +210,12 @@ def assert_relative(path): if not os.path.isabs(path): return path from distutils.errors import DistutilsSetupError - raise DistutilsSetupError( -"""Error: setup script specifies an absolute path: - - %s - -setup() arguments must *always* be /-separated paths relative to the -setup.py directory, *never* absolute paths. -""" % path - ) - - - - - - - + msg = textwrap.dedent(""" + Error: setup script specifies an absolute path: + %s + setup() arguments must *always* be /-separated paths relative to the + setup.py directory, *never* absolute paths. + """).lstrip() % path + raise DistutilsSetupError(msg) -- cgit v1.2.1 From 52dcb6d1c888a4a7a047f380783f572055a175dc Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 14 Apr 2006 19:13:24 +0000 Subject: Don't eagerly import namespace packages. This was the big reason for branching to 0.7 now, as I wanted this wart gone before anything went into Python 2.5. But it's gone now, yay! --HG-- extra : source : f3c5c19842064dd4a497baef0171aac54464a484 extra : amend_source : 3f79e71eedfc5f37a1813967bb53cf9d92a11919 --- setuptools/command/build_py.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 090b44d2..1efabc02 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -167,12 +167,12 @@ class build_py(_build_py, Mixin2to3): f = open(init_py,'rbU') if 'declare_namespace'.encode() not in f.read(): - from distutils import log - log.warn( - "WARNING: %s is a namespace package, but its __init__.py does\n" - "not declare_namespace(); setuptools 0.7 will REQUIRE this!\n" + from distutils.errors import DistutilsError + raise DistutilsError( + "Namespace package problem: %s is a namespace package, but its\n" + "__init__.py does not call declare_namespace()! Please fix it.\n" '(See the setuptools manual under "Namespace Packages" for ' - "details.)\n", package + "details.)\n" % (package,) ) f.close() return init_py -- cgit v1.2.1 From 573c2c86d4d4f506a87a1fc16060f32c1386ad38 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 30 Apr 2014 17:38:29 -0400 Subject: Correct indentation and clarify meaning by using namespacing --HG-- extra : amend_source : 20ab7547c8478eb084767fe701e627bdd462ba16 --- setuptools/command/build_py.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 1efabc02..53bfb7df 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -2,7 +2,7 @@ import os import sys import fnmatch import textwrap -from distutils.command.build_py import build_py as _build_py +import distutils.command.build_py as orig from distutils.util import convert_path from glob import glob @@ -13,7 +13,7 @@ except ImportError: def run_2to3(self, files, doctests=True): "do nothing" -class build_py(_build_py, Mixin2to3): +class build_py(orig.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,7 +23,7 @@ class build_py(_build_py, Mixin2to3): 'py_modules' and 'packages' in the same setup operation. """ def finalize_options(self): - _build_py.finalize_options(self) + orig.build_py.finalize_options(self) 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'] @@ -48,16 +48,16 @@ class build_py(_build_py, Mixin2to3): # 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)) + self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=0)) def __getattr__(self, attr): if attr=='data_files': # lazily compute data files self.data_files = files = self._get_data_files() return files - return _build_py.__getattr__(self,attr) + return orig.build_py.__getattr__(self,attr) def build_module(self, module, module_file, package): - outfile, copied = _build_py.build_module(self, module, module_file, package) + outfile, copied = orig.build_py.build_module(self, module, module_file, package) if copied: self.__updated_files.append(outfile) return outfile, copied @@ -140,7 +140,7 @@ class build_py(_build_py, Mixin2to3): needed for the 'install_lib' command to do its job properly, and to generate a correct installation manifest.) """ - return _build_py.get_outputs(self, include_bytecode) + [ + return orig.build_py.get_outputs(self, include_bytecode) + [ os.path.join(build_dir, filename) for package, src_dir, build_dir,filenames in self.data_files for filename in filenames @@ -153,7 +153,7 @@ class build_py(_build_py, Mixin2to3): except KeyError: pass - init_py = _build_py.check_package(self, package, package_dir) + init_py = orig.build_py.check_package(self, package, package_dir) self.packages_checked[package] = init_py if not init_py or not self.distribution.namespace_packages: @@ -179,10 +179,10 @@ class build_py(_build_py, Mixin2to3): def initialize_options(self): self.packages_checked={} - _build_py.initialize_options(self) + orig.build_py.initialize_options(self) def get_package_dir(self, package): - res = _build_py.get_package_dir(self, package) + res = orig.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 -- cgit v1.2.1 From 8e3f9d3253d1d0fb820dad4249d5110d017595c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 18 Jun 2014 20:31:05 +0300 Subject: Fixed PEP 8 compliancy of the setuptools.command package --- setuptools/command/build_py.py | 65 ++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 53bfb7df..98080694 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -1,10 +1,10 @@ +from glob import glob +from distutils.util import convert_path +import distutils.command.build_py as orig import os import sys import fnmatch import textwrap -import distutils.command.build_py as orig -from distutils.util import convert_path -from glob import glob try: from setuptools.lib2to3_ex import Mixin2to3 @@ -13,6 +13,7 @@ except ImportError: def run_2to3(self, files, doctests=True): "do nothing" + class build_py(orig.build_py, Mixin2to3): """Enhanced 'build_py' command that includes data files with packages @@ -22,11 +23,14 @@ class build_py(orig.build_py, Mixin2to3): Also, this version of the 'build_py' command allows you to specify both 'py_modules' and 'packages' in the same setup operation. """ + def finalize_options(self): orig.build_py.finalize_options(self) 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.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 = [] @@ -51,13 +55,14 @@ class build_py(orig.build_py, Mixin2to3): self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=0)) def __getattr__(self, attr): - if attr=='data_files': # lazily compute data files + if attr == 'data_files': # lazily compute data files self.data_files = files = self._get_data_files() return files - return orig.build_py.__getattr__(self,attr) + return orig.build_py.__getattr__(self, attr) def build_module(self, module, module_file, package): - outfile, copied = orig.build_py.build_module(self, module, module_file, package) + outfile, copied = orig.build_py.build_module(self, module, module_file, + package) if copied: self.__updated_files.append(outfile) return outfile, copied @@ -74,12 +79,12 @@ class build_py(orig.build_py, Mixin2to3): build_dir = os.path.join(*([self.build_lib] + package.split('.'))) # Length of path to strip from found files - plen = len(src_dir)+1 + plen = len(src_dir) + 1 # Strip directory from globbed filenames filenames = [ file[plen:] for file in self.find_data_files(package, src_dir) - ] + ] data.append((package, src_dir, build_dir, filenames)) return data @@ -102,7 +107,8 @@ class build_py(orig.build_py, Mixin2to3): 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_2to3_doctests: + if (copied and + srcfile in self.distribution.convert_2to3_doctests): self.__doctests_2to3.append(outf) def analyze_manifest(self): @@ -117,21 +123,22 @@ class build_py(orig.build_py, Mixin2to3): self.run_command('egg_info') ei_cmd = self.get_finalized_command('egg_info') for path in ei_cmd.filelist.files: - d,f = os.path.split(assert_relative(path)) + d, f = os.path.split(assert_relative(path)) prev = None oldf = f - while d and d!=prev and d not in src_dirs: + while d and d != prev and d not in src_dirs: prev = d d, df = os.path.split(d) f = os.path.join(df, f) if d in src_dirs: - if path.endswith('.py') and f==oldf: - continue # it's a module, not data - mf.setdefault(src_dirs[d],[]).append(path) + if path.endswith('.py') and f == oldf: + continue # it's a module, not data + mf.setdefault(src_dirs[d], []).append(path) - def get_data_files(self): pass # kludge 2.4 for lazy computation + def get_data_files(self): + pass # kludge 2.4 for lazy computation - if sys.version<"2.4": # Python 2.4 already has this code + if sys.version < "2.4": # Python 2.4 already has this code def get_outputs(self, include_bytecode=1): """Return complete list of files copied to the build directory @@ -142,9 +149,9 @@ class build_py(orig.build_py, Mixin2to3): """ return orig.build_py.get_outputs(self, include_bytecode) + [ os.path.join(build_dir, filename) - for package, src_dir, build_dir,filenames in self.data_files + for package, src_dir, build_dir, filenames in self.data_files for filename in filenames - ] + ] def check_package(self, package, package_dir): """Check namespace packages' __init__ for declare_namespace""" @@ -160,25 +167,26 @@ class build_py(orig.build_py, Mixin2to3): return init_py for pkg in self.distribution.namespace_packages: - if pkg==package or pkg.startswith(package+'.'): + if pkg == package or pkg.startswith(package + '.'): break else: return init_py - f = open(init_py,'rbU') + f = open(init_py, 'rbU') if 'declare_namespace'.encode() not in f.read(): from distutils.errors import DistutilsError + raise DistutilsError( - "Namespace package problem: %s is a namespace package, but its\n" - "__init__.py does not call declare_namespace()! Please fix it.\n" - '(See the setuptools manual under "Namespace Packages" for ' - "details.)\n" % (package,) + "Namespace package problem: %s is a namespace package, but " + "its\n__init__.py does not call declare_namespace()! Please " + 'fix it.\n(See the setuptools manual under ' + '"Namespace Packages" for details.)\n"' % (package,) ) f.close() return init_py def initialize_options(self): - self.packages_checked={} + self.packages_checked = {} orig.build_py.initialize_options(self) def get_package_dir(self, package): @@ -202,7 +210,7 @@ class build_py(orig.build_py, Mixin2to3): seen = {} return [ f for f in files if f not in bad - and f not in seen and seen.setdefault(f,1) # ditch dupes + and f not in seen and seen.setdefault(f, 1) # ditch dupes ] @@ -210,6 +218,7 @@ def assert_relative(path): if not os.path.isabs(path): return path from distutils.errors import DistutilsSetupError + msg = textwrap.dedent(""" Error: setup script specifies an absolute path: -- cgit v1.2.1 From b16a6dd269e4fd283a78834c7f379c977aad0f6e Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Wed, 18 Feb 2015 21:09:01 +0100 Subject: Delete some dead code. --- setuptools/command/build_py.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 98080694..a873d54b 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -136,22 +136,7 @@ class build_py(orig.build_py, Mixin2to3): mf.setdefault(src_dirs[d], []).append(path) def get_data_files(self): - pass # kludge 2.4 for lazy computation - - if sys.version < "2.4": # Python 2.4 already has this code - def get_outputs(self, include_bytecode=1): - """Return complete list of files copied to the build directory - - This includes both '.py' files and data files, as well as '.pyc' - and '.pyo' files if 'include_bytecode' is true. (This method is - needed for the 'install_lib' command to do its job properly, and to - generate a correct installation manifest.) - """ - return orig.build_py.get_outputs(self, include_bytecode) + [ - os.path.join(build_dir, filename) - for package, src_dir, build_dir, filenames in self.data_files - for filename in filenames - ] + pass # Lazily compute data files in _get_data_files() function. def check_package(self, package, package_dir): """Check namespace packages' __init__ for declare_namespace""" -- cgit v1.2.1 From e76a139ca4fad75c4ce8b3bc95e0009ea0823eb5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 02:48:31 -0500 Subject: Use io.open in build_py --- setuptools/command/build_py.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index a873d54b..779adf2a 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -5,6 +5,8 @@ import os import sys import fnmatch import textwrap +import io + try: from setuptools.lib2to3_ex import Mixin2to3 @@ -157,7 +159,7 @@ class build_py(orig.build_py, Mixin2to3): else: return init_py - f = open(init_py, 'rbU') + f = io.open(init_py, 'rb') if 'declare_namespace'.encode() not in f.read(): from distutils.errors import DistutilsError -- cgit v1.2.1 From 2ef88b8e709f0c090a3f7f8c7f612aacbbcd648f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 02:49:48 -0500 Subject: Use context manager for closing file --- setuptools/command/build_py.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 779adf2a..c971626c 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -159,7 +159,8 @@ class build_py(orig.build_py, Mixin2to3): else: return init_py - f = io.open(init_py, 'rb') + with io.open(init_py, 'rb') as f: + contents = f.read() if 'declare_namespace'.encode() not in f.read(): from distutils.errors import DistutilsError @@ -169,7 +170,6 @@ class build_py(orig.build_py, Mixin2to3): 'fix it.\n(See the setuptools manual under ' '"Namespace Packages" for details.)\n"' % (package,) ) - f.close() return init_py def initialize_options(self): -- cgit v1.2.1 From d7b8b096a206b178d588049a396d5687dbe7235a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 02:50:30 -0500 Subject: Prefer bytes literal --- setuptools/command/build_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index c971626c..f0d76705 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -161,7 +161,7 @@ class build_py(orig.build_py, Mixin2to3): with io.open(init_py, 'rb') as f: contents = f.read() - if 'declare_namespace'.encode() not in f.read(): + if b'declare_namespace' not in f.read(): from distutils.errors import DistutilsError raise DistutilsError( -- cgit v1.2.1 From 2b2c7c76e8eda4c608183c8e75d9eb0123724135 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 02:51:23 -0500 Subject: Move import to top --- setuptools/command/build_py.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index f0d76705..43159c7c 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -6,6 +6,7 @@ import sys import fnmatch import textwrap import io +import distutils.errors try: @@ -162,9 +163,7 @@ class build_py(orig.build_py, Mixin2to3): with io.open(init_py, 'rb') as f: contents = f.read() if b'declare_namespace' not in f.read(): - from distutils.errors import DistutilsError - - raise DistutilsError( + raise distutils.errors.DistutilsError( "Namespace package problem: %s is a namespace package, but " "its\n__init__.py does not call declare_namespace()! Please " 'fix it.\n(See the setuptools manual under ' -- cgit v1.2.1 From fc28df6ec826b3bd1ffa89d55d3674aa89d2f5fc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 02:52:39 -0500 Subject: Remove hanging indent --- setuptools/command/build_py.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 43159c7c..e729f712 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -183,8 +183,10 @@ class build_py(orig.build_py, Mixin2to3): def exclude_data_files(self, package, src_dir, files): """Filter filenames for package's data files in 'src_dir'""" - globs = (self.exclude_package_data.get('', []) - + self.exclude_package_data.get(package, [])) + globs = ( + self.exclude_package_data.get('', []) + + self.exclude_package_data.get(package, []) + ) bad = [] for pattern in globs: bad.extend( -- cgit v1.2.1 From a0ad4c94c41a9af9f2479567139ba6489305b9cc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 02:59:46 -0500 Subject: Rewrite init/loop/extend as dual-for generator expression. --- setuptools/command/build_py.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index e729f712..5bbf0870 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -187,14 +187,14 @@ class build_py(orig.build_py, Mixin2to3): self.exclude_package_data.get('', []) + self.exclude_package_data.get(package, []) ) - bad = [] - for pattern in globs: - bad.extend( - fnmatch.filter( - files, os.path.join(src_dir, convert_path(pattern)) - ) + bad = dict.fromkeys( + item + for pattern in globs + for item in fnmatch.filter( + files, + os.path.join(src_dir, convert_path(pattern)), ) - bad = dict.fromkeys(bad) + ) seen = {} return [ f for f in files if f not in bad -- cgit v1.2.1 From 4e960934f61c50b98953d6cd12b72b30e85bccf3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 03:00:28 -0500 Subject: Prefer set to dict.fromkeys --- setuptools/command/build_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 5bbf0870..3ae331fd 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -187,7 +187,7 @@ class build_py(orig.build_py, Mixin2to3): self.exclude_package_data.get('', []) + self.exclude_package_data.get(package, []) ) - bad = dict.fromkeys( + bad = set( item for pattern in globs for item in fnmatch.filter( -- cgit v1.2.1 From 3744e23d533ab5b0ebcb34f6d8792777c3433014 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 03:14:08 -0500 Subject: Reindent to remove trailing comment --- setuptools/command/build_py.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 3ae331fd..55aed230 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -197,8 +197,12 @@ class build_py(orig.build_py, Mixin2to3): ) seen = {} return [ - f for f in files if f not in bad - and f not in seen and seen.setdefault(f, 1) # ditch dupes + fn + for fn in files + if fn not in bad + # ditch dupes + and fn not in seen + and seen.setdefault(fn, 1) ] -- cgit v1.2.1 From a8d85057026bc070b2f73b57133f1910218ad815 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 03:20:12 -0500 Subject: Use a defaultdict and count to track seen items --- setuptools/command/build_py.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 55aed230..317dbba4 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -7,6 +7,8 @@ import fnmatch import textwrap import io import distutils.errors +import collections +import itertools try: @@ -195,14 +197,13 @@ class build_py(orig.build_py, Mixin2to3): os.path.join(src_dir, convert_path(pattern)), ) ) - seen = {} + seen = collections.defaultdict(itertools.count) return [ fn for fn in files if fn not in bad # ditch dupes - and fn not in seen - and seen.setdefault(fn, 1) + and not next(seen[fn]) ] -- cgit v1.2.1 From 1c7e97f95ea74c241b91dfb975c709940ba00f47 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 03:26:58 -0500 Subject: Remove unused import --- setuptools/command/build_py.py | 1 - 1 file changed, 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 317dbba4..b2dafec9 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -2,7 +2,6 @@ from glob import glob from distutils.util import convert_path import distutils.command.build_py as orig import os -import sys import fnmatch import textwrap import io -- cgit v1.2.1 From 41112f5afd0d2b0c14899ab1cf2c27183e64d6ac Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 03:34:35 -0500 Subject: Use io.open for future compatibility and consistency --- setuptools/command/build_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index b2dafec9..8a50f032 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -163,7 +163,7 @@ class build_py(orig.build_py, Mixin2to3): with io.open(init_py, 'rb') as f: contents = f.read() - if b'declare_namespace' not in f.read(): + if b'declare_namespace' not in contents: raise distutils.errors.DistutilsError( "Namespace package problem: %s is a namespace package, but " "its\n__init__.py does not call declare_namespace()! Please " -- cgit v1.2.1 From 434aef220e6ec7cfc609bce631ef8528c930c20c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Jan 2016 06:11:13 -0500 Subject: Move trailing comment to docstring --- setuptools/command/build_py.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 8a50f032..32e37e52 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -59,7 +59,8 @@ class build_py(orig.build_py, Mixin2to3): self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=0)) def __getattr__(self, attr): - if attr == 'data_files': # lazily compute data files + "lazily compute data files" + if attr == 'data_files': self.data_files = files = self._get_data_files() return files return orig.build_py.__getattr__(self, attr) -- cgit v1.2.1 From f55db00043f3f47b7121c42d54433bc80a01c243 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Jan 2016 06:11:54 -0500 Subject: Remove superfluous local variable --- setuptools/command/build_py.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 32e37e52..c24646c3 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -61,8 +61,8 @@ class build_py(orig.build_py, Mixin2to3): def __getattr__(self, attr): "lazily compute data files" if attr == 'data_files': - self.data_files = files = self._get_data_files() - return files + self.data_files = self._get_data_files() + return self.data_files return orig.build_py.__getattr__(self, attr) def build_module(self, module, module_file, package): -- cgit v1.2.1 From 775cb73ed72e87951254bbbe373951be9caac4df Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Jan 2016 06:16:11 -0500 Subject: Extract function for getting data files for package. --- setuptools/command/build_py.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index c24646c3..3ddc7673 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -75,8 +75,9 @@ class build_py(orig.build_py, Mixin2to3): def _get_data_files(self): """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" self.analyze_manifest() - data = [] - for package in self.packages or (): + return list(map(self._get_pkg_data_files, self.packages or ())) + + def _get_pkg_data_files(self, package): # Locate package source directory src_dir = self.get_package_dir(package) @@ -90,8 +91,7 @@ class build_py(orig.build_py, Mixin2to3): filenames = [ file[plen:] for file in self.find_data_files(package, src_dir) ] - data.append((package, src_dir, build_dir, filenames)) - return data + return package, src_dir, build_dir, filenames def find_data_files(self, package, src_dir): """Return filenames for package's data files in 'src_dir'""" -- cgit v1.2.1 From ddfbfa731e2cf73dc03b5a3345996afac843441e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Jan 2016 06:16:39 -0500 Subject: Reindent --- setuptools/command/build_py.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 3ddc7673..5021bd1f 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -78,20 +78,20 @@ class build_py(orig.build_py, Mixin2to3): return list(map(self._get_pkg_data_files, self.packages or ())) def _get_pkg_data_files(self, package): - # Locate package source directory - src_dir = self.get_package_dir(package) + # Locate package source directory + src_dir = self.get_package_dir(package) - # Compute package build directory - build_dir = os.path.join(*([self.build_lib] + package.split('.'))) + # Compute package build directory + build_dir = os.path.join(*([self.build_lib] + package.split('.'))) - # Length of path to strip from found files - plen = len(src_dir) + 1 + # Length of path to strip from found files + plen = len(src_dir) + 1 - # Strip directory from globbed filenames - filenames = [ - file[plen:] for file in self.find_data_files(package, src_dir) - ] - return package, src_dir, build_dir, filenames + # Strip directory from globbed filenames + filenames = [ + file[plen:] for file in self.find_data_files(package, src_dir) + ] + return package, src_dir, build_dir, filenames def find_data_files(self, package, src_dir): """Return filenames for package's data files in 'src_dir'""" -- cgit v1.2.1 From 0f590c0d72709128f32c23437fe0183386c69d1c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Jan 2016 06:33:04 -0500 Subject: Prefer relpath to string slicing for computing a path relative to a base. Fixes #341. --- setuptools/command/build_py.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 5021bd1f..0c1026aa 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -84,12 +84,10 @@ class build_py(orig.build_py, Mixin2to3): # Compute package build directory build_dir = os.path.join(*([self.build_lib] + package.split('.'))) - # Length of path to strip from found files - plen = len(src_dir) + 1 - # Strip directory from globbed filenames filenames = [ - file[plen:] for file in self.find_data_files(package, src_dir) + os.path.relpath(file, src_dir) + for file in self.find_data_files(package, src_dir) ] return package, src_dir, build_dir, filenames -- cgit v1.2.1 From 8af3b6ef5b4173a0d0d6735147c98c882ae98344 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Jan 2016 06:54:00 -0500 Subject: Always use Python 3 version of map --- setuptools/command/build_py.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 0c1026aa..8623c777 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -9,6 +9,7 @@ import distutils.errors import collections import itertools +from setuptools.extern.six.moves import map try: from setuptools.lib2to3_ex import Mixin2to3 -- cgit v1.2.1 From 4f6fc8537842c14b03c4a1ffd25b88f2f4c276c6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 22 May 2016 14:55:31 -0400 Subject: Use itertools.chain for more lenient support of any iterable types and also more uniform indentation. --- setuptools/command/build_py.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 8623c777..3849b6ad 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -94,8 +94,10 @@ class build_py(orig.build_py, Mixin2to3): def find_data_files(self, package, src_dir): """Return filenames for package's data files in 'src_dir'""" - globs = (self.package_data.get('', []) - + self.package_data.get(package, [])) + globs = itertools.chain( + self.package_data.get('', []), + self.package_data.get(package, []), + ) files = self.manifest_files.get(package, [])[:] for pattern in globs: # Each pattern has to be converted to a platform-specific path -- cgit v1.2.1 From 2d765a69b19bb92882582249942d607684dd14eb Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 22 May 2016 15:18:04 -0400 Subject: Refactor build_py.find_data_files to use iterables, constructing the files list directly. Ref #261. --- setuptools/command/build_py.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 3849b6ad..34f39037 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -98,10 +98,18 @@ class build_py(orig.build_py, Mixin2to3): self.package_data.get('', []), self.package_data.get(package, []), ) - files = self.manifest_files.get(package, [])[:] - for pattern in globs: + globs_expanded = ( # Each pattern has to be converted to a platform-specific path - files.extend(glob(os.path.join(src_dir, convert_path(pattern)))) + glob(os.path.join(src_dir, convert_path(pattern))) + for pattern in globs + ) + # flatten the expanded globs into an iterable of matches + globs_matches = itertools.chain.from_iterable(globs_expanded) + glob_files = globs_matches + files = list(itertools.chain( + self.manifest_files.get(package, []), + glob_files, + )) return self.exclude_data_files(package, src_dir, files) def build_package_data(self): -- cgit v1.2.1 From 8f0ac47db9fe2934725aa9c8a7b0089451ed033d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 22 May 2016 15:18:32 -0400 Subject: Filter non-files in find_data_files. Fixes #261. --- setuptools/command/build_py.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 34f39037..23e8b31c 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -9,7 +9,7 @@ import distutils.errors import collections import itertools -from setuptools.extern.six.moves import map +from setuptools.extern.six.moves import map, filter try: from setuptools.lib2to3_ex import Mixin2to3 @@ -105,7 +105,7 @@ class build_py(orig.build_py, Mixin2to3): ) # flatten the expanded globs into an iterable of matches globs_matches = itertools.chain.from_iterable(globs_expanded) - glob_files = globs_matches + glob_files = filter(os.path.isfile, globs_matches) files = list(itertools.chain( self.manifest_files.get(package, []), glob_files, -- cgit v1.2.1 From dde1bfbf9aca70f4d78c349059ba43b3d40eb0e5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 22 May 2016 15:21:28 -0400 Subject: Rewrite globs as chain of iterables. --- setuptools/command/build_py.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 23e8b31c..4ce35314 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -194,9 +194,9 @@ class build_py(orig.build_py, Mixin2to3): def exclude_data_files(self, package, src_dir, files): """Filter filenames for package's data files in 'src_dir'""" - globs = ( - self.exclude_package_data.get('', []) - + self.exclude_package_data.get(package, []) + globs = itertools.chain( + self.exclude_package_data.get('', []), + self.exclude_package_data.get(package, []), ) bad = set( item -- cgit v1.2.1 From ba0b4d2eb91961a2237064850deca9e711ee4368 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 22 May 2016 15:22:09 -0400 Subject: Allow files to be iterable in exclude_data_files --- setuptools/command/build_py.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 4ce35314..41b2660c 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -106,10 +106,10 @@ class build_py(orig.build_py, Mixin2to3): # flatten the expanded globs into an iterable of matches globs_matches = itertools.chain.from_iterable(globs_expanded) glob_files = filter(os.path.isfile, globs_matches) - files = list(itertools.chain( + files = itertools.chain( self.manifest_files.get(package, []), glob_files, - )) + ) return self.exclude_data_files(package, src_dir, files) def build_package_data(self): @@ -198,6 +198,7 @@ class build_py(orig.build_py, Mixin2to3): self.exclude_package_data.get('', []), self.exclude_package_data.get(package, []), ) + files = list(files) bad = set( item for pattern in globs -- cgit v1.2.1 From c05fd0799bb2a83ab877f317e8630a403a3514f7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 22 May 2016 15:40:01 -0400 Subject: Rewrite find_data_files and exclude_data_files to follow the same pattern for building platform_patterns. --- setuptools/command/build_py.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 41b2660c..cd91a85e 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -94,15 +94,17 @@ class build_py(orig.build_py, Mixin2to3): def find_data_files(self, package, src_dir): """Return filenames for package's data files in 'src_dir'""" - globs = itertools.chain( - self.package_data.get('', []), - self.package_data.get(package, []), + spec = self.package_data + raw_patterns = itertools.chain( + spec.get('', []), + spec.get(package, []), ) - globs_expanded = ( + platform_patterns = ( # Each pattern has to be converted to a platform-specific path - glob(os.path.join(src_dir, convert_path(pattern))) - for pattern in globs + os.path.join(src_dir, convert_path(pattern)) + for pattern in raw_patterns ) + globs_expanded = map(glob, platform_patterns) # flatten the expanded globs into an iterable of matches globs_matches = itertools.chain.from_iterable(globs_expanded) glob_files = filter(os.path.isfile, globs_matches) @@ -194,19 +196,24 @@ class build_py(orig.build_py, Mixin2to3): def exclude_data_files(self, package, src_dir, files): """Filter filenames for package's data files in 'src_dir'""" - globs = itertools.chain( - self.exclude_package_data.get('', []), - self.exclude_package_data.get(package, []), - ) files = list(files) - bad = set( - item - for pattern in globs - for item in fnmatch.filter( - files, - os.path.join(src_dir, convert_path(pattern)), - ) + spec = self.exclude_package_data + raw_patterns = itertools.chain( + spec.get('', []), + spec.get(package, []), + ) + platform_patterns = ( + # Each pattern has to be converted to a platform-specific path + os.path.join(src_dir, convert_path(pattern)) + for pattern in raw_patterns + ) + match_groups = ( + fnmatch.filter(files, pattern) + for pattern in platform_patterns ) + # flatten the groups of matches into an iterable of matches + matches = itertools.chain.from_iterable(match_groups) + bad = set(matches) seen = collections.defaultdict(itertools.count) return [ fn -- cgit v1.2.1 From 1af011b1f1dac17485c0cf8fe9eb08c43b5b6f2a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 22 May 2016 15:53:06 -0400 Subject: Extract duplicate code into a single method. --- setuptools/command/build_py.py | 48 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index cd91a85e..1db0acb9 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -94,17 +94,12 @@ class build_py(orig.build_py, Mixin2to3): def find_data_files(self, package, src_dir): """Return filenames for package's data files in 'src_dir'""" - spec = self.package_data - raw_patterns = itertools.chain( - spec.get('', []), - spec.get(package, []), - ) - platform_patterns = ( - # Each pattern has to be converted to a platform-specific path - os.path.join(src_dir, convert_path(pattern)) - for pattern in raw_patterns + patterns = self._get_platform_patterns( + self.package_data, + package, + src_dir, ) - globs_expanded = map(glob, platform_patterns) + globs_expanded = map(glob, patterns) # flatten the expanded globs into an iterable of matches globs_matches = itertools.chain.from_iterable(globs_expanded) glob_files = filter(os.path.isfile, globs_matches) @@ -197,19 +192,14 @@ class build_py(orig.build_py, Mixin2to3): def exclude_data_files(self, package, src_dir, files): """Filter filenames for package's data files in 'src_dir'""" files = list(files) - spec = self.exclude_package_data - raw_patterns = itertools.chain( - spec.get('', []), - spec.get(package, []), - ) - platform_patterns = ( - # Each pattern has to be converted to a platform-specific path - os.path.join(src_dir, convert_path(pattern)) - for pattern in raw_patterns + patterns = self._get_platform_patterns( + self.exclude_package_data, + package, + src_dir, ) match_groups = ( fnmatch.filter(files, pattern) - for pattern in platform_patterns + for pattern in patterns ) # flatten the groups of matches into an iterable of matches matches = itertools.chain.from_iterable(match_groups) @@ -223,6 +213,24 @@ class build_py(orig.build_py, Mixin2to3): and not next(seen[fn]) ] + @staticmethod + def _get_platform_patterns(spec, package, src_dir): + """ + yield platfrom-specific path patterns (suitable for glob + or fn_match) from a glob-based spec (such as + self.package_data or self.exclude_package_data) + matching package in src_dir. + """ + raw_patterns = itertools.chain( + spec.get('', []), + spec.get(package, []), + ) + return ( + # Each pattern has to be converted to a platform-specific path + os.path.join(src_dir, convert_path(pattern)) + for pattern in raw_patterns + ) + def assert_relative(path): if not os.path.isabs(path): -- cgit v1.2.1 From e75bb0594bad10cb307620359abcd3b5779ecfd2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 22 May 2016 15:59:45 -0400 Subject: Re-use unique_everseen from itertools recipes. --- setuptools/command/build_py.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 1db0acb9..758a3fdf 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -6,10 +6,9 @@ import fnmatch import textwrap import io import distutils.errors -import collections import itertools -from setuptools.extern.six.moves import map, filter +from setuptools.extern.six.moves import map, filter, filterfalse try: from setuptools.lib2to3_ex import Mixin2to3 @@ -204,14 +203,13 @@ class build_py(orig.build_py, Mixin2to3): # flatten the groups of matches into an iterable of matches matches = itertools.chain.from_iterable(match_groups) bad = set(matches) - seen = collections.defaultdict(itertools.count) - return [ + keepers = ( fn for fn in files if fn not in bad - # ditch dupes - and not next(seen[fn]) - ] + ) + # ditch dupes + return list(_unique_everseen(keepers)) @staticmethod def _get_platform_patterns(spec, package, src_dir): @@ -232,6 +230,25 @@ class build_py(orig.build_py, Mixin2to3): ) +# from Python docs +def _unique_everseen(iterable, key=None): + "List unique elements, preserving order. Remember all elements ever seen." + # unique_everseen('AAAABBBCCDAABBB') --> A B C D + # unique_everseen('ABBCcAD', str.lower) --> A B C D + seen = set() + seen_add = seen.add + if key is None: + for element in filterfalse(seen.__contains__, iterable): + seen_add(element) + yield element + else: + for element in iterable: + k = key(element) + if k not in seen: + seen_add(k) + yield element + + def assert_relative(path): if not os.path.isabs(path): return path -- cgit v1.2.1 From 11d5bb9e47754f0f4ded5379450e83e29d3661fb Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 2 Jun 2016 11:58:43 +0200 Subject: Fixing #190 following proposal by @jaraco --- setuptools/command/build_py.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 758a3fdf..0bad8295 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -8,6 +8,7 @@ import io import distutils.errors import itertools +from setuptools.extern import six from setuptools.extern.six.moves import map, filter, filterfalse try: @@ -66,6 +67,9 @@ class build_py(orig.build_py, Mixin2to3): return orig.build_py.__getattr__(self, attr) def build_module(self, module, module_file, package): + if six.PY2 and isinstance(package, six.string_types): + # avoid errors on Python 2 when unicode is passed (#190) + package = package.split('.') outfile, copied = orig.build_py.build_module(self, module, module_file, package) if copied: -- cgit v1.2.1 From 6d11e88f938f09ef16db4c6064b6e74acba4db1d Mon Sep 17 00:00:00 2001 From: stepshal Date: Tue, 12 Jul 2016 22:00:43 +0700 Subject: Fix quantity of blank lines after code object. --- setuptools/command/build_py.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 0bad8295..b5de9bda 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -15,6 +15,7 @@ try: from setuptools.lib2to3_ex import Mixin2to3 except ImportError: class Mixin2to3: + def run_2to3(self, files, doctests=True): "do nothing" -- cgit v1.2.1 From ed3fac3741f01ce05c139216e5af58c238c63f29 Mon Sep 17 00:00:00 2001 From: stepshal Date: Wed, 19 Oct 2016 00:23:56 +0700 Subject: Fix quantity of blank lines. --- setuptools/command/build_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index b5de9bda..289e6fb8 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -14,8 +14,8 @@ from setuptools.extern.six.moves import map, filter, filterfalse try: from setuptools.lib2to3_ex import Mixin2to3 except ImportError: - class Mixin2to3: + class Mixin2to3: def run_2to3(self, files, doctests=True): "do nothing" -- cgit v1.2.1 From 1ca6f3bf272d8ba2c0d4161cc56a74c63c8afb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 7 Dec 2016 14:59:34 +0200 Subject: Spelling fixes --- setuptools/command/build_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 289e6fb8..b0314fd4 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -219,7 +219,7 @@ class build_py(orig.build_py, Mixin2to3): @staticmethod def _get_platform_patterns(spec, package, src_dir): """ - yield platfrom-specific path patterns (suitable for glob + yield platform-specific path patterns (suitable for glob or fn_match) from a glob-based spec (such as self.package_data or self.exclude_package_data) matching package in src_dir. -- cgit v1.2.1 From ff371f18f0076bc63da05334f7e551c1cc29e10d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 1 Jan 2017 22:34:28 -0500 Subject: Strip out vendored packages and require them instead. Ref #581. --- setuptools/command/build_py.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index b0314fd4..56daa2bd 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -8,8 +8,8 @@ import io import distutils.errors import itertools -from setuptools.extern import six -from setuptools.extern.six.moves import map, filter, filterfalse +import six +from six.moves import map, filter, filterfalse try: from setuptools.lib2to3_ex import Mixin2to3 -- cgit v1.2.1 From 3d0cc355fb5e8012cb8c72f0e25042a5a44f31d6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 24 Feb 2017 11:49:51 -0500 Subject: Revert "Merge pull request #933 from pypa/feature/581-depend-not-bundle" This reverts commit 089cdeb489a0fa94d11b7307b54210ef9aa40511, reversing changes made to aaec654d804cb78dbb6391afff721a63f26a71cd. --- setuptools/command/build_py.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 56daa2bd..b0314fd4 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -8,8 +8,8 @@ import io import distutils.errors import itertools -import six -from six.moves import map, filter, filterfalse +from setuptools.extern import six +from setuptools.extern.six.moves import map, filter, filterfalse try: from setuptools.lib2to3_ex import Mixin2to3 -- cgit v1.2.1 From 7843688bc33dd4e13e10130bc49da4c290fe7d7f Mon Sep 17 00:00:00 2001 From: Dmitry Kuznetsov Date: Tue, 11 Dec 2018 20:35:24 -0800 Subject: Don't keep file modes for package data. --- setuptools/command/build_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index b0314fd4..6fc0a4e4 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -120,7 +120,7 @@ class build_py(orig.build_py, Mixin2to3): target = os.path.join(build_dir, filename) self.mkpath(os.path.dirname(target)) srcfile = os.path.join(src_dir, filename) - outf, copied = self.copy_file(srcfile, target) + outf, copied = self.copy_file(srcfile, target, preserve_mode=False) srcfile = os.path.abspath(srcfile) if (copied and srcfile in self.distribution.convert_2to3_doctests): -- cgit v1.2.1 From 512565ee5090b8c1b685102c9ffb6195c99e32c2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 21 Mar 2020 15:00:03 -0400 Subject: =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20(delint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setuptools/command/build_py.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 6fc0a4e4..bac4fb1c 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -120,7 +120,8 @@ class build_py(orig.build_py, Mixin2to3): target = os.path.join(build_dir, filename) self.mkpath(os.path.dirname(target)) srcfile = os.path.join(src_dir, filename) - outf, copied = self.copy_file(srcfile, target, preserve_mode=False) + outf, copied = self.copy_file( + srcfile, target, preserve_mode=False) srcfile = os.path.abspath(srcfile) if (copied and srcfile in self.distribution.convert_2to3_doctests): -- cgit v1.2.1 From 70e95ee66a17e1655f70c9dbda107cea958f583f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 25 Mar 2020 13:44:58 -0400 Subject: When copying package data, make sure it's writable, but otherwise preserve the mode. Fixes #2041. --- setuptools/command/build_py.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index bac4fb1c..9d0288a5 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -7,6 +7,7 @@ import textwrap import io import distutils.errors import itertools +import stat from setuptools.extern import six from setuptools.extern.six.moves import map, filter, filterfalse @@ -20,6 +21,10 @@ except ImportError: "do nothing" +def make_writable(target): + os.chmod(target, os.stat(target).st_mode | stat.S_IWRITE) + + class build_py(orig.build_py, Mixin2to3): """Enhanced 'build_py' command that includes data files with packages @@ -120,8 +125,8 @@ class build_py(orig.build_py, Mixin2to3): target = os.path.join(build_dir, filename) self.mkpath(os.path.dirname(target)) srcfile = os.path.join(src_dir, filename) - outf, copied = self.copy_file( - srcfile, target, preserve_mode=False) + outf, copied = self.copy_file(srcfile, target) + make_writable(target) srcfile = os.path.abspath(srcfile) if (copied and srcfile in self.distribution.convert_2to3_doctests): -- cgit v1.2.1 From fb7ab81a3d080422687bad71f9ae9d36eeefbee2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 16 Aug 2020 00:29:24 -0400 Subject: Remove Python 2 compatibility --- setuptools/command/build_py.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 9d0288a5..4709679b 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -9,9 +9,6 @@ import distutils.errors import itertools import stat -from setuptools.extern import six -from setuptools.extern.six.moves import map, filter, filterfalse - try: from setuptools.lib2to3_ex import Mixin2to3 except ImportError: @@ -73,9 +70,6 @@ class build_py(orig.build_py, Mixin2to3): return orig.build_py.__getattr__(self, attr) def build_module(self, module, module_file, package): - if six.PY2 and isinstance(package, six.string_types): - # avoid errors on Python 2 when unicode is passed (#190) - package = package.split('.') outfile, copied = orig.build_py.build_module(self, module, module_file, package) if copied: @@ -249,7 +243,7 @@ def _unique_everseen(iterable, key=None): seen = set() seen_add = seen.add if key is None: - for element in filterfalse(seen.__contains__, iterable): + for element in itertools.filterfalse(seen.__contains__, iterable): seen_add(element) yield element else: -- cgit v1.2.1 From 997eae8020dc28ea1ef87572275f5dc41e1bc74a Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sun, 4 Oct 2020 16:11:27 +0100 Subject: ignore any exception when loading 2to3 --- setuptools/command/build_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 4709679b..b30aa129 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -11,7 +11,7 @@ import stat try: from setuptools.lib2to3_ex import Mixin2to3 -except ImportError: +except Exception: class Mixin2to3: def run_2to3(self, files, doctests=True): -- cgit v1.2.1 From 9c2cf25a13bf33a3fd706c97064c0d2fa22be179 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 22 May 2021 19:19:05 -0400 Subject: Use unique_everseen from more_itertools. --- setuptools/command/build_py.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index b30aa129..df6fd323 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -8,6 +8,7 @@ import io import distutils.errors import itertools import stat +from setuptools.extern.more_itertools import unique_everseen try: from setuptools.lib2to3_ex import Mixin2to3 @@ -214,7 +215,7 @@ class build_py(orig.build_py, Mixin2to3): if fn not in bad ) # ditch dupes - return list(_unique_everseen(keepers)) + return list(unique_everseen(keepers)) @staticmethod def _get_platform_patterns(spec, package, src_dir): @@ -235,25 +236,6 @@ class build_py(orig.build_py, Mixin2to3): ) -# from Python docs -def _unique_everseen(iterable, key=None): - "List unique elements, preserving order. Remember all elements ever seen." - # unique_everseen('AAAABBBCCDAABBB') --> A B C D - # unique_everseen('ABBCcAD', str.lower) --> A B C D - seen = set() - seen_add = seen.add - if key is None: - for element in itertools.filterfalse(seen.__contains__, iterable): - seen_add(element) - yield element - else: - for element in iterable: - k = key(element) - if k not in seen: - seen_add(k) - yield element - - def assert_relative(path): if not os.path.isabs(path): return path -- cgit v1.2.1 From ca296ca8663a376f3c36c9f8fd86b10ba81366c2 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sun, 18 Jul 2021 09:27:21 +0100 Subject: remove lib2to3 usage --- setuptools/command/build_py.py | 44 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index df6fd323..6a615433 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -10,20 +10,12 @@ import itertools import stat from setuptools.extern.more_itertools import unique_everseen -try: - from setuptools.lib2to3_ex import Mixin2to3 -except Exception: - - class Mixin2to3: - def run_2to3(self, files, doctests=True): - "do nothing" - def make_writable(target): os.chmod(target, os.stat(target).st_mode | stat.S_IWRITE) -class build_py(orig.build_py, Mixin2to3): +class build_py(orig.build_py): """Enhanced 'build_py' command that includes data files with packages The data files are specified via a 'package_data' argument to 'setup()'. @@ -36,12 +28,10 @@ class build_py(orig.build_py, Mixin2to3): def finalize_options(self): orig.build_py.finalize_options(self) self.package_data = self.distribution.package_data - self.exclude_package_data = (self.distribution.exclude_package_data or - {}) + 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""" @@ -55,10 +45,6 @@ class build_py(orig.build_py, Mixin2to3): self.build_packages() self.build_package_data() - 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. self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=0)) @@ -71,8 +57,7 @@ class build_py(orig.build_py, Mixin2to3): return orig.build_py.__getattr__(self, attr) def build_module(self, module, module_file, package): - outfile, copied = orig.build_py.build_module(self, module, module_file, - package) + outfile, copied = orig.build_py.build_module(self, module, module_file, package) if copied: self.__updated_files.append(outfile) return outfile, copied @@ -123,9 +108,6 @@ class build_py(orig.build_py, Mixin2to3): outf, copied = self.copy_file(srcfile, target) make_writable(target) srcfile = os.path.abspath(srcfile) - if (copied and - srcfile in self.distribution.convert_2to3_doctests): - self.__doctests_2to3.append(outf) def analyze_manifest(self): self.manifest_files = mf = {} @@ -202,18 +184,11 @@ class build_py(orig.build_py, Mixin2to3): package, src_dir, ) - match_groups = ( - fnmatch.filter(files, pattern) - for pattern in patterns - ) + match_groups = (fnmatch.filter(files, pattern) for pattern in patterns) # flatten the groups of matches into an iterable of matches matches = itertools.chain.from_iterable(match_groups) bad = set(matches) - keepers = ( - fn - for fn in files - if fn not in bad - ) + keepers = (fn for fn in files if fn not in bad) # ditch dupes return list(unique_everseen(keepers)) @@ -241,12 +216,17 @@ def assert_relative(path): return path from distutils.errors import DistutilsSetupError - msg = textwrap.dedent(""" + msg = ( + textwrap.dedent( + """ Error: setup script specifies an absolute path: %s setup() arguments must *always* be /-separated paths relative to the setup.py directory, *never* absolute paths. - """).lstrip() % path + """ + ).lstrip() + % path + ) raise DistutilsSetupError(msg) -- cgit v1.2.1 From 2e66eb7147ae1e8a799b2276c7340f48f63a7220 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 1 Nov 2021 19:47:33 +0000 Subject: Fix 1461: Better loop breaker for `manifest_maker` The inconsistency for the `package_data` configuration in sdists when `include_package_data=True` in #1461 have been causing some problems for the community for a while, as also shown in #2835. As pointed out by [@jaraco](https://github.com/pypa/setuptools/issues/1461#issuecomment-749092366), this was being caused by a mechanism to break the recursion between the `egg_info` and `sdist` commands. In summary the loop is caused by the following behaviour: - the `egg_info` command uses a subclass of `sdist` (`manifest_maker`) to calculate the MANIFEST, - the `sdist` class needs to know the MANIFEST to calculate the data files when `include_package_data=True` Previously, the mechanism to break this loop was to simply ignore the data files in `sdist` when `include_package_data=True`. The approach implemented in this change was to replace this mechanism, by allowing `manifest_maker` to override the `_safe_data_files` method from `sdist`. --- Please notice [an extensive experiment] (https://github.com/abravalheri/experiment-setuptools-package-data) was carried out to investigate the previous confusing behaviour. There is also [a simplified theoretical analysis] (https://github.com/pyscaffold/pyscaffold/pull/535#issuecomment-956296407) comparing the observed behavior in the experiment and the expected one. This analysis point out to the same offender indicated by [@jaraco](https://github.com/pypa/setuptools/issues/1461#issuecomment-749092366) (which is being replaced in this change). --- setuptools/command/build_py.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 6a615433..f71c5a56 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -67,6 +67,19 @@ class build_py(orig.build_py): self.analyze_manifest() return list(map(self._get_pkg_data_files, self.packages or ())) + def get_data_files_without_manifest(self): + """ + Generate list of ``(package,src_dir,build_dir,filenames)`` tuples, + but without triggering any attempt to analyze or build the manifest. + """ + # Avoid triggering dynamic behavior in __getattr__ + if 'data_files' in self.__dict__: + return self.data_files + # Prevent eventual errors from unset `manifest_files` + # (that would otherwise be set by `analyze_manifest`) + self.__dict__.setdefault('manifest_files', {}) + return list(map(self._get_pkg_data_files, self.packages or ())) + def _get_pkg_data_files(self, package): # Locate package source directory src_dir = self.get_package_dir(package) -- cgit v1.2.1 From b8ad7d2ca1abc59e42e63ecf484036d021a2e19c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 2 Nov 2021 21:08:01 -0400 Subject: Remove data_files avoidance code. --- setuptools/command/build_py.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index f71c5a56..c3fdc092 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -72,9 +72,6 @@ class build_py(orig.build_py): Generate list of ``(package,src_dir,build_dir,filenames)`` tuples, but without triggering any attempt to analyze or build the manifest. """ - # Avoid triggering dynamic behavior in __getattr__ - if 'data_files' in self.__dict__: - return self.data_files # Prevent eventual errors from unset `manifest_files` # (that would otherwise be set by `analyze_manifest`) self.__dict__.setdefault('manifest_files', {}) -- cgit v1.2.1