From e9230cf512726e5ea428028c564a5b6a36b91095 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 21 Mar 2005 19:50:46 +0000 Subject: Add 'bdist_egg' command/format to allow creating "Python Eggs" (see http://peak.telecommunity.com/DevCenter/PythonEggs for details). This version only supports pure libraries and does not support user-defined metadata. But it's sufficient to make .egg files that can be placed on PYTHONPATH and used. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040989 --- setuptools/command/bdist_egg.py | 144 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 setuptools/command/bdist_egg.py (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py new file mode 100644 index 00000000..29c8fa5c --- /dev/null +++ b/setuptools/command/bdist_egg.py @@ -0,0 +1,144 @@ +"""setuptools.command.bdist_egg + +Build .egg distributions""" + +# This module should be kept compatible with Python 2.1 + +import os +from distutils.core import Command +from distutils.util import get_platform +from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath +from distutils.errors import * +from distutils import log + +class bdist_egg(Command): + + description = "create an \"egg\" distribution" + + user_options = [('bdist-dir=', 'd', + "temporary directory for creating the distribution"), + ('plat-name=', 'p', + "platform name to embed in generated filenames " + "(default: %s)" % get_platform()), + ('keep-temp', 'k', + "keep the pseudo-installation tree around after " + + "creating the distribution archive"), + ('dist-dir=', 'd', + "directory to put final built distributions in"), + ('skip-build', None, + "skip rebuilding everything (for testing/debugging)"), + ('relative', None, + "build the archive using relative paths" + "(default: false)"), + ] + + boolean_options = ['keep-temp', 'skip-build', 'relative'] + + + def initialize_options (self): + self.bdist_dir = None + self.plat_name = None + self.keep_temp = 0 + self.dist_dir = None + self.skip_build = 0 + self.relative = 0 + + # initialize_options() + + + def finalize_options (self): + + if self.bdist_dir is None: + bdist_base = self.get_finalized_command('bdist').bdist_base + self.bdist_dir = os.path.join(bdist_base, 'egg') + + self.set_undefined_options('bdist', + ('dist_dir', 'dist_dir'), + ('plat_name', 'plat_name')) + + # finalize_options() + + + def run (self): + + if not self.skip_build: + self.run_command('build') + + install = self.reinitialize_command('install_lib', reinit_subcommands=1) + install.install_dir = self.bdist_dir + install.skip_build = self.skip_build + install.warn_dir = 0 + + log.info("installing to %s" % self.bdist_dir) + self.run_command('install_lib') + + # And make an archive relative to the root of the + # pseudo-installation tree. + archive_basename = "%s-%s" % (self.distribution.get_fullname(), + self.plat_name) + + # OS/2 objects to any ":" characters in a filename (such as when + # a timestamp is used in a version) so change them to hyphens. + if os.name == "os2": + archive_basename = archive_basename.replace(":", "-") + + pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) + archive_root = self.bdist_dir + + # Make the EGG-INFO directory + log.info("creating EGG-INFO files") + egg_info = os.path.join(archive_root,'EGG-INFO') + self.mkpath(egg_info) + + if not self.dry_run: + self.distribution.metadata.write_pkg_info(egg_info) + + # Make the archive + make_zipfile(pseudoinstall_root+'.egg', + archive_root, verbose=self.verbose, + dry_run=self.dry_run) + + if not self.keep_temp: + remove_tree(self.bdist_dir, dry_run=self.dry_run) + + # run() + +# class bdist_egg + + + +def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): + """Create a zip file from all the files under 'base_dir'. The output + zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" + Python module (if available) or the InfoZIP "zip" utility (if installed + and found on the default search path). If neither tool is available, + raises DistutilsExecError. Returns the name of the output zip file. + """ + import zipfile + + mkpath(os.path.dirname(zip_filename), dry_run=dry_run) + + # If zipfile module is not available, try spawning an external + # 'zip' command. + log.info("creating '%s' and adding '%s' to it", + zip_filename, base_dir) + + def visit (z, dirname, names): + for name in names: + path = os.path.normpath(os.path.join(dirname, name)) + if os.path.isfile(path): + p = path[len(base_dir)+1:] + z.write(path, p) + log.info("adding '%s'" % p) + + if not dry_run: + z = zipfile.ZipFile(zip_filename, "w", + compression=zipfile.ZIP_DEFLATED) + + os.path.walk(base_dir, visit, z) + z.close() + + return zip_filename + +# make_zipfile () + -- cgit v1.2.1 From 6d85a801861c5834bf53cdf62be27aca9774e19b Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 21 Mar 2005 20:12:33 +0000 Subject: Add python version to egg filename. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040990 --- setuptools/command/bdist_egg.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 29c8fa5c..7c98155b 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -8,6 +8,7 @@ import os from distutils.core import Command from distutils.util import get_platform from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath +from distutils.sysconfig import get_python_version from distutils.errors import * from distutils import log @@ -74,8 +75,8 @@ class bdist_egg(Command): # And make an archive relative to the root of the # pseudo-installation tree. - archive_basename = "%s-%s" % (self.distribution.get_fullname(), - self.plat_name) + archive_basename = "%s-py%s-%s" % (self.distribution.get_fullname(), + get_python_version(),self.plat_name) # OS/2 objects to any ":" characters in a filename (such as when # a timestamp is used in a version) so change them to hyphens. -- cgit v1.2.1 From 8c07c4fa8d64fb78bafd892d9f963d8730fcba48 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 21 Mar 2005 20:41:57 +0000 Subject: Allow user-supplied metadata from EGG-INFO.in directory (directory name can be overridden with a command-line option). --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040991 --- setuptools/command/bdist_egg.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 7c98155b..d340c80a 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -16,7 +16,10 @@ class bdist_egg(Command): description = "create an \"egg\" distribution" - user_options = [('bdist-dir=', 'd', + user_options = [('egg-info=', 'e', + "directory containing EGG-INFO for the distribution " + "(default: EGG-INFO.in)"), + ('bdist-dir=', 'd', "temporary directory for creating the distribution"), ('plat-name=', 'p', "platform name to embed in generated filenames " @@ -37,6 +40,7 @@ class bdist_egg(Command): def initialize_options (self): + self.egg_info = None self.bdist_dir = None self.plat_name = None self.keep_temp = 0 @@ -49,6 +53,12 @@ class bdist_egg(Command): def finalize_options (self): + if self.egg_info is None and os.path.isdir('EGG-INFO.in'): + self.egg_info = 'EGG-INFO.in' + + elif self.egg_info: + self.ensure_dirname('egg_info') + if self.bdist_dir is None: bdist_base = self.get_finalized_command('bdist').bdist_base self.bdist_dir = os.path.join(bdist_base, 'egg') @@ -91,6 +101,12 @@ class bdist_egg(Command): egg_info = os.path.join(archive_root,'EGG-INFO') self.mkpath(egg_info) + if self.egg_info: + for filename in os.listdir(self.egg_info): + path = os.path.join(self.egg_info,filename) + if os.path.isfile(path): + self.copy_file(path,os.path.join(egg_info,filename)) + if not self.dry_run: self.distribution.metadata.write_pkg_info(egg_info) -- cgit v1.2.1 From 79a74b06ce3be48b74c3f6b929b76f522fee09cd Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 22 Mar 2005 00:15:03 +0000 Subject: Create stub loaders for C extensions, so that the actual dynamic library can be extracted from the egg. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040992 --- setuptools/command/bdist_egg.py | 54 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index d340c80a..7b8ad902 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -2,7 +2,7 @@ Build .egg distributions""" -# This module should be kept compatible with Python 2.1 +# This module should be kept compatible with Python 2.3 import os from distutils.core import Command @@ -69,7 +69,22 @@ class bdist_egg(Command): # finalize_options() + def write_stub(self, resource, pyfile): + f = open(pyfile,'w') + f.write('\n'.join([ + "def __bootstrap__():", + " global __bootstrap__, __loader__, __file__", + " import sys, pkg_resources", + " __file__ = pkg_resources.resource_filename(__name__,%r)" + % resource, + " del __bootstrap__, __loader__", + " reload(sys.modules[__name__])", + "__bootstrap__()", + "" # terminal \n + ])) + f.close() + def run (self): if not self.skip_build: @@ -80,13 +95,32 @@ class bdist_egg(Command): install.skip_build = self.skip_build install.warn_dir = 0 + ext_outputs = \ + install._mutate_outputs(self.distribution.has_ext_modules(), + 'build_ext', 'build_lib', + '') log.info("installing to %s" % self.bdist_dir) self.run_command('install_lib') + to_compile = [] + for ext_name in ext_outputs: + filename,ext = os.path.splitext(ext_name) + pyfile = os.path.join(self.bdist_dir, filename + '.py') + log.info("creating stub loader for %s" % ext_name) + if not self.dry_run: + self.write_stub(os.path.basename(ext_name), pyfile) + to_compile.append(pyfile) + + if to_compile: + install.byte_compile(to_compile) + # And make an archive relative to the root of the # pseudo-installation tree. - archive_basename = "%s-py%s-%s" % (self.distribution.get_fullname(), - get_python_version(),self.plat_name) + archive_basename = "%s-py%s" % (self.distribution.get_fullname(), + get_python_version()) + + if ext_outputs: + archive_basename += "-" + self.plat_name # OS/2 objects to any ":" characters in a filename (such as when # a timestamp is used in a version) so change them to hyphens. @@ -97,7 +131,7 @@ class bdist_egg(Command): archive_root = self.bdist_dir # Make the EGG-INFO directory - log.info("creating EGG-INFO files") + log.info("creating EGG-INFO directory") egg_info = os.path.join(archive_root,'EGG-INFO') self.mkpath(egg_info) @@ -106,10 +140,20 @@ class bdist_egg(Command): path = os.path.join(self.egg_info,filename) if os.path.isfile(path): self.copy_file(path,os.path.join(egg_info,filename)) - + + log.info("writing EGG-INFO/PKG-INFO") if not self.dry_run: self.distribution.metadata.write_pkg_info(egg_info) + if ext_outputs: + log.info("writing EGG-INFO/native_libs.txt") + if not self.dry_run: + libs_file = open( + os.path.join(egg_info,"native_libs.txt"),'wt') + libs_file.write('\n'.join(ext_outputs)) + libs_file.write('\n') + libs_file.close() + # Make the archive make_zipfile(pseudoinstall_root+'.egg', archive_root, verbose=self.verbose, -- cgit v1.2.1 From 5a50fc1e142970cb668b48058fdcd88690991cae Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 22 Mar 2005 18:55:59 +0000 Subject: Fix bootstrap loader so extracted files don't have to be on sys.path. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040993 --- setuptools/command/bdist_egg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 7b8ad902..b1913cf6 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -74,11 +74,11 @@ class bdist_egg(Command): f.write('\n'.join([ "def __bootstrap__():", " global __bootstrap__, __loader__, __file__", - " import sys, pkg_resources", + " import sys, pkg_resources, imp", " __file__ = pkg_resources.resource_filename(__name__,%r)" % resource, " del __bootstrap__, __loader__", - " reload(sys.modules[__name__])", + " imp.load_dynamic(__name__,__file__)", "__bootstrap__()", "" # terminal \n ])) -- cgit v1.2.1 From 6d3753cc8d96814a99cedd8a24a57977e5ef7766 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sat, 2 Apr 2005 02:43:21 +0000 Subject: Rough draft of version requirement parser. Make bdist_egg look for a distname.egg-info directory instead of EGG-INFO.in; this will be used later to support development of egg-distributed packages that an application under development expects to 'require()'. (Thanks to Fred Drake for pointing out this use case, and Bob Ippolito for helping me figure out how to support it, although the runtime support doesn't actually exist yet.) --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040999 --- setuptools/command/bdist_egg.py | 117 +++++++++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 38 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index b1913cf6..7a30c1cf 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -3,7 +3,6 @@ Build .egg distributions""" # This module should be kept compatible with Python 2.3 - import os from distutils.core import Command from distutils.util import get_platform @@ -11,14 +10,15 @@ from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath from distutils.sysconfig import get_python_version from distutils.errors import * from distutils import log +from pkg_resources import parse_requirements class bdist_egg(Command): description = "create an \"egg\" distribution" - user_options = [('egg-info=', 'e', - "directory containing EGG-INFO for the distribution " - "(default: EGG-INFO.in)"), + user_options = [('egg-base=', 'e', + "directory containing .egg-info directories" + "(default: top of the source tree)"), ('bdist-dir=', 'd', "temporary directory for creating the distribution"), ('plat-name=', 'p', @@ -40,6 +40,9 @@ class bdist_egg(Command): def initialize_options (self): + self.egg_name = None + self.egg_version = None + self.egg_base = None self.egg_info = None self.bdist_dir = None self.plat_name = None @@ -47,27 +50,35 @@ class bdist_egg(Command): self.dist_dir = None self.skip_build = 0 self.relative = 0 - - # initialize_options() def finalize_options (self): - - if self.egg_info is None and os.path.isdir('EGG-INFO.in'): - self.egg_info = 'EGG-INFO.in' - - elif self.egg_info: - self.ensure_dirname('egg_info') - + self.egg_name = self.distribution.get_name().replace('-','_') + self.egg_version = self.distribution.get_version().replace('-','_') + try: + list( + parse_requirements('%s==%s' % (self.egg_name,self.egg_version)) + ) + except ValueError: + raise DistutilsOptionError( + "Invalid distribution name or version syntax: %s-%s" % + (self.egg_name,self.egg_version) + ) + if self.egg_base is None: + dirs = self.distribution.package_dir + self.egg_base = (dirs or {}).get('','.') + + self.ensure_dirname('egg_base') + self.egg_info = os.path.join( + self.egg_base, self.egg_name+'.egg-info' + ) if self.bdist_dir is None: bdist_base = self.get_finalized_command('bdist').bdist_base self.bdist_dir = os.path.join(bdist_base, 'egg') - self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'), ('plat_name', 'plat_name')) - # finalize_options() def write_stub(self, resource, pyfile): f = open(pyfile,'w') @@ -84,9 +95,33 @@ class bdist_egg(Command): ])) f.close() - - def run (self): + + + + + + + + + + + + + + + + + + + + + + + + + + def run(self): if not self.skip_build: self.run_command('build') @@ -113,46 +148,50 @@ class bdist_egg(Command): if to_compile: install.byte_compile(to_compile) - + # And make an archive relative to the root of the # pseudo-installation tree. - archive_basename = "%s-py%s" % (self.distribution.get_fullname(), + archive_basename = "%s-%s-py%s" % (self.egg_name, self.egg_version, get_python_version()) if ext_outputs: archive_basename += "-" + self.plat_name # OS/2 objects to any ":" characters in a filename (such as when - # a timestamp is used in a version) so change them to hyphens. + # a timestamp is used in a version) so change them to underscores. if os.name == "os2": - archive_basename = archive_basename.replace(":", "-") + archive_basename = archive_basename.replace(":", "_") pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) archive_root = self.bdist_dir # Make the EGG-INFO directory - log.info("creating EGG-INFO directory") egg_info = os.path.join(archive_root,'EGG-INFO') self.mkpath(egg_info) + self.mkpath(self.egg_info) - if self.egg_info: - for filename in os.listdir(self.egg_info): - path = os.path.join(self.egg_info,filename) - if os.path.isfile(path): - self.copy_file(path,os.path.join(egg_info,filename)) - - log.info("writing EGG-INFO/PKG-INFO") + log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO')) if not self.dry_run: - self.distribution.metadata.write_pkg_info(egg_info) + self.distribution.metadata.write_pkg_info(self.egg_info) + native_libs = os.path.join(self.egg_info,"native_libs.txt") if ext_outputs: - log.info("writing EGG-INFO/native_libs.txt") + log.info("writing %s" % native_libs) if not self.dry_run: - libs_file = open( - os.path.join(egg_info,"native_libs.txt"),'wt') + libs_file = open(native_libs, 'wt') libs_file.write('\n'.join(ext_outputs)) libs_file.write('\n') libs_file.close() + elif os.path.isfile(native_libs): + log.info("removing %s" % native_libs) + if not self.dry_run: + os.unlink(native_libs) + + if self.egg_info: + for filename in os.listdir(self.egg_info): + path = os.path.join(self.egg_info,filename) + if os.path.isfile(path): + self.copy_file(path,os.path.join(egg_info,filename)) # Make the archive make_zipfile(pseudoinstall_root+'.egg', @@ -162,10 +201,6 @@ class bdist_egg(Command): if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) - # run() - -# class bdist_egg - def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): @@ -176,7 +211,7 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): raises DistutilsExecError. Returns the name of the output zip file. """ import zipfile - + mkpath(os.path.dirname(zip_filename), dry_run=dry_run) # If zipfile module is not available, try spawning an external @@ -203,3 +238,9 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): # make_zipfile () + + + + + + -- cgit v1.2.1 From 58217442d62882e5afef276ae9f7ad1a8bcba4de Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 3 Apr 2005 18:52:21 +0000 Subject: Added "AvailableDistributions" class that finds and indexes usable distributions; this replaces the previous "iter_distributions()" API. Added basic platform support to Distribution and AvailableDistributions so that platform-independent distros as well as local platform-compatible distros are acceptable. The actual platform scheme is currently delegated to distutils.util.get_platform(), but needs to be replaced with a better scheme of some kind, especially for OS X. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041004 --- setuptools/command/bdist_egg.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 7a30c1cf..e8309a71 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -10,7 +10,7 @@ from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath from distutils.sysconfig import get_python_version from distutils.errors import * from distutils import log -from pkg_resources import parse_requirements +from pkg_resources import parse_requirements, get_platform class bdist_egg(Command): @@ -75,9 +75,9 @@ class bdist_egg(Command): if self.bdist_dir is None: bdist_base = self.get_finalized_command('bdist').bdist_base self.bdist_dir = os.path.join(bdist_base, 'egg') - self.set_undefined_options('bdist', - ('dist_dir', 'dist_dir'), - ('plat_name', 'plat_name')) + if self.plat_name is None: + self.plat_name = get_platform() + self.set_undefined_options('bdist',('dist_dir', 'dist_dir')) def write_stub(self, resource, pyfile): -- cgit v1.2.1 From e15ee4d46a55e7dbfc823e52edf143b77ce3a978 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sat, 28 May 2005 23:05:59 +0000 Subject: Add experimental 'install_data' support to 'bdist_egg'. The most common distutils custom command hack in the field is to make 'install_data' put data in with the target packages by changing the --install-data to match --install-lib, so this should let bdist_egg work with more packages "out of the box". --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041016 --- setuptools/command/bdist_egg.py | 52 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index e8309a71..a3aeb775 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -96,35 +96,18 @@ class bdist_egg(Command): f.close() - - - - - - - - - - - - - - - - - - - - - - - - - def run(self): if not self.skip_build: self.run_command('build') + if self.distribution.data_files: + install = self.reinitialize_command('install_data') + install.install_dir = self.bdist_dir + install.force = 0 + install.root = None + log.info("installing package data to %s" % self.bdist_dir) + self.run_command('install_data') + install = self.reinitialize_command('install_lib', reinit_subcommands=1) install.install_dir = self.bdist_dir install.skip_build = self.skip_build @@ -134,9 +117,10 @@ class bdist_egg(Command): install._mutate_outputs(self.distribution.has_ext_modules(), 'build_ext', 'build_lib', '') - log.info("installing to %s" % self.bdist_dir) + log.info("installing library code to %s" % self.bdist_dir) self.run_command('install_lib') + to_compile = [] for ext_name in ext_outputs: filename,ext = os.path.splitext(ext_name) @@ -174,6 +158,10 @@ class bdist_egg(Command): if not self.dry_run: self.distribution.metadata.write_pkg_info(self.egg_info) + + + + native_libs = os.path.join(self.egg_info,"native_libs.txt") if ext_outputs: log.info("writing %s" % native_libs) @@ -193,6 +181,8 @@ class bdist_egg(Command): if os.path.isfile(path): self.copy_file(path,os.path.join(egg_info,filename)) + + # Make the archive make_zipfile(pseudoinstall_root+'.egg', archive_root, verbose=self.verbose, @@ -203,6 +193,16 @@ class bdist_egg(Command): + + + + + + + + + + def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): """Create a zip file from all the files under 'base_dir'. The output zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" -- cgit v1.2.1 From b75164050f0b537611c21e8824020e226ac6c39b Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 29 May 2005 05:19:59 +0000 Subject: Handle distributions with ' ' in their names --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041020 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index a3aeb775..25b711a4 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -53,7 +53,7 @@ class bdist_egg(Command): def finalize_options (self): - self.egg_name = self.distribution.get_name().replace('-','_') + self.egg_name = self.distribution.get_name().replace('-','_').replace(' ','_') self.egg_version = self.distribution.get_version().replace('-','_') try: list( -- cgit v1.2.1 From 3774798c60362dc9acc3680d5d203db45f5d9ac5 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 29 May 2005 22:05:39 +0000 Subject: Added options to alter eggs' version number by tagging with the subversion revision number, date, and/or a custom tag. This should make it easier for people to produce e.g. automated nightly builds of eggs. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041024 --- setuptools/command/bdist_egg.py | 96 ++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 25b711a4..8a2a8619 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -13,31 +13,31 @@ from distutils import log from pkg_resources import parse_requirements, get_platform class bdist_egg(Command): - description = "create an \"egg\" distribution" - - user_options = [('egg-base=', 'e', - "directory containing .egg-info directories" - "(default: top of the source tree)"), - ('bdist-dir=', 'd', - "temporary directory for creating the distribution"), - ('plat-name=', 'p', + user_options = [ + ('egg-base=', 'e', "directory containing .egg-info directories" + " (default: top of the source tree)"), + ('bdist-dir=', 'd', + "temporary directory for creating the distribution"), + ('tag-svn-revision', None, + "Add subversion revision ID to version number"), + ('tag-date', None, "Add date stamp (e.g. 20050528) to version number"), + ('tag-build=', None, "Specify explicit tag to add to version number"), + ('plat-name=', 'p', "platform name to embed in generated filenames " "(default: %s)" % get_platform()), - ('keep-temp', 'k', + ('keep-temp', 'k', "keep the pseudo-installation tree around after " + "creating the distribution archive"), - ('dist-dir=', 'd', + ('dist-dir=', 'd', "directory to put final built distributions in"), - ('skip-build', None, + ('skip-build', None, "skip rebuilding everything (for testing/debugging)"), - ('relative', None, - "build the archive using relative paths" - "(default: false)"), - ] - - boolean_options = ['keep-temp', 'skip-build', 'relative'] + ] + boolean_options = [ + 'keep-temp', 'skip-build', 'relative','tag-date','tag-svn-revision' + ] def initialize_options (self): self.egg_name = None @@ -49,12 +49,13 @@ class bdist_egg(Command): self.keep_temp = 0 self.dist_dir = None self.skip_build = 0 - self.relative = 0 - + self.tag_build = None + self.tag_svn_revision = 0 + self.tag_date = 0 def finalize_options (self): - self.egg_name = self.distribution.get_name().replace('-','_').replace(' ','_') - self.egg_version = self.distribution.get_version().replace('-','_') + self.egg_name = self.distribution.get_name().replace(' ','-') + self.egg_version = self.tagged_version() try: list( parse_requirements('%s==%s' % (self.egg_name,self.egg_version)) @@ -79,7 +80,6 @@ class bdist_egg(Command): self.plat_name = get_platform() self.set_undefined_options('bdist',('dist_dir', 'dist_dir')) - def write_stub(self, resource, pyfile): f = open(pyfile,'w') f.write('\n'.join([ @@ -135,9 +135,8 @@ class bdist_egg(Command): # And make an archive relative to the root of the # pseudo-installation tree. - archive_basename = "%s-%s-py%s" % (self.egg_name, self.egg_version, - get_python_version()) - + archive_basename = "%s-%s-py%s" % ( self.egg_name.replace('-','_'), + self.egg_version.replace('-','_'), get_python_version()) if ext_outputs: archive_basename += "-" + self.plat_name @@ -156,11 +155,12 @@ class bdist_egg(Command): log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO')) if not self.dry_run: - self.distribution.metadata.write_pkg_info(self.egg_info) - - - - + metadata = self.distribution.metadata + metadata.version, oldver = self.egg_version, metadata.version + try: + metadata.write_pkg_info(self.egg_info) + finally: + metadata.version = oldver native_libs = os.path.join(self.egg_info,"native_libs.txt") if ext_outputs: @@ -181,8 +181,6 @@ class bdist_egg(Command): if os.path.isfile(path): self.copy_file(path,os.path.join(egg_info,filename)) - - # Make the archive make_zipfile(pseudoinstall_root+'.egg', archive_root, verbose=self.verbose, @@ -191,16 +189,28 @@ class bdist_egg(Command): if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) + def tagged_version(self): + version = self.distribution.get_version() + if self.tag_build: + version+='-'+self.tag_build + if self.tag_svn_revision and os.path.exists('.svn'): + version += '-%s' % self.get_svn_revision() + if self.tag_date: + import time + version += time.strftime("-%Y%m%d") + return version - - - - - - + def get_svn_revision(self): + stdin, stdout = os.popen4("svn info"); stdin.close() + result = stdout.read(); stdout.close() + import re + match = re.search(r'Last Changed Rev: (\d+)', result) + if not match: + raise RuntimeError("svn info error: %s" % result.strip()) + return match.group(1) def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): @@ -211,7 +221,6 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): raises DistutilsExecError. Returns the name of the output zip file. """ import zipfile - mkpath(os.path.dirname(zip_filename), dry_run=dry_run) # If zipfile module is not available, try spawning an external @@ -230,17 +239,8 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): if not dry_run: z = zipfile.ZipFile(zip_filename, "w", compression=zipfile.ZIP_DEFLATED) - os.path.walk(base_dir, visit, z) z.close() return zip_filename -# make_zipfile () - - - - - - - -- cgit v1.2.1 From c3e492cc9aa7c5cb92a9fb0fa8a8188d8a477a5b Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 30 May 2005 06:46:01 +0000 Subject: Reorganize bdist_egg's handling of 'install_data' to better deal with the various kludges legacy packages are using to install data in their package directories. Some use absolute paths in 'distribution.data_files', while others create various subclasses of 'install_data', each with their own way of finding out what directory to use! So 'bdist_egg' now does all its 'install_lib' activity before 'install_data', and pokes the desired build directory into a wide variety of places, so that all of the known kludges so far will work correctly. It also checks for absolute paths in 'data_files' (carefully working around other packages' 'data_files' kludges!) and converts them back to relative ones, if they are subpaths of site-packages. Clearly, we need to get the word out about 'package_files' in Python 2.4 and above, and suggest using 'setuptools' for Python 2.3. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041028 --- setuptools/command/bdist_egg.py | 61 ++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 10 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 8a2a8619..39042fb8 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -7,7 +7,7 @@ import os from distutils.core import Command from distutils.util import get_platform from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath -from distutils.sysconfig import get_python_version +from distutils.sysconfig import get_python_version, get_python_lib from distutils.errors import * from distutils import log from pkg_resources import parse_requirements, get_platform @@ -95,19 +95,39 @@ class bdist_egg(Command): ])) f.close() + def do_install_data(self): + self.get_finalized_command('install').install_lib = self.bdist_dir + site_packages = os.path.normcase(os.path.realpath(get_python_lib())) + old, self.distribution.data_files = self.distribution.data_files,[] + for item in old: + if isinstance(item,tuple) and len(item)==2: + if os.path.isabs(item[0]): + realpath = os.path.realpath(item[0]) + normalized = os.path.normcase(realpath) + if normalized==site_packages or normalized.startswith( + site_packages+os.sep + ): + item = realpath[len(site_packages)+1:], item[1] + # XXX else: raise ??? + self.distribution.data_files.append(item) + try: + install = self.reinitialize_command('install_data') + # kludge for setups that use a 3-tuple inst_data + install.install_dir = install.install_base = \ + install.install_data = install.install_lib = self.bdist_dir + install.force = 0; install.root = None + log.info("installing package data to %s" % self.bdist_dir) + self.run_command('install_data') + finally: + self.distribution.data_files = old def run(self): + if not self.skip_build: self.run_command('build') - if self.distribution.data_files: - install = self.reinitialize_command('install_data') - install.install_dir = self.bdist_dir - install.force = 0 - install.root = None - log.info("installing package data to %s" % self.bdist_dir) - self.run_command('install_data') - + # We run install_lib before install_data, because some data hacks + # pull their data path from the install_lib command. install = self.reinitialize_command('install_lib', reinit_subcommands=1) install.install_dir = self.bdist_dir install.skip_build = self.skip_build @@ -120,7 +140,6 @@ class bdist_egg(Command): log.info("installing library code to %s" % self.bdist_dir) self.run_command('install_lib') - to_compile = [] for ext_name in ext_outputs: filename,ext = os.path.splitext(ext_name) @@ -133,6 +152,9 @@ class bdist_egg(Command): if to_compile: install.byte_compile(to_compile) + if self.distribution.data_files: + self.do_install_data() + # And make an archive relative to the root of the # pseudo-installation tree. archive_basename = "%s-%s-py%s" % ( self.egg_name.replace('-','_'), @@ -213,6 +235,15 @@ class bdist_egg(Command): return match.group(1) + + + + + + + + + def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): """Create a zip file from all the files under 'base_dir'. The output zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" @@ -244,3 +275,13 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): return zip_filename + + + + + + + + + + -- cgit v1.2.1 From a0453161619be7baa6b7d7e4b223f431ac42340d Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 30 May 2005 23:22:10 +0000 Subject: Ensure that the distribution name written to PKG-INFO is the same as the name you'll use in 'require()' operations for that distribution. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041030 --- setuptools/command/bdist_egg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 39042fb8..d3139580 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -174,15 +174,15 @@ class bdist_egg(Command): egg_info = os.path.join(archive_root,'EGG-INFO') self.mkpath(egg_info) self.mkpath(self.egg_info) - log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO')) if not self.dry_run: metadata = self.distribution.metadata metadata.version, oldver = self.egg_version, metadata.version + metadata.name, oldname = self.egg_name, metadata.name try: metadata.write_pkg_info(self.egg_info) finally: - metadata.version = oldver + metadata.name, metadata.version = oldname, oldver native_libs = os.path.join(self.egg_info,"native_libs.txt") if ext_outputs: -- cgit v1.2.1 From 0c9e886999bb42cf825054778b1664e41f8164b4 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 5 Jun 2005 18:59:37 +0000 Subject: Add "safe_name" and "safe_version" functions to allow sanitizing of distribution names and versions in arbitrary packages that might be built using EasyInstall. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041040 --- setuptools/command/bdist_egg.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index d3139580..8692fd39 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -10,7 +10,7 @@ from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath from distutils.sysconfig import get_python_version, get_python_lib from distutils.errors import * from distutils import log -from pkg_resources import parse_requirements, get_platform +from pkg_resources import parse_requirements, get_platform, safe_name, safe_version class bdist_egg(Command): description = "create an \"egg\" distribution" @@ -54,7 +54,7 @@ class bdist_egg(Command): self.tag_date = 0 def finalize_options (self): - self.egg_name = self.distribution.get_name().replace(' ','-') + self.egg_name = safe_name(self.distribution.get_name()) self.egg_version = self.tagged_version() try: list( @@ -122,7 +122,6 @@ class bdist_egg(Command): self.distribution.data_files = old def run(self): - if not self.skip_build: self.run_command('build') @@ -161,6 +160,7 @@ class bdist_egg(Command): self.egg_version.replace('-','_'), get_python_version()) if ext_outputs: archive_basename += "-" + self.plat_name + ext_outputs = [out.replace(os.sep,'/') for out in ext_outputs] # OS/2 objects to any ":" characters in a filename (such as when # a timestamp is used in a version) so change them to underscores. @@ -223,7 +223,7 @@ class bdist_egg(Command): import time version += time.strftime("-%Y%m%d") - return version + return safe_version(version) def get_svn_revision(self): stdin, stdout = os.popen4("svn info"); stdin.close() -- cgit v1.2.1 From 5bb11a1a2f926e565193c27efa9de861734f478d Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 7 Jun 2005 04:41:51 +0000 Subject: Package scripts under EGG-INFO/scripts. Refactor subcommand invocations for less duplication and greater clarity. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041044 --- setuptools/command/bdist_egg.py | 70 ++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 8692fd39..ee6f2e80 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -96,9 +96,12 @@ class bdist_egg(Command): f.close() def do_install_data(self): + # Hack for packages that install data to install's --install-lib self.get_finalized_command('install').install_lib = self.bdist_dir + site_packages = os.path.normcase(os.path.realpath(get_python_lib())) old, self.distribution.data_files = self.distribution.data_files,[] + for item in old: if isinstance(item,tuple) and len(item)==2: if os.path.isabs(item[0]): @@ -110,36 +113,27 @@ class bdist_egg(Command): item = realpath[len(site_packages)+1:], item[1] # XXX else: raise ??? self.distribution.data_files.append(item) + try: - install = self.reinitialize_command('install_data') - # kludge for setups that use a 3-tuple inst_data - install.install_dir = install.install_base = \ - install.install_data = install.install_lib = self.bdist_dir - install.force = 0; install.root = None log.info("installing package data to %s" % self.bdist_dir) - self.run_command('install_data') + self.call_command('install_data', force=0, root=None) finally: self.distribution.data_files = old - def run(self): - if not self.skip_build: - self.run_command('build') + def run(self): # We run install_lib before install_data, because some data hacks # pull their data path from the install_lib command. - install = self.reinitialize_command('install_lib', reinit_subcommands=1) - install.install_dir = self.bdist_dir - install.skip_build = self.skip_build - install.warn_dir = 0 - - ext_outputs = \ - install._mutate_outputs(self.distribution.has_ext_modules(), - 'build_ext', 'build_lib', - '') + log.info("installing library code to %s" % self.bdist_dir) - self.run_command('install_lib') + cmd = self.call_command('install_lib', warn_dir=0) + + ext_outputs = cmd._mutate_outputs( + self.distribution.has_ext_modules(), 'build_ext', 'build_lib', '' + ) to_compile = [] + for ext_name in ext_outputs: filename,ext = os.path.splitext(ext_name) pyfile = os.path.join(self.bdist_dir, filename + '.py') @@ -149,15 +143,21 @@ class bdist_egg(Command): to_compile.append(pyfile) if to_compile: - install.byte_compile(to_compile) + cmd.byte_compile(to_compile) if self.distribution.data_files: self.do_install_data() + if self.distribution.scripts: + script_dir = os.path.join(self.bdist_dir,'EGG-INFO','scripts') + log.info("installing scripts to %s" % script_dir) + self.call_command('install_scripts', install_dir=script_dir) + # And make an archive relative to the root of the # pseudo-installation tree. archive_basename = "%s-%s-py%s" % ( self.egg_name.replace('-','_'), self.egg_version.replace('-','_'), get_python_version()) + if ext_outputs: archive_basename += "-" + self.plat_name ext_outputs = [out.replace(os.sep,'/') for out in ext_outputs] @@ -207,7 +207,6 @@ class bdist_egg(Command): make_zipfile(pseudoinstall_root+'.egg', archive_root, verbose=self.verbose, dry_run=self.dry_run) - if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) @@ -234,14 +233,23 @@ class bdist_egg(Command): raise RuntimeError("svn info error: %s" % result.strip()) return match.group(1) + def call_command(self,cmdname,**kw): + cmd = self.reinitialize_command(cmdname) + for dirname in INSTALL_DIRECTORY_ATTRS: + if dirname in cmd.__dict__: # don't overwrite methods! + setattr(cmd,dirname,self.bdist_dir) + cmd.skip_build = self.skip_build + for k,v in kw.items(): + setattr(cmd,k,v) + self.run_command(cmdname) + return cmd +# Attribute names of options for commands that might need to be convinced to +# install to the egg build directory - - - - - - +INSTALL_DIRECTORY_ATTRS = [ + 'install_lib', 'install_dir', 'install_data', 'install_base' +] def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): @@ -277,11 +285,3 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): - - - - - - - - -- cgit v1.2.1 From 18b9ae1e5df8c0c141970c23c9aa0589928655c6 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 12 Jun 2005 15:49:54 +0000 Subject: Restructure easy_install as a distutils "Command" object, so that it can access the distutils configuration and logging infrastructure, and can "inherit" options from a distutils setup script that wants to use it to install its own dependencies. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041052 --- setuptools/command/bdist_egg.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index ee6f2e80..18001eff 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -4,7 +4,7 @@ Build .egg distributions""" # This module should be kept compatible with Python 2.3 import os -from distutils.core import Command +from setuptools import Command from distutils.util import get_platform from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath from distutils.sysconfig import get_python_version, get_python_lib @@ -234,16 +234,16 @@ class bdist_egg(Command): return match.group(1) def call_command(self,cmdname,**kw): - cmd = self.reinitialize_command(cmdname) + """Invoke reinitialized command `cmdname` with keyword args""" for dirname in INSTALL_DIRECTORY_ATTRS: - if dirname in cmd.__dict__: # don't overwrite methods! - setattr(cmd,dirname,self.bdist_dir) - cmd.skip_build = self.skip_build - for k,v in kw.items(): - setattr(cmd,k,v) + kw.setdefault(dirname,self.bdist_dir) + kw.setdefault('skip_build',self.skip_build) + + cmd = self.reinitialize_command(cmdname, **kw) self.run_command(cmdname) return cmd + # Attribute names of options for commands that might need to be convinced to # install to the egg build directory -- cgit v1.2.1 From 26a5ebfbad61a20d1011dd14585f86bde34211bb Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 12 Jun 2005 21:47:34 +0000 Subject: Add 'ez_setup' bootstrap installer. Prep for 0.4a2 release. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041054 --- setuptools/command/bdist_egg.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 18001eff..cabc3350 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -10,7 +10,8 @@ from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath from distutils.sysconfig import get_python_version, get_python_lib from distutils.errors import * from distutils import log -from pkg_resources import parse_requirements, get_platform, safe_name, safe_version +from pkg_resources import parse_requirements, get_platform, safe_name, \ + safe_version, Distribution class bdist_egg(Command): description = "create an \"egg\" distribution" @@ -34,7 +35,6 @@ class bdist_egg(Command): ('skip-build', None, "skip rebuilding everything (for testing/debugging)"), ] - boolean_options = [ 'keep-temp', 'skip-build', 'relative','tag-date','tag-svn-revision' ] @@ -133,14 +133,14 @@ class bdist_egg(Command): ) to_compile = [] - - for ext_name in ext_outputs: + for (p,ext_name) in enumerate(ext_outputs): filename,ext = os.path.splitext(ext_name) pyfile = os.path.join(self.bdist_dir, filename + '.py') log.info("creating stub loader for %s" % ext_name) if not self.dry_run: self.write_stub(os.path.basename(ext_name), pyfile) to_compile.append(pyfile) + ext_outputs[p] = ext_name.replace(os.sep,'/') if to_compile: cmd.byte_compile(to_compile) @@ -155,18 +155,10 @@ class bdist_egg(Command): # And make an archive relative to the root of the # pseudo-installation tree. - archive_basename = "%s-%s-py%s" % ( self.egg_name.replace('-','_'), - self.egg_version.replace('-','_'), get_python_version()) - - if ext_outputs: - archive_basename += "-" + self.plat_name - ext_outputs = [out.replace(os.sep,'/') for out in ext_outputs] - - # OS/2 objects to any ":" characters in a filename (such as when - # a timestamp is used in a version) so change them to underscores. - if os.name == "os2": - archive_basename = archive_basename.replace(":", "_") - + archive_basename = Distribution( + None, None, self.egg_name, self.egg_version, get_python_version(), + ext_outputs and self.plat_name + ).egg_name() pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) archive_root = self.bdist_dir @@ -174,6 +166,7 @@ class bdist_egg(Command): egg_info = os.path.join(archive_root,'EGG-INFO') self.mkpath(egg_info) self.mkpath(self.egg_info) + log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO')) if not self.dry_run: metadata = self.distribution.metadata @@ -244,6 +237,13 @@ class bdist_egg(Command): return cmd + + + + + + + # Attribute names of options for commands that might need to be convinced to # install to the egg build directory -- cgit v1.2.1 From 8a1ba5d6cdaa0318c4f3fc5de1ae4d092d58003e Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 14 Jun 2005 15:30:32 +0000 Subject: Add support for quiet/verbose/dry-run/optimize flags. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041064 --- setuptools/command/bdist_egg.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index cabc3350..98ebda79 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -190,7 +190,7 @@ class bdist_egg(Command): if not self.dry_run: os.unlink(native_libs) - if self.egg_info: + if self.egg_info and os.path.exists(self.egg_info): for filename in os.listdir(self.egg_info): path = os.path.join(self.egg_info,filename) if os.path.isfile(path): @@ -231,7 +231,7 @@ class bdist_egg(Command): for dirname in INSTALL_DIRECTORY_ATTRS: kw.setdefault(dirname,self.bdist_dir) kw.setdefault('skip_build',self.skip_build) - + kw.setdefault('dry_run', self.dry_run) cmd = self.reinitialize_command(cmdname, **kw) self.run_command(cmdname) return cmd @@ -262,24 +262,24 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): import zipfile mkpath(os.path.dirname(zip_filename), dry_run=dry_run) - # If zipfile module is not available, try spawning an external - # 'zip' command. - log.info("creating '%s' and adding '%s' to it", - zip_filename, base_dir) + log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir) def visit (z, dirname, names): for name in names: path = os.path.normpath(os.path.join(dirname, name)) if os.path.isfile(path): p = path[len(base_dir)+1:] - z.write(path, p) - log.info("adding '%s'" % p) + if not dry_run: + z.write(path, p) + log.debug("adding '%s'" % p) if not dry_run: z = zipfile.ZipFile(zip_filename, "w", compression=zipfile.ZIP_DEFLATED) os.path.walk(base_dir, visit, z) z.close() + else: + os.path.walk(base_dir, visit, None) return zip_filename -- cgit v1.2.1 From c386a7e6a79c74308eb97d1cf3ac23b6c0b085d8 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 15 Jun 2005 02:12:49 +0000 Subject: Make write_stub() a function, so easy_install can use it too. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041067 --- setuptools/command/bdist_egg.py | 71 ++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 15 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 98ebda79..cd3d3ecb 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -13,6 +13,32 @@ from distutils import log from pkg_resources import parse_requirements, get_platform, safe_name, \ safe_version, Distribution + +def write_stub(resource, pyfile): + f = open(pyfile,'w') + f.write('\n'.join([ + "def __bootstrap__():", + " global __bootstrap__, __loader__, __file__", + " import sys, pkg_resources, imp", + " __file__ = pkg_resources.resource_filename(__name__,%r)" + % resource, + " del __bootstrap__, __loader__", + " imp.load_dynamic(__name__,__file__)", + "__bootstrap__()", + "" # terminal \n + ])) + f.close() + + + + + + + + + + + class bdist_egg(Command): description = "create an \"egg\" distribution" user_options = [ @@ -53,6 +79,7 @@ class bdist_egg(Command): self.tag_svn_revision = 0 self.tag_date = 0 + def finalize_options (self): self.egg_name = safe_name(self.distribution.get_name()) self.egg_version = self.tagged_version() @@ -80,20 +107,19 @@ class bdist_egg(Command): self.plat_name = get_platform() self.set_undefined_options('bdist',('dist_dir', 'dist_dir')) - def write_stub(self, resource, pyfile): - f = open(pyfile,'w') - f.write('\n'.join([ - "def __bootstrap__():", - " global __bootstrap__, __loader__, __file__", - " import sys, pkg_resources, imp", - " __file__ = pkg_resources.resource_filename(__name__,%r)" - % resource, - " del __bootstrap__, __loader__", - " imp.load_dynamic(__name__,__file__)", - "__bootstrap__()", - "" # terminal \n - ])) - f.close() + + + + + + + + + + + + + def do_install_data(self): # Hack for packages that install data to install's --install-lib @@ -121,6 +147,21 @@ class bdist_egg(Command): self.distribution.data_files = old + + + + + + + + + + + + + + + def run(self): # We run install_lib before install_data, because some data hacks # pull their data path from the install_lib command. @@ -138,7 +179,7 @@ class bdist_egg(Command): pyfile = os.path.join(self.bdist_dir, filename + '.py') log.info("creating stub loader for %s" % ext_name) if not self.dry_run: - self.write_stub(os.path.basename(ext_name), pyfile) + write_stub(os.path.basename(ext_name), pyfile) to_compile.append(pyfile) ext_outputs[p] = ext_name.replace(os.sep,'/') -- cgit v1.2.1 From 643acd6ad1eb4aeebac199c91af001181c7786f3 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 27 Jun 2005 00:31:03 +0000 Subject: EasyInstall/setuptools 0.5a4: significant new features, including automatic installation of dependencies, the ability to specify dependencies in a setup script, and several new options to control EasyInstall's behavior. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041073 --- setuptools/command/bdist_egg.py | 92 ++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index cd3d3ecb..8abcb855 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -11,7 +11,7 @@ from distutils.sysconfig import get_python_version, get_python_lib from distutils.errors import * from distutils import log from pkg_resources import parse_requirements, get_platform, safe_name, \ - safe_version, Distribution + safe_version, Distribution, yield_lines def write_stub(resource, pyfile): @@ -78,7 +78,7 @@ class bdist_egg(Command): self.tag_build = None self.tag_svn_revision = 0 self.tag_date = 0 - + self.egg_output = None def finalize_options (self): self.egg_name = safe_name(self.distribution.get_name()) @@ -105,19 +105,19 @@ class bdist_egg(Command): self.bdist_dir = os.path.join(bdist_base, 'egg') if self.plat_name is None: self.plat_name = get_platform() - self.set_undefined_options('bdist',('dist_dir', 'dist_dir')) - - - - - - - - + self.set_undefined_options('bdist',('dist_dir', 'dist_dir')) + if self.egg_output is None: + # Compute filename of the output egg + basename = Distribution( + None, None, self.egg_name, self.egg_version, + get_python_version(), + self.distribution.has_ext_modules() and self.plat_name + ).egg_name() + self.egg_output = os.path.join(self.dist_dir, basename+'.egg') @@ -146,22 +146,22 @@ class bdist_egg(Command): finally: self.distribution.data_files = old + def get_outputs(self): + return [self.egg_output] - - - - - - - - - - - - - - - + def write_requirements(self): + dist = self.distribution + if not getattr(dist,'install_requires',None) and \ + not getattr(dist,'extras_require',None): return + requires = os.path.join(self.egg_info,"requires.txt") + log.info("writing %s", requires) + if not self.dry_run: + f = open(requires, 'wt') + f.write('\n'.join(yield_lines(dist.install_requires))) + for extra,reqs in dist.extras_require.items(): + f.write('\n\n[%s]\n%s' % (extra, '\n'.join(yield_lines(reqs)))) + f.close() + def run(self): # We run install_lib before install_data, because some data hacks # pull their data path from the install_lib command. @@ -189,24 +189,19 @@ class bdist_egg(Command): if self.distribution.data_files: self.do_install_data() + # Make the EGG-INFO directory + archive_root = self.bdist_dir + egg_info = os.path.join(archive_root,'EGG-INFO') + self.mkpath(egg_info) + self.mkpath(self.egg_info) + if self.distribution.scripts: - script_dir = os.path.join(self.bdist_dir,'EGG-INFO','scripts') + script_dir = os.path.join(egg_info, 'scripts') log.info("installing scripts to %s" % script_dir) self.call_command('install_scripts', install_dir=script_dir) - # And make an archive relative to the root of the - # pseudo-installation tree. - archive_basename = Distribution( - None, None, self.egg_name, self.egg_version, get_python_version(), - ext_outputs and self.plat_name - ).egg_name() - pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) - archive_root = self.bdist_dir + self.write_requirements() - # Make the EGG-INFO directory - egg_info = os.path.join(archive_root,'EGG-INFO') - self.mkpath(egg_info) - self.mkpath(self.egg_info) log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO')) if not self.dry_run: @@ -231,15 +226,20 @@ class bdist_egg(Command): if not self.dry_run: os.unlink(native_libs) - if self.egg_info and os.path.exists(self.egg_info): - for filename in os.listdir(self.egg_info): - path = os.path.join(self.egg_info,filename) - if os.path.isfile(path): - self.copy_file(path,os.path.join(egg_info,filename)) + for filename in os.listdir(self.egg_info): + path = os.path.join(self.egg_info,filename) + if os.path.isfile(path): + self.copy_file(path,os.path.join(egg_info,filename)) + if os.path.exists(os.path.join(self.egg_info,'depends.txt')): + log.warn( + "WARNING: 'depends.txt' will not be used by setuptools 0.6!" + ) + log.warn( + "Use the install_requires/extras_require setup() args instead." + ) # Make the archive - make_zipfile(pseudoinstall_root+'.egg', - archive_root, verbose=self.verbose, + make_zipfile(self.egg_output, archive_root, verbose=self.verbose, dry_run=self.dry_run) if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) -- cgit v1.2.1 From 52928dfe183fcd7e7e5684914522b1da47938ae1 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 4 Jul 2005 18:45:41 +0000 Subject: Fix a problem using bdist_egg with non-setuptools distributions. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041076 --- setuptools/command/bdist_egg.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 8abcb855..b21ef741 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -201,9 +201,8 @@ class bdist_egg(Command): self.call_command('install_scripts', install_dir=script_dir) self.write_requirements() - - log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO')) + if not self.dry_run: metadata = self.distribution.metadata metadata.version, oldver = self.egg_version, metadata.version @@ -233,9 +232,7 @@ class bdist_egg(Command): if os.path.exists(os.path.join(self.egg_info,'depends.txt')): log.warn( - "WARNING: 'depends.txt' will not be used by setuptools 0.6!" - ) - log.warn( + "WARNING: 'depends.txt' will not be used by setuptools 0.6!\n" "Use the install_requires/extras_require setup() args instead." ) # Make the archive @@ -244,6 +241,9 @@ class bdist_egg(Command): if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) + getattr(self.distribution,'dist_files',[]).append( + ('bdist_egg',get_python_version(),self.egg_output)) + def tagged_version(self): version = self.distribution.get_version() if self.tag_build: -- cgit v1.2.1 From 4a63bc6f16d3a4616edae1403f3c7bd67bdfa2f3 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 6 Jul 2005 01:37:41 +0000 Subject: Added ``egg_info`` command to ``setuptools``-based packages. This command just creates or updates the "projectname.egg-info" directory, without building an egg. It's used by the ``bdist_egg`` command now, and will be used by the ``test`` and ``develop`` commands later on. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041077 --- setuptools/command/bdist_egg.py | 155 +++++++++++++++------------------------- 1 file changed, 57 insertions(+), 98 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index b21ef741..6cc818d3 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -5,13 +5,10 @@ Build .egg distributions""" # This module should be kept compatible with Python 2.3 import os from setuptools import Command -from distutils.util import get_platform -from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath +from distutils.dir_util import remove_tree, mkpath from distutils.sysconfig import get_python_version, get_python_lib -from distutils.errors import * from distutils import log -from pkg_resources import parse_requirements, get_platform, safe_name, \ - safe_version, Distribution, yield_lines +from pkg_resources import get_platform, Distribution def write_stub(resource, pyfile): @@ -39,17 +36,16 @@ def write_stub(resource, pyfile): + + + class bdist_egg(Command): + description = "create an \"egg\" distribution" + user_options = [ - ('egg-base=', 'e', "directory containing .egg-info directories" - " (default: top of the source tree)"), ('bdist-dir=', 'd', "temporary directory for creating the distribution"), - ('tag-svn-revision', None, - "Add subversion revision ID to version number"), - ('tag-date', None, "Add date stamp (e.g. 20050528) to version number"), - ('tag-build=', None, "Specify explicit tag to add to version number"), ('plat-name=', 'p', "platform name to embed in generated filenames " "(default: %s)" % get_platform()), @@ -61,48 +57,47 @@ class bdist_egg(Command): ('skip-build', None, "skip rebuilding everything (for testing/debugging)"), ] + boolean_options = [ 'keep-temp', 'skip-build', 'relative','tag-date','tag-svn-revision' ] + + + + + + + + + + + + + + + + + + def initialize_options (self): - self.egg_name = None - self.egg_version = None - self.egg_base = None - self.egg_info = None self.bdist_dir = None self.plat_name = None self.keep_temp = 0 self.dist_dir = None self.skip_build = 0 - self.tag_build = None - self.tag_svn_revision = 0 - self.tag_date = 0 self.egg_output = None - def finalize_options (self): - self.egg_name = safe_name(self.distribution.get_name()) - self.egg_version = self.tagged_version() - try: - list( - parse_requirements('%s==%s' % (self.egg_name,self.egg_version)) - ) - except ValueError: - raise DistutilsOptionError( - "Invalid distribution name or version syntax: %s-%s" % - (self.egg_name,self.egg_version) - ) - if self.egg_base is None: - dirs = self.distribution.package_dir - self.egg_base = (dirs or {}).get('','.') - self.ensure_dirname('egg_base') - self.egg_info = os.path.join( - self.egg_base, self.egg_name+'.egg-info' - ) + + def finalize_options(self): + ei_cmd = self.get_finalized_command("egg_info") + self.egg_info = ei_cmd.egg_info + if self.bdist_dir is None: bdist_base = self.get_finalized_command('bdist').bdist_base self.bdist_dir = os.path.join(bdist_base, 'egg') + if self.plat_name is None: self.plat_name = get_platform() @@ -112,7 +107,7 @@ class bdist_egg(Command): # Compute filename of the output egg basename = Distribution( - None, None, self.egg_name, self.egg_version, + None, None, ei_cmd.egg_name, ei_cmd.egg_version, get_python_version(), self.distribution.has_ext_modules() and self.plat_name ).egg_name() @@ -121,6 +116,11 @@ class bdist_egg(Command): + + + + + def do_install_data(self): # Hack for packages that install data to install's --install-lib self.get_finalized_command('install').install_lib = self.bdist_dir @@ -146,26 +146,29 @@ class bdist_egg(Command): finally: self.distribution.data_files = old + def get_outputs(self): return [self.egg_output] - def write_requirements(self): - dist = self.distribution - if not getattr(dist,'install_requires',None) and \ - not getattr(dist,'extras_require',None): return - requires = os.path.join(self.egg_info,"requires.txt") - log.info("writing %s", requires) - if not self.dry_run: - f = open(requires, 'wt') - f.write('\n'.join(yield_lines(dist.install_requires))) - for extra,reqs in dist.extras_require.items(): - f.write('\n\n[%s]\n%s' % (extra, '\n'.join(yield_lines(reqs)))) - f.close() - + + def call_command(self,cmdname,**kw): + """Invoke reinitialized command `cmdname` with keyword args""" + for dirname in INSTALL_DIRECTORY_ATTRS: + kw.setdefault(dirname,self.bdist_dir) + kw.setdefault('skip_build',self.skip_build) + kw.setdefault('dry_run', self.dry_run) + cmd = self.reinitialize_command(cmdname, **kw) + self.run_command(cmdname) + return cmd + + def run(self): + # Generate metadata first + self.run_command("egg_info") + # We run install_lib before install_data, because some data hacks # pull their data path from the install_lib command. - + log.info("installing library code to %s" % self.bdist_dir) cmd = self.call_command('install_lib', warn_dir=0) @@ -193,24 +196,12 @@ class bdist_egg(Command): archive_root = self.bdist_dir egg_info = os.path.join(archive_root,'EGG-INFO') self.mkpath(egg_info) - self.mkpath(self.egg_info) if self.distribution.scripts: script_dir = os.path.join(egg_info, 'scripts') log.info("installing scripts to %s" % script_dir) self.call_command('install_scripts', install_dir=script_dir) - self.write_requirements() - log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO')) - - if not self.dry_run: - metadata = self.distribution.metadata - metadata.version, oldver = self.egg_version, metadata.version - metadata.name, oldname = self.egg_name, metadata.name - try: - metadata.write_pkg_info(self.egg_info) - finally: - metadata.name, metadata.version = oldname, oldver native_libs = os.path.join(self.egg_info,"native_libs.txt") if ext_outputs: @@ -235,49 +226,17 @@ class bdist_egg(Command): "WARNING: 'depends.txt' will not be used by setuptools 0.6!\n" "Use the install_requires/extras_require setup() args instead." ) + # Make the archive make_zipfile(self.egg_output, archive_root, verbose=self.verbose, dry_run=self.dry_run) if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) + # Add to 'Distribution.dist_files' so that the "upload" command works getattr(self.distribution,'dist_files',[]).append( ('bdist_egg',get_python_version(),self.egg_output)) - def tagged_version(self): - version = self.distribution.get_version() - if self.tag_build: - version+='-'+self.tag_build - - if self.tag_svn_revision and os.path.exists('.svn'): - version += '-%s' % self.get_svn_revision() - - if self.tag_date: - import time - version += time.strftime("-%Y%m%d") - - return safe_version(version) - - def get_svn_revision(self): - stdin, stdout = os.popen4("svn info"); stdin.close() - result = stdout.read(); stdout.close() - import re - match = re.search(r'Last Changed Rev: (\d+)', result) - if not match: - raise RuntimeError("svn info error: %s" % result.strip()) - return match.group(1) - - def call_command(self,cmdname,**kw): - """Invoke reinitialized command `cmdname` with keyword args""" - for dirname in INSTALL_DIRECTORY_ATTRS: - kw.setdefault(dirname,self.bdist_dir) - kw.setdefault('skip_build',self.skip_build) - kw.setdefault('dry_run', self.dry_run) - cmd = self.reinitialize_command(cmdname, **kw) - self.run_command(cmdname) - return cmd - - -- cgit v1.2.1 From db0f52341dfc8237e655037e5ba632029da44887 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sat, 9 Jul 2005 04:25:49 +0000 Subject: Fix typos in option specs for bdist_egg. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041103 --- setuptools/command/bdist_egg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 6cc818d3..74a2cd26 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -52,14 +52,14 @@ class bdist_egg(Command): ('keep-temp', 'k', "keep the pseudo-installation tree around after " + "creating the distribution archive"), - ('dist-dir=', 'd', + ('dist-dir=', 'b', "directory to put final built distributions in"), ('skip-build', None, "skip rebuilding everything (for testing/debugging)"), ] boolean_options = [ - 'keep-temp', 'skip-build', 'relative','tag-date','tag-svn-revision' + 'keep-temp', 'skip-build', ] -- cgit v1.2.1 From 451377d0e877fc610d1bdf8181ba70a90e4c14cc Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 10 Jul 2005 04:49:31 +0000 Subject: Detect and handle conflicts with "unmanaged" packages when installing packages managed by EasyInstall. Also, add an option to exclude source files from .egg distributions. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041109 --- setuptools/command/bdist_egg.py | 49 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 74a2cd26..552bd7e8 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -49,6 +49,8 @@ class bdist_egg(Command): ('plat-name=', 'p', "platform name to embed in generated filenames " "(default: %s)" % get_platform()), + ('exclude-source-files', None, + "remove all .py files from the generated egg"), ('keep-temp', 'k', "keep the pseudo-installation tree around after " + "creating the distribution archive"), @@ -59,7 +61,7 @@ class bdist_egg(Command): ] boolean_options = [ - 'keep-temp', 'skip-build', + 'keep-temp', 'skip-build', 'exclude-source-files' ] @@ -78,8 +80,6 @@ class bdist_egg(Command): - - def initialize_options (self): self.bdist_dir = None self.plat_name = None @@ -87,7 +87,7 @@ class bdist_egg(Command): self.dist_dir = None self.skip_build = 0 self.egg_output = None - + self.exclude_source_files = None def finalize_options(self): @@ -227,6 +227,8 @@ class bdist_egg(Command): "Use the install_requires/extras_require setup() args instead." ) + if self.exclude_source_files: self.zap_pyfiles() + # Make the archive make_zipfile(self.egg_output, archive_root, verbose=self.verbose, dry_run=self.dry_run) @@ -236,6 +238,45 @@ class bdist_egg(Command): # Add to 'Distribution.dist_files' so that the "upload" command works getattr(self.distribution,'dist_files',[]).append( ('bdist_egg',get_python_version(),self.egg_output)) + + + + + + + def zap_pyfiles(self): + log.info("Removing .py files from temporary directory") + for base,dirs,files in os.walk(self.bdist_dir): + if 'EGG-INFO' in dirs: + dirs.remove('EGG-INFO') + for name in files: + if name.endswith('.py'): + path = os.path.join(base,name) + log.debug("Deleting %s", path) + os.unlink(path) + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.1 From ebe75f51d4e7be105729ac7555b97a17115aa570 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 10 Jul 2005 05:06:31 +0000 Subject: Allow EasyInstall to accept a directory containing a setup script as one of its arguments. Fix swapped short option names for --bdist-dir and --dist-dir in bdist_egg. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041110 --- setuptools/command/bdist_egg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 552bd7e8..21dcc464 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -44,7 +44,7 @@ class bdist_egg(Command): description = "create an \"egg\" distribution" user_options = [ - ('bdist-dir=', 'd', + ('bdist-dir=', 'b', "temporary directory for creating the distribution"), ('plat-name=', 'p', "platform name to embed in generated filenames " @@ -54,7 +54,7 @@ class bdist_egg(Command): ('keep-temp', 'k', "keep the pseudo-installation tree around after " + "creating the distribution archive"), - ('dist-dir=', 'b', + ('dist-dir=', 'd', "directory to put final built distributions in"), ('skip-build', None, "skip rebuilding everything (for testing/debugging)"), -- cgit v1.2.1 From 4b0b1262dced5aab98a18fda75e8e43ae40e28d8 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 10 Jul 2005 16:24:26 +0000 Subject: First-pass implementation of zippability analysis; scans for impure distribution or use of __file__/__path__ and selected 'inspect' operations. Currently, the analysis is a bit overconservative; when the runtime is more robust, it should probably allow extensions to be zipped by default. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041114 --- setuptools/command/bdist_egg.py | 119 +++++++++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 39 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 21dcc464..621bbb18 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -3,13 +3,13 @@ Build .egg distributions""" # This module should be kept compatible with Python 2.3 -import os +import os, marshal from setuptools import Command from distutils.dir_util import remove_tree, mkpath from distutils.sysconfig import get_python_version, get_python_lib from distutils import log from pkg_resources import get_platform, Distribution - +from types import CodeType def write_stub(resource, pyfile): f = open(pyfile,'w') @@ -175,11 +175,12 @@ class bdist_egg(Command): ext_outputs = cmd._mutate_outputs( self.distribution.has_ext_modules(), 'build_ext', 'build_lib', '' ) - + self.stubs = [] to_compile = [] for (p,ext_name) in enumerate(ext_outputs): filename,ext = os.path.splitext(ext_name) pyfile = os.path.join(self.bdist_dir, filename + '.py') + self.stubs.append(pyfile) log.info("creating stub loader for %s" % ext_name) if not self.dry_run: write_stub(os.path.basename(ext_name), pyfile) @@ -202,7 +203,6 @@ class bdist_egg(Command): log.info("installing scripts to %s" % script_dir) self.call_command('install_scripts', install_dir=script_dir) - native_libs = os.path.join(self.egg_info,"native_libs.txt") if ext_outputs: log.info("writing %s" % native_libs) @@ -221,6 +221,10 @@ class bdist_egg(Command): if os.path.isfile(path): self.copy_file(path,os.path.join(egg_info,filename)) + # Write a zip safety flag file + flag = self.zip_safe() and 'zip-safe' or 'not-zip-safe' + open(os.path.join(archive_root,'EGG-INFO',flag),'w').close() + if os.path.exists(os.path.join(self.egg_info,'depends.txt')): log.warn( "WARNING: 'depends.txt' will not be used by setuptools 0.6!\n" @@ -240,49 +244,86 @@ class bdist_egg(Command): ('bdist_egg',get_python_version(),self.egg_output)) - - - - def zap_pyfiles(self): log.info("Removing .py files from temporary directory") - for base,dirs,files in os.walk(self.bdist_dir): - if 'EGG-INFO' in dirs: - dirs.remove('EGG-INFO') + for base,dirs,files in self.walk_contents(): for name in files: if name.endswith('.py'): path = os.path.join(base,name) log.debug("Deleting %s", path) os.unlink(path) - - - - - - - - - - - - - - - - - - - - - - - - - - - - + def walk_contents(self): + """Walk files about to be archived, skipping the metadata directory""" + walker = os.walk(self.bdist_dir) + base,dirs,files = walker.next() + if 'EGG-INFO' in dirs: + dirs.remove('EGG-INFO') + + yield base,dirs,files + for bdf in walker: + yield bdf + + def zip_safe(self): + safe = getattr(self.distribution,'zip_safe',None) + if safe is not None: + return safe + log.warn("zip_safe flag not set; analyzing archive contents...") + safe = True + for base, dirs, files in self.walk_contents(): + for name in files: + if name.endswith('.py') or name.endswith('.pyw'): + continue + elif name.endswith('.pyc') or name.endswith('.pyo'): + # always scan, even if we already know we're not safe + safe = self.scan_module(base, name) and safe + elif safe: + log.warn( + "Distribution contains data or extensions; assuming " + "it's unsafe (set zip_safe=True in setup() to change" + ) + safe = False # XXX + return safe + + def scan_module(self, base, name): + """Check whether module possibly uses unsafe-for-zipfile stuff""" + filename = os.path.join(base,name) + if filename[:-1] in self.stubs: + return True # Extension module + + pkg = base[len(self.bdist_dir)+1:].replace(os.sep,'.') + module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0] + + f = open(filename,'rb'); f.read(8) # skip magic & date + code = marshal.load(f); f.close() + safe = True + + symbols = dict.fromkeys(iter_symbols(code)) + for bad in ['__file__', '__path__']: + if bad in symbols: + log.warn("%s: module references %s", module, bad) + safe = False + if 'inspect' in symbols: + for bad in [ + 'getsource', 'getabsfile', 'getsourcefile', 'getfile' + 'getsourcelines', 'findsource', 'getcomments', 'getframeinfo', + 'getinnerframes', 'getouterframes', 'stack', 'trace' + ]: + if bad in symbols: + log.warn("%s: module MAY be using inspect.%s", module, bad) + safe = False + return safe + + +def iter_symbols(code): + """Yield names and strings used by `code` and its nested code objects""" + for name in code.co_names: yield name + for const in code.co_consts: + if isinstance(const,basestring): + yield const + elif isinstance(const,CodeType): + for name in iter_symbols(const): + yield name # Attribute names of options for commands that might need to be convinced to -- cgit v1.2.1 From d73eb6d059ce9ef94848b918c52453e39a0d213d Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 11 Jul 2005 04:12:48 +0000 Subject: Enhanced "zip safety" analysis (including scan of win32.exe's) and have EasyInstall act on zip safety flags. Add a lot more docs for setuptools. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041115 --- setuptools/command/bdist_egg.py | 163 +++++++++++++++++++++++++--------------- 1 file changed, 102 insertions(+), 61 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 621bbb18..e75a4a9c 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -221,9 +221,7 @@ class bdist_egg(Command): if os.path.isfile(path): self.copy_file(path,os.path.join(egg_info,filename)) - # Write a zip safety flag file - flag = self.zip_safe() and 'zip-safe' or 'not-zip-safe' - open(os.path.join(archive_root,'EGG-INFO',flag),'w').close() + write_safety_flag(archive_root, self.zip_safe()) if os.path.exists(os.path.join(self.egg_info,'depends.txt')): log.warn( @@ -231,8 +229,9 @@ class bdist_egg(Command): "Use the install_requires/extras_require setup() args instead." ) - if self.exclude_source_files: self.zap_pyfiles() - + if self.exclude_source_files: + self.zap_pyfiles() + # Make the archive make_zipfile(self.egg_output, archive_root, verbose=self.verbose, dry_run=self.dry_run) @@ -244,76 +243,118 @@ class bdist_egg(Command): ('bdist_egg',get_python_version(),self.egg_output)) + def zap_pyfiles(self): log.info("Removing .py files from temporary directory") - for base,dirs,files in self.walk_contents(): + for base,dirs,files in walk_egg(self.bdist_dir): for name in files: if name.endswith('.py'): path = os.path.join(base,name) log.debug("Deleting %s", path) os.unlink(path) - def walk_contents(self): - """Walk files about to be archived, skipping the metadata directory""" - walker = os.walk(self.bdist_dir) - base,dirs,files = walker.next() - if 'EGG-INFO' in dirs: - dirs.remove('EGG-INFO') - - yield base,dirs,files - for bdf in walker: - yield bdf - def zip_safe(self): safe = getattr(self.distribution,'zip_safe',None) if safe is not None: return safe log.warn("zip_safe flag not set; analyzing archive contents...") - safe = True - for base, dirs, files in self.walk_contents(): - for name in files: - if name.endswith('.py') or name.endswith('.pyw'): - continue - elif name.endswith('.pyc') or name.endswith('.pyo'): - # always scan, even if we already know we're not safe - safe = self.scan_module(base, name) and safe - elif safe: - log.warn( - "Distribution contains data or extensions; assuming " - "it's unsafe (set zip_safe=True in setup() to change" - ) - safe = False # XXX - return safe - - def scan_module(self, base, name): - """Check whether module possibly uses unsafe-for-zipfile stuff""" - filename = os.path.join(base,name) - if filename[:-1] in self.stubs: - return True # Extension module - - pkg = base[len(self.bdist_dir)+1:].replace(os.sep,'.') - module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0] - - f = open(filename,'rb'); f.read(8) # skip magic & date - code = marshal.load(f); f.close() - safe = True - - symbols = dict.fromkeys(iter_symbols(code)) - for bad in ['__file__', '__path__']: - if bad in symbols: - log.warn("%s: module references %s", module, bad) - safe = False - if 'inspect' in symbols: - for bad in [ - 'getsource', 'getabsfile', 'getsourcefile', 'getfile' - 'getsourcelines', 'findsource', 'getcomments', 'getframeinfo', - 'getinnerframes', 'getouterframes', 'stack', 'trace' - ]: - if bad in symbols: - log.warn("%s: module MAY be using inspect.%s", module, bad) - safe = False - return safe + return analyze_egg(self.bdist_dir, self.stubs) + + + + + + + + + + + + + + + + + + + + + + + + + +def walk_egg(egg_dir): + """Walk an unpacked egg's contents, skipping the metadata directory""" + walker = os.walk(egg_dir) + base,dirs,files = walker.next() + if 'EGG-INFO' in dirs: + dirs.remove('EGG-INFO') + yield base,dirs,files + for bdf in walker: + yield bdf + +def analyze_egg(egg_dir, stubs): + safe = True + for base, dirs, files in walk_egg(egg_dir): + for name in files: + if name.endswith('.py') or name.endswith('.pyw'): + continue + elif name.endswith('.pyc') or name.endswith('.pyo'): + # always scan, even if we already know we're not safe + safe = scan_module(egg_dir, base, name, stubs) and safe + '''elif safe: + log.warn( + "Distribution contains data or extensions; assuming " + "it's unsafe (set zip_safe=True in setup() to change" + ) + safe = False # XXX''' + return safe + +def write_safety_flag(egg_dir, safe): + # Write a zip safety flag file + flag = safe and 'zip-safe' or 'not-zip-safe' + open(os.path.join(egg_dir,'EGG-INFO',flag),'w').close() + + + + + + + + + + +def scan_module(egg_dir, base, name, stubs): + """Check whether module possibly uses unsafe-for-zipfile stuff""" + + filename = os.path.join(base,name) + if filename[:-1] in stubs: + return True # Extension module + + pkg = base[len(egg_dir)+1:].replace(os.sep,'.') + module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0] + + f = open(filename,'rb'); f.read(8) # skip magic & date + code = marshal.load(f); f.close() + safe = True + + symbols = dict.fromkeys(iter_symbols(code)) + for bad in ['__file__', '__path__']: + if bad in symbols: + log.warn("%s: module references %s", module, bad) + safe = False + if 'inspect' in symbols: + for bad in [ + 'getsource', 'getabsfile', 'getsourcefile', 'getfile' + 'getsourcelines', 'findsource', 'getcomments', 'getframeinfo', + 'getinnerframes', 'getouterframes', 'stack', 'trace' + ]: + if bad in symbols: + log.warn("%s: module MAY be using inspect.%s", module, bad) + safe = False + return safe def iter_symbols(code): """Yield names and strings used by `code` and its nested code objects""" -- cgit v1.2.1 From b9c686a49c0154f849aef99dcacaecffc45378eb Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 12 Jul 2005 23:43:22 +0000 Subject: Update zip-safety scanner to check for modules that might be used as ``python -m`` scripts. Misc. fixes for win32.exe support, including changes to support Python 2.4's changed ``bdist_wininst`` format. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041123 --- setuptools/command/bdist_egg.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index e75a4a9c..0a9d9a0c 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -332,14 +332,11 @@ def scan_module(egg_dir, base, name, stubs): filename = os.path.join(base,name) if filename[:-1] in stubs: return True # Extension module - pkg = base[len(egg_dir)+1:].replace(os.sep,'.') module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0] - f = open(filename,'rb'); f.read(8) # skip magic & date code = marshal.load(f); f.close() safe = True - symbols = dict.fromkeys(iter_symbols(code)) for bad in ['__file__', '__path__']: if bad in symbols: @@ -353,7 +350,11 @@ def scan_module(egg_dir, base, name, stubs): ]: if bad in symbols: log.warn("%s: module MAY be using inspect.%s", module, bad) - safe = False + safe = False + if '__name__' in symbols and '__main__' in symbols and '.' not in module: + if get_python_version()>="2.4": + log.warn("%s: top-level module may be 'python -m' script", module) + safe = False return safe def iter_symbols(code): @@ -366,7 +367,6 @@ def iter_symbols(code): for name in iter_symbols(const): yield name - # Attribute names of options for commands that might need to be convinced to # install to the egg build directory -- cgit v1.2.1 From 471ae3465a5fe8e1cd2e15ee989e7a91c163acf0 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sun, 14 Aug 2005 21:17:45 +0000 Subject: Auto-generate namespace __init__.py files for packages without them. This is a workaround for packages like 'll-color', which are distributed without 'll/__init__.py', to avoid overwriting ll-core's copy of ll/__init__.py. This allows existing packages that use this sort of kludging to be treated as a crude namespace package, as long as the "real" __init__.py also calls declare_namespace(). --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041204 --- setuptools/command/bdist_egg.py | 54 ++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 0a9d9a0c..eb92bd24 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -26,8 +26,8 @@ def write_stub(resource, pyfile): ])) f.close() - - +# stub __init__.py for packages distributed without one +NS_PKG_STUB = '__import__("pkg_resources").declare_namespace(__name__)' @@ -186,7 +186,7 @@ class bdist_egg(Command): write_stub(os.path.basename(ext_name), pyfile) to_compile.append(pyfile) ext_outputs[p] = ext_name.replace(os.sep,'/') - + to_compile.extend(self.make_init_files()) if to_compile: cmd.byte_compile(to_compile) @@ -260,30 +260,30 @@ class bdist_egg(Command): log.warn("zip_safe flag not set; analyzing archive contents...") return analyze_egg(self.bdist_dir, self.stubs) - - - - - - - - - - - - - - - - - - - - - - - - + def make_init_files(self): + """Create missing package __init__ files""" + init_files = [] + for base,dirs,files in walk_egg(self.bdist_dir): + if base==self.bdist_dir: + # don't put an __init__ in the root + continue + for name in files: + if name.endswith('.py'): + if '__init__.py' not in files: + pkg = base[len(self.bdist_dir)+1:].replace(os.sep,'.') + if self.distribution.has_contents_for(pkg): + log.warn("Creating missing __init__.py for %s",pkg) + filename = os.path.join(base,'__init__.py') + if not self.dry_run: + f = open(filename,'w'); f.write(NS_PKG_STUB) + f.close() + init_files.append(filename) + break + else: + # not a package, don't traverse to subdirectories + dirs[:] = [] + + return init_files def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" -- cgit v1.2.1 From b577c94170b64436919bea8e002c64623d0a9644 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 22 Aug 2005 13:40:10 +0000 Subject: Make easy_install --record strip the RPM root when building RPMs, and have bdist_egg ignore the RPM root when building an egg. This version now can actually run bdist_rpm to completion, although the resulting RPM will install an egg without a corresponding .pth file. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041226 --- setuptools/command/bdist_egg.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index eb92bd24..1f17bb82 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -170,7 +170,11 @@ class bdist_egg(Command): # pull their data path from the install_lib command. log.info("installing library code to %s" % self.bdist_dir) + instcmd = self.get_finalized_command('install') + old_root = instcmd.root + instcmd.root = None cmd = self.call_command('install_lib', warn_dir=0) + instcmd.root = old_root ext_outputs = cmd._mutate_outputs( self.distribution.has_ext_modules(), 'build_ext', 'build_lib', '' -- cgit v1.2.1 From b2382a4ed6703da09393343974c87ce0f4ce6670 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 23 Aug 2005 13:24:42 +0000 Subject: Simplify non-root install process and improve Mac OS docs for it. Support .pth files and legacy packages possibly being symlinks, and ensure that overwrites don't follow the symlink. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041229 --- setuptools/command/bdist_egg.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 1f17bb82..0c5fae43 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -168,14 +168,11 @@ class bdist_egg(Command): # We run install_lib before install_data, because some data hacks # pull their data path from the install_lib command. - log.info("installing library code to %s" % self.bdist_dir) instcmd = self.get_finalized_command('install') - old_root = instcmd.root - instcmd.root = None + old_root = instcmd.root; instcmd.root = None cmd = self.call_command('install_lib', warn_dir=0) instcmd.root = old_root - ext_outputs = cmd._mutate_outputs( self.distribution.has_ext_modules(), 'build_ext', 'build_lib', '' ) @@ -201,7 +198,6 @@ class bdist_egg(Command): archive_root = self.bdist_dir egg_info = os.path.join(archive_root,'EGG-INFO') self.mkpath(egg_info) - if self.distribution.scripts: script_dir = os.path.join(egg_info, 'scripts') log.info("installing scripts to %s" % script_dir) -- cgit v1.2.1 From ff23de19b2189dc8cf0d7730034fa01667bda04a Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sat, 3 Sep 2005 03:20:54 +0000 Subject: Work around a problem with SuSE Linux's patched install_lib command, by figuring out the extension paths without its help. :( --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041234 --- setuptools/command/bdist_egg.py | 47 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 0c5fae43..dd30ffbd 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -173,9 +173,8 @@ class bdist_egg(Command): old_root = instcmd.root; instcmd.root = None cmd = self.call_command('install_lib', warn_dir=0) instcmd.root = old_root - ext_outputs = cmd._mutate_outputs( - self.distribution.has_ext_modules(), 'build_ext', 'build_lib', '' - ) + + ext_outputs = self.get_ext_outputs() self.stubs = [] to_compile = [] for (p,ext_name) in enumerate(ext_outputs): @@ -187,6 +186,7 @@ class bdist_egg(Command): write_stub(os.path.basename(ext_name), pyfile) to_compile.append(pyfile) ext_outputs[p] = ext_name.replace(os.sep,'/') + to_compile.extend(self.make_init_files()) if to_compile: cmd.byte_compile(to_compile) @@ -284,6 +284,47 @@ class bdist_egg(Command): dirs[:] = [] return init_files + + def get_ext_outputs(self): + """Get a list of relative paths to C extensions in the output distro""" + + if not self.distribution.has_ext_modules(): + return [] + + build_cmd = self.get_finalized_command('build_ext') + prefix_len = len(build_cmd.build_lib) + len(os.sep) + + outputs = [] + for filename in build_cmd.get_outputs(): + outputs.append(filename[prefix_len:]) + + return outputs + + + + + + + + + + + + + + + + + + + + + + + + + + def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" -- cgit v1.2.1 From 4869239fcea5c102385155550c3005b3f92ecfe5 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 9 Nov 2005 03:23:34 +0000 Subject: Detect .dll, .so, .dylib and .pyd files that might have been included in a project as data files rather than as Python extensions. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041409 --- setuptools/command/bdist_egg.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index dd30ffbd..9003542f 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -288,31 +288,31 @@ class bdist_egg(Command): def get_ext_outputs(self): """Get a list of relative paths to C extensions in the output distro""" + outputs = [] + paths = {self.bdist_dir:''} + for base, dirs, files in os.walk(self.bdist_dir): + for filename in files: + if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS: + outputs.append(paths[base]+filename) + for filename in dirs: + paths[os.path.join(base,filename)] = paths[base]+filename+'/' + if not self.distribution.has_ext_modules(): - return [] + return outputs build_cmd = self.get_finalized_command('build_ext') prefix_len = len(build_cmd.build_lib) + len(os.sep) - outputs = [] for filename in build_cmd.get_outputs(): - outputs.append(filename[prefix_len:]) + if os.path.splitext(filename)[1].lower() not in NATIVE_EXTENSIONS: + # only add files w/unrecognized extensions, since the + # recognized ones will already be in the list + outputs.append(filename[prefix_len:]) return outputs - - - - - - - - - - - - +NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) -- cgit v1.2.1 From 207ddcbad2db42f7f94099ab501ab46351e56f4d Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 14 Dec 2005 20:49:36 +0000 Subject: Basic roundtripping support between bdist_wininst and eggs. EasyInstall will now recognize when a bdist_wininst .exe wraps a .egg-info style package, and reconstitute it correctly, maintaining the original zip safety flag, if applicable. This still needs support for entrypoint scripts, though, as does the install_scripts command. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041678 --- setuptools/command/bdist_egg.py | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 9003542f..16d2486f 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -221,7 +221,9 @@ class bdist_egg(Command): if os.path.isfile(path): self.copy_file(path,os.path.join(egg_info,filename)) - write_safety_flag(archive_root, self.zip_safe()) + write_safety_flag( + os.path.join(archive_root,'EGG-INFO'), self.zip_safe() + ) if os.path.exists(os.path.join(self.egg_info,'depends.txt')): log.warn( @@ -242,8 +244,6 @@ class bdist_egg(Command): getattr(self.distribution,'dist_files',[]).append( ('bdist_egg',get_python_version(),self.egg_output)) - - def zap_pyfiles(self): log.info("Removing .py files from temporary directory") for base,dirs,files in walk_egg(self.bdist_dir): @@ -337,6 +337,11 @@ def walk_egg(egg_dir): yield bdf def analyze_egg(egg_dir, stubs): + # check for existing flag in EGG-INFO + for flag,fn in safety_flags.items(): + if os.path.exists(os.path.join(egg_dir,'EGG-INFO',fn)): + return flag + safe = True for base, dirs, files in walk_egg(egg_dir): for name in files: @@ -345,27 +350,22 @@ def analyze_egg(egg_dir, stubs): elif name.endswith('.pyc') or name.endswith('.pyo'): # always scan, even if we already know we're not safe safe = scan_module(egg_dir, base, name, stubs) and safe - '''elif safe: - log.warn( - "Distribution contains data or extensions; assuming " - "it's unsafe (set zip_safe=True in setup() to change" - ) - safe = False # XXX''' return safe def write_safety_flag(egg_dir, safe): - # Write a zip safety flag file - flag = safe and 'zip-safe' or 'not-zip-safe' - open(os.path.join(egg_dir,'EGG-INFO',flag),'w').close() - - - - - - - - - + # Write or remove zip safety flag file(s) + for flag,fn in safety_flags.items(): + fn = os.path.join(egg_dir, fn) + if os.path.exists(fn): + if safe is None or bool(safe)<>flag: + os.unlink(fn) + elif safe is not None and bool(safe)==flag: + open(fn,'w').close() + +safety_flags = { + True: 'zip-safe', + False: 'not-zip-safe', +} def scan_module(egg_dir, base, name, stubs): """Check whether module possibly uses unsafe-for-zipfile stuff""" -- cgit v1.2.1 From f41432389955d4e1835cef866d23b15ab6edf51a Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 13 Jan 2006 22:32:57 +0000 Subject: Don't write .py stubs except for actual extensions that don't already have them. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4042034 --- setuptools/command/bdist_egg.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 16d2486f..68b1ba67 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -10,6 +10,7 @@ from distutils.sysconfig import get_python_version, get_python_lib from distutils import log from pkg_resources import get_platform, Distribution from types import CodeType +from setuptools.extension import Library def write_stub(resource, pyfile): f = open(pyfile,'w') @@ -38,7 +39,6 @@ NS_PKG_STUB = '__import__("pkg_resources").declare_namespace(__name__)' - class bdist_egg(Command): description = "create an \"egg\" distribution" @@ -174,7 +174,7 @@ class bdist_egg(Command): cmd = self.call_command('install_lib', warn_dir=0) instcmd.root = old_root - ext_outputs = self.get_ext_outputs() + all_outputs, ext_outputs = self.get_ext_outputs() self.stubs = [] to_compile = [] for (p,ext_name) in enumerate(ext_outputs): @@ -204,11 +204,11 @@ class bdist_egg(Command): self.call_command('install_scripts', install_dir=script_dir) native_libs = os.path.join(self.egg_info,"native_libs.txt") - if ext_outputs: + if all_outputs: log.info("writing %s" % native_libs) if not self.dry_run: libs_file = open(native_libs, 'wt') - libs_file.write('\n'.join(ext_outputs)) + libs_file.write('\n'.join(all_outputs)) libs_file.write('\n') libs_file.close() elif os.path.isfile(native_libs): @@ -288,28 +288,28 @@ class bdist_egg(Command): def get_ext_outputs(self): """Get a list of relative paths to C extensions in the output distro""" - outputs = [] + all_outputs = [] + ext_outputs = [] + paths = {self.bdist_dir:''} for base, dirs, files in os.walk(self.bdist_dir): for filename in files: if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS: - outputs.append(paths[base]+filename) + all_outputs.append(paths[base]+filename) for filename in dirs: paths[os.path.join(base,filename)] = paths[base]+filename+'/' - - if not self.distribution.has_ext_modules(): - return outputs - - build_cmd = self.get_finalized_command('build_ext') - prefix_len = len(build_cmd.build_lib) + len(os.sep) - - for filename in build_cmd.get_outputs(): - if os.path.splitext(filename)[1].lower() not in NATIVE_EXTENSIONS: - # only add files w/unrecognized extensions, since the - # recognized ones will already be in the list - outputs.append(filename[prefix_len:]) - return outputs + if self.distribution.has_ext_modules(): + build_cmd = self.get_finalized_command('build_ext') + for ext in build_cmd.extensions: + if isinstance(ext,Library): + continue + fullname = build_cmd.get_ext_fullname(ext.name) + filename = build_cmd.get_ext_filename(fullname) + if not os.path.basename(filename).startswith('dl-'): + ext_outputs.append(filename) + + return all_outputs, ext_outputs NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) -- cgit v1.2.1 From 49c03612e7eb1a75ec836c574f6d1711fb6ecebf Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 13 Feb 2006 17:32:42 +0000 Subject: Fixed duplication of scripts inside .egg files --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4042345 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 68b1ba67..4c0976d4 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -201,7 +201,7 @@ class bdist_egg(Command): if self.distribution.scripts: script_dir = os.path.join(egg_info, 'scripts') log.info("installing scripts to %s" % script_dir) - self.call_command('install_scripts', install_dir=script_dir) + self.call_command('install_scripts',install_dir=script_dir,no_ep=1) native_libs = os.path.join(self.egg_info,"native_libs.txt") if all_outputs: -- cgit v1.2.1 From f4be07202e3e615ba7fc0e2256d236356cdc6902 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 13 Feb 2006 21:35:50 +0000 Subject: Don't compress eggs on Python 2.3, as a possible workaround for 64-bit zipimport bug. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4042351 --- setuptools/command/bdist_egg.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 4c0976d4..2a48362e 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -3,7 +3,7 @@ Build .egg distributions""" # This module should be kept compatible with Python 2.3 -import os, marshal +import sys, os, marshal from setuptools import Command from distutils.dir_util import remove_tree, mkpath from distutils.sysconfig import get_python_version, get_python_lib @@ -415,8 +415,7 @@ INSTALL_DIRECTORY_ATTRS = [ 'install_lib', 'install_dir', 'install_data', 'install_base' ] - -def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): +def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0, compress=None): """Create a zip file from all the files under 'base_dir'. The output zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed @@ -425,7 +424,6 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): """ import zipfile mkpath(os.path.dirname(zip_filename), dry_run=dry_run) - log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir) def visit (z, dirname, names): @@ -437,9 +435,12 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): z.write(path, p) log.debug("adding '%s'" % p) + if compress is None: + compress = (sys.version>="2.4") # avoid 2.3 zipimport bug when 64 bits + + compression = [zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED][bool(compress)] if not dry_run: - z = zipfile.ZipFile(zip_filename, "w", - compression=zipfile.ZIP_DEFLATED) + z = zipfile.ZipFile(zip_filename, "w", compression=compression) os.path.walk(base_dir, visit, z) z.close() else: @@ -448,4 +449,3 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): return zip_filename - -- cgit v1.2.1 From 854c175586480056a84ee5e7806becd36e3803f6 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 21 Mar 2006 19:04:55 +0000 Subject: Don't generate a loader .py file in .egg file for extensions that aren't actually built. This prevents problems w/customized setups that make some extensions optional (e.g. scipy.distutils). --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4043201 --- setuptools/command/bdist_egg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 2a48362e..d571ac80 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -307,7 +307,8 @@ class bdist_egg(Command): fullname = build_cmd.get_ext_fullname(ext.name) filename = build_cmd.get_ext_filename(fullname) if not os.path.basename(filename).startswith('dl-'): - ext_outputs.append(filename) + if os.path.exists(os.path.join(self.bdist_dir,filename)): + ext_outputs.append(filename) return all_outputs, ext_outputs @@ -325,7 +326,6 @@ NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) - def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" walker = os.walk(egg_dir) -- cgit v1.2.1 From fe16ffbec3ca87fbfb0071c5a0d80e6c2fc9efee Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 18 Apr 2006 16:16:33 +0000 Subject: Split ``get_platform()`` into ``get_supported_platform()`` and ``get_build_platform()`` to work around a Mac versioning problem that caused the behavior of ``compatible_platforms()`` to be platform specific. (Backport from 0.7 trunk, rev 45536) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4045538 --- setuptools/command/bdist_egg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index d571ac80..74f2d426 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -8,7 +8,7 @@ from setuptools import Command from distutils.dir_util import remove_tree, mkpath from distutils.sysconfig import get_python_version, get_python_lib from distutils import log -from pkg_resources import get_platform, Distribution +from pkg_resources import get_build_platform, Distribution from types import CodeType from setuptools.extension import Library @@ -48,7 +48,7 @@ class bdist_egg(Command): "temporary directory for creating the distribution"), ('plat-name=', 'p', "platform name to embed in generated filenames " - "(default: %s)" % get_platform()), + "(default: %s)" % get_build_platform()), ('exclude-source-files', None, "remove all .py files from the generated egg"), ('keep-temp', 'k', @@ -99,7 +99,7 @@ class bdist_egg(Command): self.bdist_dir = os.path.join(bdist_base, 'egg') if self.plat_name is None: - self.plat_name = get_platform() + self.plat_name = get_build_platform() self.set_undefined_options('bdist',('dist_dir', 'dist_dir')) -- cgit v1.2.1 From 847ce20a9390a14d3c415d9127db4bf9b86af3cb Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 24 Apr 2006 20:52:59 +0000 Subject: Backport 'module' fixes to 0.6 --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4045696 --- setuptools/command/bdist_egg.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 74f2d426..ae94a869 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -12,6 +12,13 @@ from pkg_resources import get_build_platform, Distribution from types import CodeType from setuptools.extension import Library +def strip_module(filename): + if '.' in filename: + filename = os.path.splitext(filename)[0] + if filename.endswith('module'): + filename = filename[:-6] + return filename + def write_stub(resource, pyfile): f = open(pyfile,'w') f.write('\n'.join([ @@ -32,13 +39,6 @@ NS_PKG_STUB = '__import__("pkg_resources").declare_namespace(__name__)' - - - - - - - class bdist_egg(Command): description = "create an \"egg\" distribution" @@ -179,7 +179,7 @@ class bdist_egg(Command): to_compile = [] for (p,ext_name) in enumerate(ext_outputs): filename,ext = os.path.splitext(ext_name) - pyfile = os.path.join(self.bdist_dir, filename + '.py') + pyfile = os.path.join(self.bdist_dir, strip_module(filename)+'.py') self.stubs.append(pyfile) log.info("creating stub loader for %s" % ext_name) if not self.dry_run: -- cgit v1.2.1 From dcd12bd1088713adb87cfc1344ca30b10869ae36 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 28 Apr 2006 18:13:46 +0000 Subject: Backport doc fixes and 2.4-only -m safety check to 0.6 branch --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4045791 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index ae94a869..7f32c369 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -393,7 +393,7 @@ def scan_module(egg_dir, base, name, stubs): log.warn("%s: module MAY be using inspect.%s", module, bad) safe = False if '__name__' in symbols and '__main__' in symbols and '.' not in module: - if get_python_version()>="2.4": + if sys.version[:3]=="2.4": # -m works w/zipfiles in 2.5 log.warn("%s: top-level module may be 'python -m' script", module) safe = False return safe -- cgit v1.2.1 From f51668576f921197b6596d835a810a130e7a77e4 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 7 Jun 2006 19:36:49 +0000 Subject: Fix bdist_egg not including files in .egg-info subdirectories. (merge from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4046722 --- setuptools/command/bdist_egg.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 7f32c369..0ae3984e 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -8,7 +8,7 @@ from setuptools import Command from distutils.dir_util import remove_tree, mkpath from distutils.sysconfig import get_python_version, get_python_lib from distutils import log -from pkg_resources import get_build_platform, Distribution +from pkg_resources import get_build_platform, Distribution, ensure_directory from types import CodeType from setuptools.extension import Library @@ -91,7 +91,7 @@ class bdist_egg(Command): def finalize_options(self): - ei_cmd = self.get_finalized_command("egg_info") + ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info") self.egg_info = ei_cmd.egg_info if self.bdist_dir is None: @@ -216,10 +216,7 @@ class bdist_egg(Command): if not self.dry_run: os.unlink(native_libs) - for filename in os.listdir(self.egg_info): - path = os.path.join(self.egg_info,filename) - if os.path.isfile(path): - self.copy_file(path,os.path.join(egg_info,filename)) + self.copy_metadata_to(egg_info) write_safety_flag( os.path.join(archive_root,'EGG-INFO'), self.zip_safe() @@ -233,7 +230,7 @@ class bdist_egg(Command): if self.exclude_source_files: self.zap_pyfiles() - + # Make the archive make_zipfile(self.egg_output, archive_root, verbose=self.verbose, dry_run=self.dry_run) @@ -244,6 +241,9 @@ class bdist_egg(Command): getattr(self.distribution,'dist_files',[]).append( ('bdist_egg',get_python_version(),self.egg_output)) + + + def zap_pyfiles(self): log.info("Removing .py files from temporary directory") for base,dirs,files in walk_egg(self.bdist_dir): @@ -262,7 +262,7 @@ class bdist_egg(Command): def make_init_files(self): """Create missing package __init__ files""" - init_files = [] + init_files = [] for base,dirs,files in walk_egg(self.bdist_dir): if base==self.bdist_dir: # don't put an __init__ in the root @@ -276,7 +276,7 @@ class bdist_egg(Command): filename = os.path.join(base,'__init__.py') if not self.dry_run: f = open(filename,'w'); f.write(NS_PKG_STUB) - f.close() + f.close() init_files.append(filename) break else: @@ -285,6 +285,14 @@ class bdist_egg(Command): return init_files + def copy_metadata_to(self, target_dir): + prefix = os.path.join(self.egg_info,'') + for path in self.ei_cmd.filelist.files: + if path.startswith(prefix): + target = os.path.join(target_dir, path[len(prefix):]) + ensure_directory(target) + self.copy_file(path, target) + def get_ext_outputs(self): """Get a list of relative paths to C extensions in the output distro""" @@ -318,18 +326,10 @@ NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) - - - - - - - - def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" walker = os.walk(egg_dir) - base,dirs,files = walker.next() + base,dirs,files = walker.next() if 'EGG-INFO' in dirs: dirs.remove('EGG-INFO') yield base,dirs,files @@ -448,4 +448,4 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0, compress=None): return zip_filename - +# -- cgit v1.2.1 From 403e6845234a3eb83b5e2858edb5e204f6641842 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 14 Jul 2006 23:37:52 +0000 Subject: * Fixed ``AttributeError`` when trying to download a ``setup_requires`` dependency when a distribution lacks a ``dependency_links`` setting. * Made ``zip-safe`` and ``not-zip-safe`` flag files contain a single byte, so as to play better with packaging tools that complain about zero-length files. * Made ``setup.py develop`` respect the ``--no-deps`` option, which it previously was ignoring. (bug fixes backported from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4050659 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 0ae3984e..981a1f9b 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -360,7 +360,7 @@ def write_safety_flag(egg_dir, safe): if safe is None or bool(safe)<>flag: os.unlink(fn) elif safe is not None and bool(safe)==flag: - open(fn,'w').close() + f=open(fn,'wb'); f.write('\n'); f.close() safety_flags = { True: 'zip-safe', -- cgit v1.2.1 From ae347c1ed3e39fb2c00b8b9fc8aedcf507313c20 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 22 Sep 2006 00:09:06 +0000 Subject: Add support for "eggsecutable" headers: a /bin/sh script that is prepended to an .egg file to allow it to be run as a script on Unix-ish platforms. (This is mainly so that setuptools itself can have a single-file installer on Unix, without doing multiple downloads, dealing with firewalls, etc.) (Backport from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4051969 --- setuptools/command/bdist_egg.py | 57 +++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 981a1f9b..1f768e82 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -8,7 +8,9 @@ from setuptools import Command from distutils.dir_util import remove_tree, mkpath from distutils.sysconfig import get_python_version, get_python_lib from distutils import log +from distutils.errors import DistutilsSetupError from pkg_resources import get_build_platform, Distribution, ensure_directory +from pkg_resources import EntryPoint from types import CodeType from setuptools.extension import Library @@ -37,8 +39,6 @@ def write_stub(resource, pyfile): # stub __init__.py for packages distributed without one NS_PKG_STUB = '__import__("pkg_resources").declare_namespace(__name__)' - - class bdist_egg(Command): description = "create an \"egg\" distribution" @@ -233,7 +233,7 @@ class bdist_egg(Command): # Make the archive make_zipfile(self.egg_output, archive_root, verbose=self.verbose, - dry_run=self.dry_run) + dry_run=self.dry_run, mode=self.gen_header()) if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) @@ -285,6 +285,47 @@ class bdist_egg(Command): return init_files + def gen_header(self): + epm = EntryPoint.parse_map(self.distribution.entry_points or '') + ep = epm.get('setuptools.installation',{}).get('eggsecutable') + if ep is None: + return 'w' # not an eggsecutable, do it the usual way. + + if not ep.attrs or ep.extras: + raise DistutilsSetupError( + "eggsecutable entry point (%r) cannot have 'extras' " + "or refer to a module" % (ep,) + ) + + pyver = sys.version[:3] + pkg = ep.module_name + full = '.'.join(ep.attrs) + base = ep.attrs[0] + basename = os.path.basename(self.egg_output) + + header = ( + "#!/bin/sh\n" + 'if [[ `basename $0` = "%(basename)s" ]]\n' + 'then exec python%(pyver)s -c "' + "import sys, os; sys.path.insert(0, os.path.abspath('$0')); " + "from %(pkg)s import %(base)s; sys.exit(%(full)s())" + '" "$@"\n' + 'else\n' + ' echo $0 is not the correct name for this egg file.\n' + ' echo Please rename it back to %(basename)s and try again.\n' + ' exec false\n' + 'fi\n' + + ) % locals() + + if not self.dry_run: + f = open(self.egg_output, 'w') + f.write(header) + f.close() + return 'a' + + + def copy_metadata_to(self, target_dir): prefix = os.path.join(self.egg_info,'') for path in self.ei_cmd.filelist.files: @@ -415,7 +456,9 @@ INSTALL_DIRECTORY_ATTRS = [ 'install_lib', 'install_dir', 'install_data', 'install_base' ] -def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0, compress=None): +def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, + mode='w' +): """Create a zip file from all the files under 'base_dir'. The output zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed @@ -426,7 +469,7 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0, compress=None): mkpath(os.path.dirname(zip_filename), dry_run=dry_run) log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir) - def visit (z, dirname, names): + def visit(z, dirname, names): for name in names: path = os.path.normpath(os.path.join(dirname, name)) if os.path.isfile(path): @@ -440,12 +483,10 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0, compress=None): compression = [zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED][bool(compress)] if not dry_run: - z = zipfile.ZipFile(zip_filename, "w", compression=compression) + z = zipfile.ZipFile(zip_filename, mode, compression=compression) os.path.walk(base_dir, visit, z) z.close() else: os.path.walk(base_dir, visit, None) - return zip_filename - # -- cgit v1.2.1 From 07a18df5a16b6df50102a0e931d7c4c91b186b48 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Thu, 28 Sep 2006 04:50:22 +0000 Subject: Fix problem generating "eggsecutable" header if dist/ dir doesn't exist yet. (backport from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4052024 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 1f768e82..f7128fd1 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -319,13 +319,13 @@ class bdist_egg(Command): ) % locals() if not self.dry_run: + mkpath(os.path.dirname(self.egg_output), dry_run=self.dry_run) f = open(self.egg_output, 'w') f.write(header) f.close() return 'a' - def copy_metadata_to(self, target_dir): prefix = os.path.join(self.egg_info,'') for path in self.ei_cmd.filelist.files: -- cgit v1.2.1 From ba006a1c6da9674ab91b5b0e6be616c06ec00799 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 24 Jan 2007 15:26:00 +0000 Subject: Fix "eggsecutables" (such as setuptools' own egg) only being runnable with bash-compatible shells. (backport from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4053540 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index f7128fd1..2e9007ce 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -305,7 +305,7 @@ class bdist_egg(Command): header = ( "#!/bin/sh\n" - 'if [[ `basename $0` = "%(basename)s" ]]\n' + 'if [ `basename $0` = "%(basename)s" ]\n' 'then exec python%(pyver)s -c "' "import sys, os; sys.path.insert(0, os.path.abspath('$0')); " "from %(pkg)s import %(base)s; sys.exit(%(full)s())" -- cgit v1.2.1 From 7c4938d53774c51b441970e177ce72cc3bdf68ce Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 18 Jan 2008 21:51:23 +0000 Subject: chmod/test cleanups and Jython compatibility (backport from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4060062 --- setuptools/command/bdist_egg.py | 43 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 2e9007ce..bb1112c1 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -382,7 +382,7 @@ def analyze_egg(egg_dir, stubs): for flag,fn in safety_flags.items(): if os.path.exists(os.path.join(egg_dir,'EGG-INFO',fn)): return flag - + if not can_scan(): return False safe = True for base, dirs, files in walk_egg(egg_dir): for name in files: @@ -448,6 +448,47 @@ def iter_symbols(code): elif isinstance(const,CodeType): for name in iter_symbols(const): yield name + +def can_scan(): + if not sys.platform.startswith('java') and sys.platform != 'cli': + # CPython, PyPy, etc. + return True + log.warn("Unable to analyze compiled code on this platform.") + log.warn("Please ask the author to include a 'zip_safe'" + " setting (either True or False) in the package's setup.py") + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # Attribute names of options for commands that might need to be convinced to # install to the egg build directory -- cgit v1.2.1 From 3dc61ffa084eaff9c3515f8faf7fde19a94160dd Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Thu, 21 Aug 2008 19:20:10 +0000 Subject: Fix for http://bugs.python.org/setuptools/issue9 (backport from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4065955 --- setuptools/command/bdist_egg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index bb1112c1..61fd6c3d 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -203,10 +203,12 @@ class bdist_egg(Command): log.info("installing scripts to %s" % script_dir) self.call_command('install_scripts',install_dir=script_dir,no_ep=1) - native_libs = os.path.join(self.egg_info,"native_libs.txt") + self.copy_metadata_to(egg_info) + native_libs = os.path.join(egg_info, "native_libs.txt") if all_outputs: log.info("writing %s" % native_libs) if not self.dry_run: + ensure_directory(native_libs) libs_file = open(native_libs, 'wt') libs_file.write('\n'.join(all_outputs)) libs_file.write('\n') @@ -216,8 +218,6 @@ class bdist_egg(Command): if not self.dry_run: os.unlink(native_libs) - self.copy_metadata_to(egg_info) - write_safety_flag( os.path.join(archive_root,'EGG-INFO'), self.zip_safe() ) -- cgit v1.2.1 From fda8b67a391633a89527c1ba47e13bd39327a888 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Thu, 11 Sep 2008 15:44:25 +0000 Subject: Fix for http://bugs.python.org/setuptools/issue37 - missing __loader__ running under Google App Engine. (backport from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4066389 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 61fd6c3d..9e852a3f 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -29,7 +29,7 @@ def write_stub(resource, pyfile): " import sys, pkg_resources, imp", " __file__ = pkg_resources.resource_filename(__name__,%r)" % resource, - " del __bootstrap__, __loader__", + " __loader__ = None; del __bootstrap__, __loader__", " imp.load_dynamic(__name__,__file__)", "__bootstrap__()", "" # terminal \n -- cgit v1.2.1 From c1098e903f4eab3c673089fb60d3540e28fe0778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 12 Sep 2009 16:58:06 +0200 Subject: Replace os.path.walk with os.walk. --HG-- branch : distribute extra : rebase_source : 9bc223da3173d759f3c59eb72138e7405b4384ed --- setuptools/command/bdist_egg.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 9e852a3f..32cebe9d 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -525,9 +525,11 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, compression = [zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED][bool(compress)] if not dry_run: z = zipfile.ZipFile(zip_filename, mode, compression=compression) - os.path.walk(base_dir, visit, z) + for dirname, dirs, files in os.walk(base_dir): + visit(z, dirname, files) z.close() else: - os.path.walk(base_dir, visit, None) + for dirname, dirs, files in os.walk(base_dir): + visit(None, dirname, file) return zip_filename # -- cgit v1.2.1 From 709275f058fc9062b7a10db5123bd1ef91500832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 12 Sep 2009 23:22:28 +0200 Subject: Open zipsafe file in text mode. --HG-- branch : distribute extra : rebase_source : 3215e6d146816dc96a2cb23b6a6fb16fd63e1648 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 32cebe9d..43589c23 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -401,7 +401,7 @@ def write_safety_flag(egg_dir, safe): if safe is None or bool(safe)<>flag: os.unlink(fn) elif safe is not None and bool(safe)==flag: - f=open(fn,'wb'); f.write('\n'); f.close() + f=open(fn,'wt'); f.write('\n'); f.close() safety_flags = { True: 'zip-safe', -- cgit v1.2.1 From 5c528f51ae4ce4dd5359c350af9f0b3cacee36ba Mon Sep 17 00:00:00 2001 From: tarek Date: Sun, 24 Jan 2010 23:17:23 +0100 Subject: Python 2.7 compat --HG-- branch : distribute extra : rebase_source : f60f3110e0dd27c406f8fc48c4ed49da4dec8cac --- setuptools/command/bdist_egg.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 43589c23..90e1f525 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -6,7 +6,12 @@ Build .egg distributions""" import sys, os, marshal from setuptools import Command from distutils.dir_util import remove_tree, mkpath -from distutils.sysconfig import get_python_version, get_python_lib +try: + from distutils.sysconfig import get_python_version, get_python_lib +except ImportError: + from sysconfig import get_python_version + from distutils.sysconfig import get_python_lib + from distutils import log from distutils.errors import DistutilsSetupError from pkg_resources import get_build_platform, Distribution, ensure_directory -- cgit v1.2.1 From a6f96e7709806a0211de70a0eb9089de77d000e2 Mon Sep 17 00:00:00 2001 From: Tarek Ziade Date: Tue, 21 Sep 2010 17:35:08 +0200 Subject: fixed typo - thanks to Ted Tibbets --HG-- branch : distribute extra : rebase_source : 87b145e4977333b08b77bdf857930f456c8b0e13 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 90e1f525..3bb56fc3 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -535,6 +535,6 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, z.close() else: for dirname, dirs, files in os.walk(base_dir): - visit(None, dirname, file) + visit(None, dirname, files) return zip_filename # -- cgit v1.2.1 From 5a4d274c93ab53f31f3926757cbe80a0dbdf0130 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 16 Mar 2011 16:19:13 -0400 Subject: Fix for issue192 --HG-- branch : distribute extra : rebase_source : cbae39614a979ea69ced9a0541e71b0377c3a9d5 --- setuptools/command/bdist_egg.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 3bb56fc3..68ca15c7 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -332,7 +332,11 @@ class bdist_egg(Command): def copy_metadata_to(self, target_dir): - prefix = os.path.join(self.egg_info,'') + "Copy metadata (egg info) to the target_dir" + # normalize the path (so that a forward-slash in egg_info will + # match using startswith below) + norm_egg_info = os.path.normpath(self.egg_info) + prefix = os.path.join(norm_egg_info,'') for path in self.ei_cmd.filelist.files: if path.startswith(prefix): target = os.path.join(target_dir, path[len(prefix):]) -- cgit v1.2.1 From 58a658b26d1c95b31d02050dcccd648d2e4ce27b Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 20 Jun 2011 22:55:16 +0100 Subject: Changes to support 2.x and 3.x in the same codebase. --HG-- branch : distribute extra : rebase_source : 7d3608edee54a43789f0574d702fb839628b5071 --- setuptools/command/bdist_egg.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 68ca15c7..007f3ba9 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -17,6 +17,7 @@ from distutils.errors import DistutilsSetupError from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint from types import CodeType +from setuptools.compat import basestring, next from setuptools.extension import Library def strip_module(filename): @@ -379,7 +380,7 @@ NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" walker = os.walk(egg_dir) - base,dirs,files = walker.next() + base,dirs,files = next(walker) if 'EGG-INFO' in dirs: dirs.remove('EGG-INFO') yield base,dirs,files @@ -407,7 +408,7 @@ def write_safety_flag(egg_dir, safe): for flag,fn in safety_flags.items(): fn = os.path.join(egg_dir, fn) if os.path.exists(fn): - if safe is None or bool(safe)<>flag: + if safe is None or bool(safe) != flag: os.unlink(fn) elif safe is not None and bool(safe)==flag: f=open(fn,'wt'); f.write('\n'); f.close() -- cgit v1.2.1 From 311fb781f87f8885d9a94343b4b7e9731bc0c9e7 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 26 Jun 2012 15:15:27 -0700 Subject: Add tests and fix for marshal.load of pyc files on Python 3.3 Fixes https://bitbucket.org/tarek/distribute/issue/283/bdist_egg-issues-with-python-330ax --HG-- branch : distribute extra : rebase_source : ec6f2611d3f8a54b7e11cfadf9d03fdcdef39639 --- setuptools/command/bdist_egg.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 68ca15c7..0ee9c55b 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -426,7 +426,11 @@ def scan_module(egg_dir, base, name, stubs): pkg = base[len(egg_dir)+1:].replace(os.sep,'.') module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0] f = open(filename,'rb'); f.read(8) # skip magic & date - code = marshal.load(f); f.close() + try: + code = marshal.load(f); f.close() + except ValueError: + f.seek(0); f.read(12) # skip magic & date & file size; file size added in Python 3.3 + code = marshal.load(f); f.close() safe = True symbols = dict.fromkeys(iter_symbols(code)) for bad in ['__file__', '__path__']: -- cgit v1.2.1 From 12c0d7f3e916957294a095a8425554fe8413e42e Mon Sep 17 00:00:00 2001 From: Jim Fulton Date: Sat, 14 Jul 2012 14:25:06 -0400 Subject: Issue #283 bdist_egg issues with python 3.3.0aX --HG-- branch : distribute extra : rebase_source : 3173cb1ab5550635b8565767059701ab2649ac19 --- setuptools/command/bdist_egg.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 68ca15c7..a9d98d3b 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -459,6 +459,8 @@ def iter_symbols(code): yield name def can_scan(): + if sys.version_info > (3, 3): + return False # Can't scan recent formats if not sys.platform.startswith('java') and sys.platform != 'cli': # CPython, PyPy, etc. return True -- cgit v1.2.1 From 4084ebc22ff58d406b73fe25c069b5235f04c4d8 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Wed, 25 Jul 2012 05:11:56 +0200 Subject: Issue #283: Reenable scanning of *.pyc / *.pyo files on Python 3.3. Scanning of these files was fixed in commit 2479772eeea7. --HG-- branch : distribute extra : rebase_source : fcbb14f0e6efc2c42b691fa2a8920816903ede42 --- setuptools/command/bdist_egg.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index cf2d75e4..0ee9c55b 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -463,8 +463,6 @@ def iter_symbols(code): yield name def can_scan(): - if sys.version_info > (3, 3): - return False # Can't scan recent formats if not sys.platform.startswith('java') and sys.platform != 'cli': # CPython, PyPy, etc. return True -- cgit v1.2.1 From 9553dd9910df577351ea04bb1613767096beeca0 Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Mon, 8 Oct 2012 20:58:18 +0200 Subject: marshall.load() does not necessarily raise ValueError. Fixes #283. --HG-- branch : distribute extra : rebase_source : 203cee618118fb65bf109d2db0275aa90aa5a12d --- setuptools/command/bdist_egg.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 0ee9c55b..17fae984 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -425,12 +425,12 @@ def scan_module(egg_dir, base, name, stubs): return True # Extension module pkg = base[len(egg_dir)+1:].replace(os.sep,'.') module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0] - f = open(filename,'rb'); f.read(8) # skip magic & date - try: - code = marshal.load(f); f.close() - except ValueError: - f.seek(0); f.read(12) # skip magic & date & file size; file size added in Python 3.3 - code = marshal.load(f); f.close() + if sys.version_info < (3, 3): + skip = 8 # skip magic & date + else: + skip = 12 # skip magic & date & file size + f = open(filename,'rb'); f.read(skip) + code = marshal.load(f); f.close() safe = True symbols = dict.fromkeys(iter_symbols(code)) for bad in ['__file__', '__path__']: -- cgit v1.2.1 From ff75a6cbdbcde8d9e3b979c30c3d6e64a1bc5374 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 3 May 2013 23:09:46 -0400 Subject: Copy changes from 1aae1efe5733 for setuptools/command/* (except easy_install.py --HG-- branch : Setuptools-Distribute merge extra : source : 0c89fbb19c269ce1cb3bc3e9ece9864127768169 --- setuptools/command/bdist_egg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 9e852a3f..7e5a3799 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -165,12 +165,13 @@ class bdist_egg(Command): def run(self): # Generate metadata first self.run_command("egg_info") - # We run install_lib before install_data, because some data hacks # pull their data path from the install_lib command. log.info("installing library code to %s" % self.bdist_dir) instcmd = self.get_finalized_command('install') old_root = instcmd.root; instcmd.root = None + if self.distribution.has_c_libraries() and not self.skip_build: + self.run_command('build_clib') cmd = self.call_command('install_lib', warn_dir=0) instcmd.root = old_root @@ -190,7 +191,6 @@ class bdist_egg(Command): to_compile.extend(self.make_init_files()) if to_compile: cmd.byte_compile(to_compile) - if self.distribution.data_files: self.do_install_data() @@ -398,7 +398,7 @@ def write_safety_flag(egg_dir, safe): for flag,fn in safety_flags.items(): fn = os.path.join(egg_dir, fn) if os.path.exists(fn): - if safe is None or bool(safe)<>flag: + if safe is None or bool(safe)!=flag: os.unlink(fn) elif safe is not None and bool(safe)==flag: f=open(fn,'wb'); f.write('\n'); f.close() -- cgit v1.2.1 From c04abca662dcbffd00d928e06fbf32b9f49f8e57 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Wed, 12 Jun 2013 03:53:21 +0200 Subject: Use new sysconfig module with Python 2.7 or >=3.2. --- setuptools/command/bdist_egg.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index c3356bb7..1ba0499e 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -7,10 +7,14 @@ import sys, os, marshal from setuptools import Command from distutils.dir_util import remove_tree, mkpath try: - from distutils.sysconfig import get_python_version, get_python_lib + # Python 2.7 or >=3.2 + from sysconfig import get_path, get_python_version + def _get_purelib(): + return get_path("purelib") except ImportError: - from sysconfig import get_python_version - from distutils.sysconfig import get_python_lib + from distutils.sysconfig import get_python_lib, get_python_version + def _get_purelib(): + return get_python_lib(False) from distutils import log from distutils.errors import DistutilsSetupError @@ -130,7 +134,7 @@ class bdist_egg(Command): # Hack for packages that install data to install's --install-lib self.get_finalized_command('install').install_lib = self.bdist_dir - site_packages = os.path.normcase(os.path.realpath(get_python_lib())) + site_packages = os.path.normcase(os.path.realpath(_get_purelib())) old, self.distribution.data_files = self.distribution.data_files,[] for item in old: -- cgit v1.2.1 From 911fe5e498a58f1a05b2a7b3a34dfcaa7b9dd89d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 11 Feb 2014 22:33:15 -0500 Subject: Backed out changeset 28901bac2f2e See #148 --HG-- branch : setuptools extra : amend_source : 73cc453f11a0b77f930138eee03b1fc8e69399af --- setuptools/command/bdist_egg.py | 54 ++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index eb92bd24..0a9d9a0c 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -26,8 +26,8 @@ def write_stub(resource, pyfile): ])) f.close() -# stub __init__.py for packages distributed without one -NS_PKG_STUB = '__import__("pkg_resources").declare_namespace(__name__)' + + @@ -186,7 +186,7 @@ class bdist_egg(Command): write_stub(os.path.basename(ext_name), pyfile) to_compile.append(pyfile) ext_outputs[p] = ext_name.replace(os.sep,'/') - to_compile.extend(self.make_init_files()) + if to_compile: cmd.byte_compile(to_compile) @@ -260,30 +260,30 @@ class bdist_egg(Command): log.warn("zip_safe flag not set; analyzing archive contents...") return analyze_egg(self.bdist_dir, self.stubs) - def make_init_files(self): - """Create missing package __init__ files""" - init_files = [] - for base,dirs,files in walk_egg(self.bdist_dir): - if base==self.bdist_dir: - # don't put an __init__ in the root - continue - for name in files: - if name.endswith('.py'): - if '__init__.py' not in files: - pkg = base[len(self.bdist_dir)+1:].replace(os.sep,'.') - if self.distribution.has_contents_for(pkg): - log.warn("Creating missing __init__.py for %s",pkg) - filename = os.path.join(base,'__init__.py') - if not self.dry_run: - f = open(filename,'w'); f.write(NS_PKG_STUB) - f.close() - init_files.append(filename) - break - else: - # not a package, don't traverse to subdirectories - dirs[:] = [] - - return init_files + + + + + + + + + + + + + + + + + + + + + + + + def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" -- cgit v1.2.1 From 4d159b9c8e84676146e41b144271818492f2a6fa Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Mar 2014 13:54:26 +0100 Subject: Update bdist_egg for style --- setuptools/command/bdist_egg.py | 133 ++++++++++------------------------------ 1 file changed, 34 insertions(+), 99 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 8f4d44c3..383eb5f8 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -3,7 +3,9 @@ Build .egg distributions""" # This module should be kept compatible with Python 2.3 -import sys, os, marshal +import sys +import os +import marshal from setuptools import Command from distutils.dir_util import remove_tree, mkpath try: @@ -33,22 +35,21 @@ def strip_module(filename): def write_stub(resource, pyfile): f = open(pyfile,'w') - f.write('\n'.join([ - "def __bootstrap__():", - " global __bootstrap__, __loader__, __file__", - " import sys, pkg_resources, imp", - " __file__ = pkg_resources.resource_filename(__name__,%r)" - % resource, - " __loader__ = None; del __bootstrap__, __loader__", - " imp.load_dynamic(__name__,__file__)", - "__bootstrap__()", - "" # terminal \n - ])) + f.write( + '\n'.join([ + "def __bootstrap__():", + " global __bootstrap__, __loader__, __file__", + " import sys, pkg_resources, imp", + " __file__ = pkg_resources.resource_filename(__name__,%r)" + % resource, + " __loader__ = None; del __bootstrap__, __loader__", + " imp.load_dynamic(__name__,__file__)", + "__bootstrap__()", + "" # terminal \n + ])) f.close() - - class bdist_egg(Command): description = "create an \"egg\" distribution" @@ -56,41 +57,24 @@ class bdist_egg(Command): user_options = [ ('bdist-dir=', 'b', "temporary directory for creating the distribution"), - ('plat-name=', 'p', - "platform name to embed in generated filenames " - "(default: %s)" % get_build_platform()), + ('plat-name=', 'p', "platform name to embed in generated filenames " + "(default: %s)" % get_build_platform()), ('exclude-source-files', None, - "remove all .py files from the generated egg"), + "remove all .py files from the generated egg"), ('keep-temp', 'k', - "keep the pseudo-installation tree around after " + - "creating the distribution archive"), + "keep the pseudo-installation tree around after " + + "creating the distribution archive"), ('dist-dir=', 'd', - "directory to put final built distributions in"), + "directory to put final built distributions in"), ('skip-build', None, - "skip rebuilding everything (for testing/debugging)"), + "skip rebuilding everything (for testing/debugging)"), ] boolean_options = [ 'keep-temp', 'skip-build', 'exclude-source-files' ] - - - - - - - - - - - - - - - - - def initialize_options (self): + def initialize_options(self): self.bdist_dir = None self.plat_name = None self.keep_temp = 0 @@ -99,7 +83,6 @@ class bdist_egg(Command): self.egg_output = None self.exclude_source_files = None - def finalize_options(self): ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info") self.egg_info = ei_cmd.egg_info @@ -124,13 +107,6 @@ class bdist_egg(Command): self.egg_output = os.path.join(self.dist_dir, basename+'.egg') - - - - - - - def do_install_data(self): # Hack for packages that install data to install's --install-lib self.get_finalized_command('install').install_lib = self.bdist_dir @@ -156,11 +132,9 @@ class bdist_egg(Command): finally: self.distribution.data_files = old - def get_outputs(self): return [self.egg_output] - def call_command(self,cmdname,**kw): """Invoke reinitialized command `cmdname` with keyword args""" for dirname in INSTALL_DIRECTORY_ATTRS: @@ -171,7 +145,6 @@ class bdist_egg(Command): self.run_command(cmdname) return cmd - def run(self): # Generate metadata first self.run_command("egg_info") @@ -179,7 +152,8 @@ class bdist_egg(Command): # pull their data path from the install_lib command. log.info("installing library code to %s" % self.bdist_dir) instcmd = self.get_finalized_command('install') - old_root = instcmd.root; instcmd.root = None + old_root = instcmd.root + instcmd.root = None if self.distribution.has_c_libraries() and not self.skip_build: self.run_command('build_clib') cmd = self.call_command('install_lib', warn_dir=0) @@ -242,7 +216,7 @@ class bdist_egg(Command): # Make the archive make_zipfile(self.egg_output, archive_root, verbose=self.verbose, - dry_run=self.dry_run, mode=self.gen_header()) + dry_run=self.dry_run, mode=self.gen_header()) if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) @@ -250,9 +224,6 @@ class bdist_egg(Command): getattr(self.distribution,'dist_files',[]).append( ('bdist_egg',get_python_version(),self.egg_output)) - - - def zap_pyfiles(self): log.info("Removing .py files from temporary directory") for base,dirs,files in walk_egg(self.bdist_dir): @@ -269,8 +240,6 @@ class bdist_egg(Command): log.warn("zip_safe flag not set; analyzing archive contents...") return analyze_egg(self.bdist_dir, self.stubs) - - def gen_header(self): epm = EntryPoint.parse_map(self.distribution.entry_points or '') ep = epm.get('setuptools.installation',{}).get('eggsecutable') @@ -311,7 +280,6 @@ class bdist_egg(Command): f.close() return 'a' - def copy_metadata_to(self, target_dir): "Copy metadata (egg info) to the target_dir" # normalize the path (so that a forward-slash in egg_info will @@ -355,8 +323,6 @@ class bdist_egg(Command): NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) - - def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" walker = os.walk(egg_dir) @@ -391,7 +357,9 @@ def write_safety_flag(egg_dir, safe): if safe is None or bool(safe) != flag: os.unlink(fn) elif safe is not None and bool(safe)==flag: - f=open(fn,'wt'); f.write('\n'); f.close() + f = open(fn,'wt') + f.write('\n') + f.close() safety_flags = { True: 'zip-safe', @@ -410,8 +378,10 @@ def scan_module(egg_dir, base, name, stubs): skip = 8 # skip magic & date else: skip = 12 # skip magic & date & file size - f = open(filename,'rb'); f.read(skip) - code = marshal.load(f); f.close() + f = open(filename,'rb') + f.read(skip) + code = marshal.load(f) + f.close() safe = True symbols = dict.fromkeys(iter_symbols(code)) for bad in ['__file__', '__path__']: @@ -451,39 +421,6 @@ def can_scan(): log.warn("Please ask the author to include a 'zip_safe'" " setting (either True or False) in the package's setup.py") - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Attribute names of options for commands that might need to be convinced to # install to the egg build directory @@ -492,8 +429,7 @@ INSTALL_DIRECTORY_ATTRS = [ ] def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, - mode='w' -): + mode='w'): """Create a zip file from all the files under 'base_dir'. The output zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed @@ -526,4 +462,3 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, for dirname, dirs, files in os.walk(base_dir): visit(None, dirname, files) return zip_filename -# -- cgit v1.2.1 From c410f8d4eaaba5575453fbee26948419bbc2a247 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Mar 2014 13:58:43 +0100 Subject: Create stub template from a multiline string. --- setuptools/command/bdist_egg.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 383eb5f8..0d1cc65e 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -6,6 +6,7 @@ Build .egg distributions""" import sys import os import marshal +import textwrap from setuptools import Command from distutils.dir_util import remove_tree, mkpath try: @@ -34,19 +35,17 @@ def strip_module(filename): return filename def write_stub(resource, pyfile): + _stub_template = textwrap.dedent(""" + def __bootstrap__(): + global __bootstrap__, __loader__, __file__ + import sys, pkg_resources, imp + __file__ = pkg_resources.resource_filename(__name__, %r) + __loader__ = None; del __bootstrap__, __loader__ + imp.load_dynamic(__name__,__file__) + __bootstrap__() + """).lstrip() f = open(pyfile,'w') - f.write( - '\n'.join([ - "def __bootstrap__():", - " global __bootstrap__, __loader__, __file__", - " import sys, pkg_resources, imp", - " __file__ = pkg_resources.resource_filename(__name__,%r)" - % resource, - " __loader__ = None; del __bootstrap__, __loader__", - " imp.load_dynamic(__name__,__file__)", - "__bootstrap__()", - "" # terminal \n - ])) + f.write(_stub_template % resource) f.close() -- cgit v1.2.1 From 86cd51682907df59a05918584bb85663862adeac Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Mar 2014 13:59:13 +0100 Subject: Use file context for write_stub --- setuptools/command/bdist_egg.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 0d1cc65e..c19a0ba7 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -44,9 +44,8 @@ def write_stub(resource, pyfile): imp.load_dynamic(__name__,__file__) __bootstrap__() """).lstrip() - f = open(pyfile,'w') - f.write(_stub_template % resource) - f.close() + with open(pyfile, 'w') as f: + f.write(_stub_template % resource) class bdist_egg(Command): -- 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/bdist_egg.py | 157 ++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 70 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index c19a0ba7..831d6042 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -3,29 +3,33 @@ Build .egg distributions""" # This module should be kept compatible with Python 2.3 +from distutils.errors import DistutilsSetupError +from distutils.dir_util import remove_tree, mkpath +from distutils import log +from types import CodeType import sys import os import marshal import textwrap + +from pkg_resources import get_build_platform, Distribution, ensure_directory +from pkg_resources import EntryPoint +from setuptools.compat import basestring, next +from setuptools.extension import Library from setuptools import Command -from distutils.dir_util import remove_tree, mkpath + try: # Python 2.7 or >=3.2 from sysconfig import get_path, get_python_version + def _get_purelib(): return get_path("purelib") except ImportError: from distutils.sysconfig import get_python_lib, get_python_version + def _get_purelib(): return get_python_lib(False) -from distutils import log -from distutils.errors import DistutilsSetupError -from pkg_resources import get_build_platform, Distribution, ensure_directory -from pkg_resources import EntryPoint -from types import CodeType -from setuptools.compat import basestring, next -from setuptools.extension import Library def strip_module(filename): if '.' in filename: @@ -34,6 +38,7 @@ def strip_module(filename): filename = filename[:-6] return filename + def write_stub(resource, pyfile): _stub_template = textwrap.dedent(""" def __bootstrap__(): @@ -49,23 +54,22 @@ def write_stub(resource, pyfile): class bdist_egg(Command): - description = "create an \"egg\" distribution" user_options = [ ('bdist-dir=', 'b', - "temporary directory for creating the distribution"), + "temporary directory for creating the distribution"), ('plat-name=', 'p', "platform name to embed in generated filenames " - "(default: %s)" % get_build_platform()), + "(default: %s)" % get_build_platform()), ('exclude-source-files', None, - "remove all .py files from the generated egg"), + "remove all .py files from the generated egg"), ('keep-temp', 'k', - "keep the pseudo-installation tree around after " + - "creating the distribution archive"), + "keep the pseudo-installation tree around after " + + "creating the distribution archive"), ('dist-dir=', 'd', - "directory to put final built distributions in"), + "directory to put final built distributions in"), ('skip-build', None, - "skip rebuilding everything (for testing/debugging)"), + "skip rebuilding everything (for testing/debugging)"), ] boolean_options = [ @@ -92,7 +96,7 @@ class bdist_egg(Command): if self.plat_name is None: self.plat_name = get_build_platform() - self.set_undefined_options('bdist',('dist_dir', 'dist_dir')) + self.set_undefined_options('bdist', ('dist_dir', 'dist_dir')) if self.egg_output is None: @@ -103,25 +107,25 @@ class bdist_egg(Command): self.distribution.has_ext_modules() and self.plat_name ).egg_name() - self.egg_output = os.path.join(self.dist_dir, basename+'.egg') + self.egg_output = os.path.join(self.dist_dir, basename + '.egg') def do_install_data(self): # Hack for packages that install data to install's --install-lib self.get_finalized_command('install').install_lib = self.bdist_dir site_packages = os.path.normcase(os.path.realpath(_get_purelib())) - old, self.distribution.data_files = self.distribution.data_files,[] + old, self.distribution.data_files = self.distribution.data_files, [] for item in old: - if isinstance(item,tuple) and len(item)==2: + if isinstance(item, tuple) and len(item) == 2: if os.path.isabs(item[0]): realpath = os.path.realpath(item[0]) normalized = os.path.normcase(realpath) - if normalized==site_packages or normalized.startswith( - site_packages+os.sep + if normalized == site_packages or normalized.startswith( + site_packages + os.sep ): - item = realpath[len(site_packages)+1:], item[1] - # XXX else: raise ??? + item = realpath[len(site_packages) + 1:], item[1] + # XXX else: raise ??? self.distribution.data_files.append(item) try: @@ -133,11 +137,11 @@ class bdist_egg(Command): def get_outputs(self): return [self.egg_output] - def call_command(self,cmdname,**kw): + def call_command(self, cmdname, **kw): """Invoke reinitialized command `cmdname` with keyword args""" for dirname in INSTALL_DIRECTORY_ATTRS: - kw.setdefault(dirname,self.bdist_dir) - kw.setdefault('skip_build',self.skip_build) + kw.setdefault(dirname, self.bdist_dir) + kw.setdefault('skip_build', self.skip_build) kw.setdefault('dry_run', self.dry_run) cmd = self.reinitialize_command(cmdname, **kw) self.run_command(cmdname) @@ -160,15 +164,16 @@ class bdist_egg(Command): all_outputs, ext_outputs = self.get_ext_outputs() self.stubs = [] to_compile = [] - for (p,ext_name) in enumerate(ext_outputs): - filename,ext = os.path.splitext(ext_name) - pyfile = os.path.join(self.bdist_dir, strip_module(filename)+'.py') + for (p, ext_name) in enumerate(ext_outputs): + filename, ext = os.path.splitext(ext_name) + pyfile = os.path.join(self.bdist_dir, strip_module(filename) + + '.py') self.stubs.append(pyfile) log.info("creating stub loader for %s" % ext_name) if not self.dry_run: write_stub(os.path.basename(ext_name), pyfile) to_compile.append(pyfile) - ext_outputs[p] = ext_name.replace(os.sep,'/') + ext_outputs[p] = ext_name.replace(os.sep, '/') if to_compile: cmd.byte_compile(to_compile) @@ -177,12 +182,13 @@ class bdist_egg(Command): # Make the EGG-INFO directory archive_root = self.bdist_dir - egg_info = os.path.join(archive_root,'EGG-INFO') + egg_info = os.path.join(archive_root, 'EGG-INFO') self.mkpath(egg_info) if self.distribution.scripts: script_dir = os.path.join(egg_info, 'scripts') log.info("installing scripts to %s" % script_dir) - self.call_command('install_scripts',install_dir=script_dir,no_ep=1) + self.call_command('install_scripts', install_dir=script_dir, + no_ep=1) self.copy_metadata_to(egg_info) native_libs = os.path.join(egg_info, "native_libs.txt") @@ -200,10 +206,10 @@ class bdist_egg(Command): os.unlink(native_libs) write_safety_flag( - os.path.join(archive_root,'EGG-INFO'), self.zip_safe() + os.path.join(archive_root, 'EGG-INFO'), self.zip_safe() ) - if os.path.exists(os.path.join(self.egg_info,'depends.txt')): + if os.path.exists(os.path.join(self.egg_info, 'depends.txt')): log.warn( "WARNING: 'depends.txt' will not be used by setuptools 0.6!\n" "Use the install_requires/extras_require setup() args instead." @@ -214,25 +220,25 @@ class bdist_egg(Command): # Make the archive make_zipfile(self.egg_output, archive_root, verbose=self.verbose, - dry_run=self.dry_run, mode=self.gen_header()) + dry_run=self.dry_run, mode=self.gen_header()) if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) # Add to 'Distribution.dist_files' so that the "upload" command works - getattr(self.distribution,'dist_files',[]).append( - ('bdist_egg',get_python_version(),self.egg_output)) + getattr(self.distribution, 'dist_files', []).append( + ('bdist_egg', get_python_version(), self.egg_output)) def zap_pyfiles(self): log.info("Removing .py files from temporary directory") - for base,dirs,files in walk_egg(self.bdist_dir): + for base, dirs, files in walk_egg(self.bdist_dir): for name in files: if name.endswith('.py'): - path = os.path.join(base,name) + path = os.path.join(base, name) log.debug("Deleting %s", path) os.unlink(path) def zip_safe(self): - safe = getattr(self.distribution,'zip_safe',None) + safe = getattr(self.distribution, 'zip_safe', None) if safe is not None: return safe log.warn("zip_safe flag not set; analyzing archive contents...") @@ -240,7 +246,7 @@ class bdist_egg(Command): def gen_header(self): epm = EntryPoint.parse_map(self.distribution.entry_points or '') - ep = epm.get('setuptools.installation',{}).get('eggsecutable') + ep = epm.get('setuptools.installation', {}).get('eggsecutable') if ep is None: return 'w' # not an eggsecutable, do it the usual way. @@ -268,7 +274,6 @@ class bdist_egg(Command): ' echo Please rename it back to %(basename)s and try again.\n' ' exec false\n' 'fi\n' - ) % locals() if not self.dry_run: @@ -283,7 +288,7 @@ class bdist_egg(Command): # normalize the path (so that a forward-slash in egg_info will # match using startswith below) norm_egg_info = os.path.normpath(self.egg_info) - prefix = os.path.join(norm_egg_info,'') + prefix = os.path.join(norm_egg_info, '') for path in self.ei_cmd.filelist.files: if path.startswith(prefix): target = os.path.join(target_dir, path[len(prefix):]) @@ -296,23 +301,24 @@ class bdist_egg(Command): all_outputs = [] ext_outputs = [] - paths = {self.bdist_dir:''} + paths = {self.bdist_dir: ''} for base, dirs, files in os.walk(self.bdist_dir): for filename in files: if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS: - all_outputs.append(paths[base]+filename) + all_outputs.append(paths[base] + filename) for filename in dirs: - paths[os.path.join(base,filename)] = paths[base]+filename+'/' + paths[os.path.join(base, filename)] = (paths[base] + + filename + '/') if self.distribution.has_ext_modules(): build_cmd = self.get_finalized_command('build_ext') for ext in build_cmd.extensions: - if isinstance(ext,Library): + if isinstance(ext, Library): continue fullname = build_cmd.get_ext_fullname(ext.name) filename = build_cmd.get_ext_filename(fullname) if not os.path.basename(filename).startswith('dl-'): - if os.path.exists(os.path.join(self.bdist_dir,filename)): + if os.path.exists(os.path.join(self.bdist_dir, filename)): ext_outputs.append(filename) return all_outputs, ext_outputs @@ -324,19 +330,21 @@ NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" walker = os.walk(egg_dir) - base,dirs,files = next(walker) + base, dirs, files = next(walker) if 'EGG-INFO' in dirs: dirs.remove('EGG-INFO') - yield base,dirs,files + yield base, dirs, files for bdf in walker: yield bdf + def analyze_egg(egg_dir, stubs): # check for existing flag in EGG-INFO - for flag,fn in safety_flags.items(): - if os.path.exists(os.path.join(egg_dir,'EGG-INFO',fn)): + for flag, fn in safety_flags.items(): + if os.path.exists(os.path.join(egg_dir, 'EGG-INFO', fn)): return flag - if not can_scan(): return False + if not can_scan(): + return False safe = True for base, dirs, files in walk_egg(egg_dir): for name in files: @@ -347,36 +355,39 @@ def analyze_egg(egg_dir, stubs): safe = scan_module(egg_dir, base, name, stubs) and safe return safe + def write_safety_flag(egg_dir, safe): # Write or remove zip safety flag file(s) - for flag,fn in safety_flags.items(): + for flag, fn in safety_flags.items(): fn = os.path.join(egg_dir, fn) if os.path.exists(fn): if safe is None or bool(safe) != flag: os.unlink(fn) - elif safe is not None and bool(safe)==flag: - f = open(fn,'wt') + elif safe is not None and bool(safe) == flag: + f = open(fn, 'wt') f.write('\n') f.close() + safety_flags = { True: 'zip-safe', False: 'not-zip-safe', } + def scan_module(egg_dir, base, name, stubs): """Check whether module possibly uses unsafe-for-zipfile stuff""" - filename = os.path.join(base,name) + filename = os.path.join(base, name) if filename[:-1] in stubs: - return True # Extension module - pkg = base[len(egg_dir)+1:].replace(os.sep,'.') - module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0] + return True # Extension module + pkg = base[len(egg_dir) + 1:].replace(os.sep, '.') + module = pkg + (pkg and '.' or '') + os.path.splitext(name)[0] if sys.version_info < (3, 3): - skip = 8 # skip magic & date + skip = 8 # skip magic & date else: skip = 12 # skip magic & date & file size - f = open(filename,'rb') + f = open(filename, 'rb') f.read(skip) code = marshal.load(f) f.close() @@ -396,21 +407,24 @@ def scan_module(egg_dir, base, name, stubs): log.warn("%s: module MAY be using inspect.%s", module, bad) safe = False if '__name__' in symbols and '__main__' in symbols and '.' not in module: - if sys.version[:3]=="2.4": # -m works w/zipfiles in 2.5 + if sys.version[:3] == "2.4": # -m works w/zipfiles in 2.5 log.warn("%s: top-level module may be 'python -m' script", module) safe = False return safe + def iter_symbols(code): """Yield names and strings used by `code` and its nested code objects""" - for name in code.co_names: yield name + for name in code.co_names: + yield name for const in code.co_consts: - if isinstance(const,basestring): + if isinstance(const, basestring): yield const - elif isinstance(const,CodeType): + elif isinstance(const, CodeType): for name in iter_symbols(const): yield name + def can_scan(): if not sys.platform.startswith('java') and sys.platform != 'cli': # CPython, PyPy, etc. @@ -426,8 +440,9 @@ INSTALL_DIRECTORY_ATTRS = [ 'install_lib', 'install_dir', 'install_data', 'install_base' ] + def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, - mode='w'): + mode='w'): """Create a zip file from all the files under 'base_dir'. The output zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed @@ -435,6 +450,7 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, raises DistutilsExecError. Returns the name of the output zip file. """ import zipfile + mkpath(os.path.dirname(zip_filename), dry_run=dry_run) log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir) @@ -442,13 +458,14 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, for name in names: path = os.path.normpath(os.path.join(dirname, name)) if os.path.isfile(path): - p = path[len(base_dir)+1:] + p = path[len(base_dir) + 1:] if not dry_run: z.write(path, p) log.debug("adding '%s'" % p) if compress is None: - compress = (sys.version>="2.4") # avoid 2.3 zipimport bug when 64 bits + # avoid 2.3 zipimport bug when 64 bits + compress = (sys.version >= "2.4") compression = [zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED][bool(compress)] if not dry_run: -- cgit v1.2.1 From 508f0f5134f3f5e87f53b7773086c8ecb30c527e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Jul 2014 15:00:26 -0400 Subject: next compatibility is no longer required --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 831d6042..34fdeec2 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -14,7 +14,7 @@ import textwrap from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint -from setuptools.compat import basestring, next +from setuptools.compat import basestring from setuptools.extension import Library from setuptools import Command -- cgit v1.2.1 From b49435397a5094f94678adf3549cc8941aa469b7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Jul 2014 15:06:51 -0400 Subject: Use six for Python 2 compatibility --HG-- branch : feature/issue-229 extra : source : 7b1997ececc5772798ce33a0f8e77387cb55a977 --- setuptools/command/bdist_egg.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 34fdeec2..3d241b99 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -12,9 +12,10 @@ import os import marshal import textwrap +import six + from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint -from setuptools.compat import basestring from setuptools.extension import Library from setuptools import Command @@ -418,7 +419,7 @@ def iter_symbols(code): for name in code.co_names: yield name for const in code.co_consts: - if isinstance(const, basestring): + if isinstance(const, six.string_types): yield const elif isinstance(const, CodeType): for name in iter_symbols(const): -- 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/bdist_egg.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 34fdeec2..87dce882 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -2,7 +2,6 @@ Build .egg distributions""" -# This module should be kept compatible with Python 2.3 from distutils.errors import DistutilsSetupError from distutils.dir_util import remove_tree, mkpath from distutils import log @@ -406,10 +405,6 @@ def scan_module(egg_dir, base, name, stubs): if bad in symbols: log.warn("%s: module MAY be using inspect.%s", module, bad) safe = False - if '__name__' in symbols and '__main__' in symbols and '.' not in module: - if sys.version[:3] == "2.4": # -m works w/zipfiles in 2.5 - log.warn("%s: top-level module may be 'python -m' script", module) - safe = False return safe @@ -441,7 +436,7 @@ INSTALL_DIRECTORY_ATTRS = [ ] -def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, +def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=True, mode='w'): """Create a zip file from all the files under 'base_dir'. The output zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" @@ -463,11 +458,7 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None, z.write(path, p) log.debug("adding '%s'" % p) - if compress is None: - # avoid 2.3 zipimport bug when 64 bits - compress = (sys.version >= "2.4") - - compression = [zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED][bool(compress)] + compression = zipfile.ZIP_DEFLATED if compress else zipfile.ZIP_STORED if not dry_run: z = zipfile.ZipFile(zip_filename, mode, compression=compression) for dirname, dirs, files in os.walk(base_dir): -- cgit v1.2.1 From 06872bb0bbbeb953e90bd0941444b0d499056557 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 31 Dec 2015 11:51:01 -0500 Subject: Update vendoring technique to match that used for packaging. Ref #229. --HG-- branch : feature/issue-229 --- setuptools/command/bdist_egg.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 73f8e3f1..78164819 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -11,7 +11,12 @@ import os import marshal import textwrap -import six +try: + from setuptools._vendor import six +except ImportError: + # fallback to naturally-installed version; allows system packagers to + # omit vendored packages. + import six from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint -- cgit v1.2.1 From 952c1bafda1929c74c737646aa025e6ffad6632e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 31 Dec 2015 16:30:47 -0500 Subject: Modeling after Astropy's technique for bundling libraries, the imports are now much cleaner. Thanks @embray. Ref #229. --HG-- branch : feature/issue-229 --- setuptools/command/bdist_egg.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 78164819..9cebd7fa 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -11,12 +11,7 @@ import os import marshal import textwrap -try: - from setuptools._vendor import six -except ImportError: - # fallback to naturally-installed version; allows system packagers to - # omit vendored packages. - import six +from setuptools.extern import six from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint -- cgit v1.2.1 From 01de794bc829cc9eb0c1512b3570acec970e1acf Mon Sep 17 00:00:00 2001 From: stepshal Date: Thu, 14 Jul 2016 21:45:22 +0700 Subject: Put imports in same block alphabeticaly. --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 9cebd7fa..c40022a1 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -8,8 +8,8 @@ from distutils import log from types import CodeType import sys import os -import marshal import textwrap +import marshal from setuptools.extern import six -- cgit v1.2.1 From 39bf3155d47c0024240be414a611dcb6d549f53c Mon Sep 17 00:00:00 2001 From: stepshal Date: Thu, 21 Jul 2016 09:37:34 +0700 Subject: Add missing blank lines after class or function definition. --- setuptools/command/bdist_egg.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index c40022a1..50744b87 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -432,6 +432,7 @@ def can_scan(): # Attribute names of options for commands that might need to be convinced to # install to the egg build directory + INSTALL_DIRECTORY_ATTRS = [ 'install_lib', 'install_dir', 'install_data', 'install_base' ] -- cgit v1.2.1 From 18c0fdab26ba13a9cf142408d7f1f2566be21fa7 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Wed, 3 Aug 2016 13:55:56 +0200 Subject: Fix logging using arguments instead of formatter --- setuptools/command/bdist_egg.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 50744b87..cbea7537 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -129,7 +129,7 @@ class bdist_egg(Command): self.distribution.data_files.append(item) try: - log.info("installing package data to %s" % self.bdist_dir) + log.info("installing package data to %s", self.bdist_dir) self.call_command('install_data', force=0, root=None) finally: self.distribution.data_files = old @@ -152,7 +152,7 @@ class bdist_egg(Command): self.run_command("egg_info") # We run install_lib before install_data, because some data hacks # pull their data path from the install_lib command. - log.info("installing library code to %s" % self.bdist_dir) + log.info("installing library code to %s", self.bdist_dir) instcmd = self.get_finalized_command('install') old_root = instcmd.root instcmd.root = None @@ -169,7 +169,7 @@ class bdist_egg(Command): pyfile = os.path.join(self.bdist_dir, strip_module(filename) + '.py') self.stubs.append(pyfile) - log.info("creating stub loader for %s" % ext_name) + log.info("creating stub loader for %s", ext_name) if not self.dry_run: write_stub(os.path.basename(ext_name), pyfile) to_compile.append(pyfile) @@ -186,14 +186,14 @@ class bdist_egg(Command): self.mkpath(egg_info) if self.distribution.scripts: script_dir = os.path.join(egg_info, 'scripts') - log.info("installing scripts to %s" % script_dir) + log.info("installing scripts to %s", script_dir) self.call_command('install_scripts', install_dir=script_dir, no_ep=1) self.copy_metadata_to(egg_info) native_libs = os.path.join(egg_info, "native_libs.txt") if all_outputs: - log.info("writing %s" % native_libs) + log.info("writing %s", native_libs) if not self.dry_run: ensure_directory(native_libs) libs_file = open(native_libs, 'wt') @@ -201,7 +201,7 @@ class bdist_egg(Command): libs_file.write('\n') libs_file.close() elif os.path.isfile(native_libs): - log.info("removing %s" % native_libs) + log.info("removing %s", native_libs) if not self.dry_run: os.unlink(native_libs) @@ -458,7 +458,7 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=True, p = path[len(base_dir) + 1:] if not dry_run: z.write(path, p) - log.debug("adding '%s'" % p) + log.debug("adding '%s'", p) compression = zipfile.ZIP_DEFLATED if compress else zipfile.ZIP_STORED if not dry_run: -- cgit v1.2.1 From 31bd37c6ac8de9e8c1bacebc2d8e1215df91eb96 Mon Sep 17 00:00:00 2001 From: stepshal Date: Tue, 18 Oct 2016 20:24:35 +0700 Subject: Fix quantity of blank lines. --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index cbea7537..8cd9dfef 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -429,10 +429,10 @@ def can_scan(): log.warn("Please ask the author to include a 'zip_safe'" " setting (either True or False) in the package's setup.py") + # Attribute names of options for commands that might need to be convinced to # install to the egg build directory - INSTALL_DIRECTORY_ATTRS = [ 'install_lib', 'install_dir', 'install_data', 'install_base' ] -- 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/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 8cd9dfef..ae344cd0 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -11,7 +11,7 @@ import os import textwrap import marshal -from setuptools.extern import six +import six from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint -- 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/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index ae344cd0..8cd9dfef 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -11,7 +11,7 @@ import os import textwrap import marshal -import six +from setuptools.extern import six from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint -- cgit v1.2.1 From 29688821b381268a0d59c0d26317d88ad518f966 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Wed, 21 Jun 2017 14:08:35 +0200 Subject: Sort file lists to generate reproducible zip files that do not differ depending on (random) filesystem order See https://reproducible-builds.org/ for why this matters. --- setuptools/command/bdist_egg.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 8cd9dfef..51755d52 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -38,6 +38,14 @@ def strip_module(filename): filename = filename[:-6] return filename +def sorted_walk(dir): + """Do os.walk in a reproducible way, + independent of indeterministic filesystem readdir order + """ + for base, dirs, files in os.walk(dir): + dirs.sort() + files.sort() + yield base, dirs, files def write_stub(resource, pyfile): _stub_template = textwrap.dedent(""" @@ -302,7 +310,7 @@ class bdist_egg(Command): ext_outputs = [] paths = {self.bdist_dir: ''} - for base, dirs, files in os.walk(self.bdist_dir): + for base, dirs, files in sorted_walk(self.bdist_dir): for filename in files: if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS: all_outputs.append(paths[base] + filename) @@ -329,7 +337,7 @@ NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" - walker = os.walk(egg_dir) + walker = sorted_walk(egg_dir) base, dirs, files = next(walker) if 'EGG-INFO' in dirs: dirs.remove('EGG-INFO') @@ -463,10 +471,10 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=True, compression = zipfile.ZIP_DEFLATED if compress else zipfile.ZIP_STORED if not dry_run: z = zipfile.ZipFile(zip_filename, mode, compression=compression) - for dirname, dirs, files in os.walk(base_dir): + for dirname, dirs, files in sorted_walk(base_dir): visit(z, dirname, files) z.close() else: - for dirname, dirs, files in os.walk(base_dir): + for dirname, dirs, files in sorted_walk(base_dir): visit(None, dirname, files) return zip_filename -- cgit v1.2.1 From ee33fa23dcdb7f9a0e89e2df3a50706b75678a36 Mon Sep 17 00:00:00 2001 From: Bibo Hao Date: Wed, 13 Sep 2017 11:47:12 +0800 Subject: python 3 bdist_egg --exclude-source-files __pycache__ issue --- setuptools/command/bdist_egg.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 51755d52..5bfc7ba2 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -8,6 +8,7 @@ from distutils import log from types import CodeType import sys import os +import re import textwrap import marshal @@ -238,6 +239,8 @@ class bdist_egg(Command): def zap_pyfiles(self): log.info("Removing .py files from temporary directory") + py3 = sys.version_info >= (3, 0) + re_pycache_file = re.compile('(.+)\.cpython-3\d(.pyc)$') for base, dirs, files in walk_egg(self.bdist_dir): for name in files: if name.endswith('.py'): @@ -245,6 +248,17 @@ class bdist_egg(Command): log.debug("Deleting %s", path) os.unlink(path) + if py3 and base.endswith('__pycache__'): + path_old = os.path.join(base, name) + + m = re_pycache_file.match(name) + path_new = os.path.join(base, os.pardir, m.group(1) + m.group(2)) + log.info("Renaming Python 3 .pyc file from [%s] to [%s]" % (path_old, path_new)) + if os.path.exists(path_new): + os.unlink(path_new) + os.rename(path_old, path_new) + + def zip_safe(self): safe = getattr(self.distribution, 'zip_safe', None) if safe is not None: -- cgit v1.2.1 From 0830232c2c700f09bbd39b8cddc2a0828399e7e8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 9 Nov 2017 19:23:29 -0500 Subject: Unconditionally rename __pycache__ files if they exist. --- setuptools/command/bdist_egg.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 5bfc7ba2..f52c40d1 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -239,7 +239,6 @@ class bdist_egg(Command): def zap_pyfiles(self): log.info("Removing .py files from temporary directory") - py3 = sys.version_info >= (3, 0) re_pycache_file = re.compile('(.+)\.cpython-3\d(.pyc)$') for base, dirs, files in walk_egg(self.bdist_dir): for name in files: @@ -248,12 +247,12 @@ class bdist_egg(Command): log.debug("Deleting %s", path) os.unlink(path) - if py3 and base.endswith('__pycache__'): + if base.endswith('__pycache__'): path_old = os.path.join(base, name) - + m = re_pycache_file.match(name) path_new = os.path.join(base, os.pardir, m.group(1) + m.group(2)) - log.info("Renaming Python 3 .pyc file from [%s] to [%s]" % (path_old, path_new)) + log.info("Renaming file from [%s] to [%s]" % (path_old, path_new)) if os.path.exists(path_new): os.unlink(path_new) os.rename(path_old, path_new) -- cgit v1.2.1 From 9a79433af7e66ee5c1f721a1803dad4873666e62 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 9 Nov 2017 19:30:56 -0500 Subject: Use named groups in the pattern --- setuptools/command/bdist_egg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index f52c40d1..14dd97d3 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -239,7 +239,6 @@ class bdist_egg(Command): def zap_pyfiles(self): log.info("Removing .py files from temporary directory") - re_pycache_file = re.compile('(.+)\.cpython-3\d(.pyc)$') for base, dirs, files in walk_egg(self.bdist_dir): for name in files: if name.endswith('.py'): @@ -250,8 +249,9 @@ class bdist_egg(Command): if base.endswith('__pycache__'): path_old = os.path.join(base, name) - m = re_pycache_file.match(name) - path_new = os.path.join(base, os.pardir, m.group(1) + m.group(2)) + pattern = r'(?P.+)\.(?P[^.]+)\.pyc' + m = re.match(pattern, name) + path_new = os.path.join(base, os.pardir, m.group('name') + '.pyc') log.info("Renaming file from [%s] to [%s]" % (path_old, path_new)) if os.path.exists(path_new): os.unlink(path_new) -- cgit v1.2.1 From 2676c5a277c5e571cdaeed64e5494315d5ec4c1f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 9 Nov 2017 19:34:54 -0500 Subject: Avoid check/act race condition --- setuptools/command/bdist_egg.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 14dd97d3..4e36c635 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -253,8 +253,10 @@ class bdist_egg(Command): m = re.match(pattern, name) path_new = os.path.join(base, os.pardir, m.group('name') + '.pyc') log.info("Renaming file from [%s] to [%s]" % (path_old, path_new)) - if os.path.exists(path_new): - os.unlink(path_new) + try: + os.remove(path_new) + except OSError: + pass os.rename(path_old, path_new) -- cgit v1.2.1 From 7874d4e0980265937b6957ba05805e00bacc0ed8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 9 Nov 2017 19:36:07 -0500 Subject: Re-use path --- setuptools/command/bdist_egg.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 4e36c635..5fdb62d9 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -241,13 +241,14 @@ class bdist_egg(Command): log.info("Removing .py files from temporary directory") for base, dirs, files in walk_egg(self.bdist_dir): for name in files: + path = os.path.join(base, name) + if name.endswith('.py'): - path = os.path.join(base, name) log.debug("Deleting %s", path) os.unlink(path) if base.endswith('__pycache__'): - path_old = os.path.join(base, name) + path_old = path pattern = r'(?P.+)\.(?P[^.]+)\.pyc' m = re.match(pattern, name) -- cgit v1.2.1 From 7bf15cb3c8a29545cc4869a4a1c52ac678eba1da Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Thu, 25 Jan 2018 10:27:04 +0100 Subject: fix Python 3.7 support - update scanning code to handle pyc header change - handle change to `Exception.__repr__` output --- setuptools/command/bdist_egg.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 5fdb62d9..d222c208 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -409,8 +409,10 @@ def scan_module(egg_dir, base, name, stubs): module = pkg + (pkg and '.' or '') + os.path.splitext(name)[0] if sys.version_info < (3, 3): skip = 8 # skip magic & date - else: + elif sys.version_info < (3, 7): skip = 12 # skip magic & date & file size + else: + skip = 16 # skip magic & reserved? & date & file size f = open(filename, 'rb') f.read(skip) code = marshal.load(f) -- cgit v1.2.1 From d916fa24c1eafb839ab18cc09c4c4350e183ab83 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 5 Feb 2018 10:29:14 -0500 Subject: Feed the hobgoblins (delint). --- setuptools/command/bdist_egg.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index d222c208..423b8187 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -39,6 +39,7 @@ def strip_module(filename): filename = filename[:-6] return filename + def sorted_walk(dir): """Do os.walk in a reproducible way, independent of indeterministic filesystem readdir order @@ -48,6 +49,7 @@ def sorted_walk(dir): files.sort() yield base, dirs, files + def write_stub(resource, pyfile): _stub_template = textwrap.dedent(""" def __bootstrap__(): @@ -252,15 +254,17 @@ class bdist_egg(Command): pattern = r'(?P.+)\.(?P[^.]+)\.pyc' m = re.match(pattern, name) - path_new = os.path.join(base, os.pardir, m.group('name') + '.pyc') - log.info("Renaming file from [%s] to [%s]" % (path_old, path_new)) + path_new = os.path.join( + base, os.pardir, m.group('name') + '.pyc') + log.info( + "Renaming file from [%s] to [%s]" + % (path_old, path_new)) try: os.remove(path_new) except OSError: pass os.rename(path_old, path_new) - def zip_safe(self): safe = getattr(self.distribution, 'zip_safe', None) if safe is not None: @@ -412,7 +416,7 @@ def scan_module(egg_dir, base, name, stubs): elif sys.version_info < (3, 7): skip = 12 # skip magic & date & file size else: - skip = 16 # skip magic & reserved? & date & file size + skip = 16 # skip magic & reserved? & date & file size f = open(filename, 'rb') f.read(skip) code = marshal.load(f) -- cgit v1.2.1 From 7392f01ffced3acfdef25b0b2d55cefdc6ee468a Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 26 Apr 2018 18:06:09 +0300 Subject: Drop support for EOL Python 3.3 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 423b8187..14530729 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -411,7 +411,7 @@ def scan_module(egg_dir, base, name, stubs): return True # Extension module pkg = base[len(egg_dir) + 1:].replace(os.sep, '.') module = pkg + (pkg and '.' or '') + os.path.splitext(name)[0] - if sys.version_info < (3, 3): + if sys.version_info.major == 2: skip = 8 # skip magic & date elif sys.version_info < (3, 7): skip = 12 # skip magic & date & file size -- cgit v1.2.1 From dc9fcbd5ef343321cf29ce1e34f454dadeb59dd2 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Tue, 10 Jul 2018 11:16:04 -0400 Subject: Switch over to using six.PY{2,3} when possible --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 14530729..9f8df917 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -411,7 +411,7 @@ def scan_module(egg_dir, base, name, stubs): return True # Extension module pkg = base[len(egg_dir) + 1:].replace(os.sep, '.') module = pkg + (pkg and '.' or '') + os.path.splitext(name)[0] - if sys.version_info.major == 2: + if six.PY2: skip = 8 # skip magic & date elif sys.version_info < (3, 7): skip = 12 # skip magic & date & file size -- cgit v1.2.1 From 314386fd5d4d0e925960f3e9982102095b9579c9 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Wed, 15 May 2019 12:20:25 +0200 Subject: Deprecated Eggsecutable Scripts Closes: #1557 --- setuptools/command/bdist_egg.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 9f8df917..ae44eaa2 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -11,13 +11,14 @@ import os import re import textwrap import marshal +import warnings from setuptools.extern import six from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint from setuptools.extension import Library -from setuptools import Command +from setuptools import Command, SetuptoolsDeprecationWarning try: # Python 2.7 or >=3.2 @@ -278,6 +279,12 @@ class bdist_egg(Command): if ep is None: return 'w' # not an eggsecutable, do it the usual way. + warnings.warn( + "Eggsecutables are deprecated and will be removed in a future " + "version.", + SetuptoolsDeprecationWarning + ) + if not ep.attrs or ep.extras: raise DistutilsSetupError( "eggsecutable entry point (%r) cannot have 'extras' " -- cgit v1.2.1 From 43add1d3f5138e38adc4940647cc6eae94fb6123 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 17 Aug 2019 19:14:48 -0700 Subject: Fixes for python3.10 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 9f8df917..98470f17 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -284,7 +284,7 @@ class bdist_egg(Command): "or refer to a module" % (ep,) ) - pyver = sys.version[:3] + pyver = '{}.{}'.format(*sys.version_info) pkg = ep.module_name full = '.'.join(ep.attrs) base = ep.attrs[0] -- cgit v1.2.1 From 4516d87036f971a4c98900301b6354c0aae73dc8 Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Sun, 21 Jun 2020 16:39:53 -0600 Subject: Use importlib instead of imp in __bootstrap__ functions --- setuptools/command/bdist_egg.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 1b28d4c9..e94fe252 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -55,10 +55,11 @@ def write_stub(resource, pyfile): _stub_template = textwrap.dedent(""" def __bootstrap__(): global __bootstrap__, __loader__, __file__ - import sys, pkg_resources, imp + import sys, pkg_resources + from importlib.machinery import ExtensionFileLoader __file__ = pkg_resources.resource_filename(__name__, %r) __loader__ = None; del __bootstrap__, __loader__ - imp.load_dynamic(__name__,__file__) + ExtensionFileLoader(__name__,__file__).exec_module() __bootstrap__() """).lstrip() with open(pyfile, 'w') as f: -- cgit v1.2.1 From 8b4ce333c093f459698c0545550269a393387c5f Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Sat, 11 Jul 2020 12:51:48 -0600 Subject: Change exec_module to load_module Fixes #2246 --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index e94fe252..7af3165c 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -59,7 +59,7 @@ def write_stub(resource, pyfile): from importlib.machinery import ExtensionFileLoader __file__ = pkg_resources.resource_filename(__name__, %r) __loader__ = None; del __bootstrap__, __loader__ - ExtensionFileLoader(__name__,__file__).exec_module() + ExtensionFileLoader(__name__,__file__).load_module() __bootstrap__() """).lstrip() with open(pyfile, 'w') as f: -- cgit v1.2.1 From 33c9d86af4dc1df04cf1b38a0102fe7e121173ec Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 10 Aug 2020 21:10:46 +1000 Subject: Change load_module to exec_module --- setuptools/command/bdist_egg.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 7af3165c..4be15457 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -55,11 +55,12 @@ def write_stub(resource, pyfile): _stub_template = textwrap.dedent(""" def __bootstrap__(): global __bootstrap__, __loader__, __file__ - import sys, pkg_resources - from importlib.machinery import ExtensionFileLoader + import sys, pkg_resources, importlib.util __file__ = pkg_resources.resource_filename(__name__, %r) __loader__ = None; del __bootstrap__, __loader__ - ExtensionFileLoader(__name__,__file__).load_module() + spec = importlib.util.spec_from_file_location(__name__,__file__) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) __bootstrap__() """).lstrip() with open(pyfile, 'w') as f: -- 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/bdist_egg.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 4be15457..a88efb45 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -13,24 +13,16 @@ import textwrap import marshal import warnings -from setuptools.extern import six - from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint from setuptools.extension import Library from setuptools import Command, SetuptoolsDeprecationWarning -try: - # Python 2.7 or >=3.2 - from sysconfig import get_path, get_python_version +from sysconfig import get_path, get_python_version - def _get_purelib(): - return get_path("purelib") -except ImportError: - from distutils.sysconfig import get_python_lib, get_python_version - def _get_purelib(): - return get_python_lib(False) +def _get_purelib(): + return get_path("purelib") def strip_module(filename): @@ -420,9 +412,7 @@ def scan_module(egg_dir, base, name, stubs): return True # Extension module pkg = base[len(egg_dir) + 1:].replace(os.sep, '.') module = pkg + (pkg and '.' or '') + os.path.splitext(name)[0] - if six.PY2: - skip = 8 # skip magic & date - elif sys.version_info < (3, 7): + if sys.version_info < (3, 7): skip = 12 # skip magic & date & file size else: skip = 16 # skip magic & reserved? & date & file size @@ -453,7 +443,7 @@ def iter_symbols(code): for name in code.co_names: yield name for const in code.co_consts: - if isinstance(const, six.string_types): + if isinstance(const, str): yield const elif isinstance(const, CodeType): for name in iter_symbols(const): -- cgit v1.2.1 From fc891f5cf6d93ad533e2afb5e15a2952408ab358 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Thu, 31 Dec 2020 13:08:18 +0100 Subject: Apply noqa C901 comments to overly complex code --- setuptools/command/bdist_egg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index a88efb45..206f2419 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -153,7 +153,7 @@ class bdist_egg(Command): self.run_command(cmdname) return cmd - def run(self): + def run(self): # noqa: C901 # is too complex (14) # FIXME # Generate metadata first self.run_command("egg_info") # We run install_lib before install_data, because some data hacks -- cgit v1.2.1 From fa81391fe65fa727f79f1be73f058e83ffe97193 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Jan 2021 21:13:41 -0500 Subject: Remove eggsecutable --- setuptools/command/bdist_egg.py | 49 ++--------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 206f2419..e6b1609f 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -2,7 +2,6 @@ Build .egg distributions""" -from distutils.errors import DistutilsSetupError from distutils.dir_util import remove_tree, mkpath from distutils import log from types import CodeType @@ -11,12 +10,10 @@ import os import re import textwrap import marshal -import warnings from pkg_resources import get_build_platform, Distribution, ensure_directory -from pkg_resources import EntryPoint from setuptools.extension import Library -from setuptools import Command, SetuptoolsDeprecationWarning +from setuptools import Command from sysconfig import get_path, get_python_version @@ -268,49 +265,7 @@ class bdist_egg(Command): return analyze_egg(self.bdist_dir, self.stubs) def gen_header(self): - epm = EntryPoint.parse_map(self.distribution.entry_points or '') - ep = epm.get('setuptools.installation', {}).get('eggsecutable') - if ep is None: - return 'w' # not an eggsecutable, do it the usual way. - - warnings.warn( - "Eggsecutables are deprecated and will be removed in a future " - "version.", - SetuptoolsDeprecationWarning - ) - - if not ep.attrs or ep.extras: - raise DistutilsSetupError( - "eggsecutable entry point (%r) cannot have 'extras' " - "or refer to a module" % (ep,) - ) - - pyver = '{}.{}'.format(*sys.version_info) - pkg = ep.module_name - full = '.'.join(ep.attrs) - base = ep.attrs[0] - basename = os.path.basename(self.egg_output) - - header = ( - "#!/bin/sh\n" - 'if [ `basename $0` = "%(basename)s" ]\n' - 'then exec python%(pyver)s -c "' - "import sys, os; sys.path.insert(0, os.path.abspath('$0')); " - "from %(pkg)s import %(base)s; sys.exit(%(full)s())" - '" "$@"\n' - 'else\n' - ' echo $0 is not the correct name for this egg file.\n' - ' echo Please rename it back to %(basename)s and try again.\n' - ' exec false\n' - 'fi\n' - ) % locals() - - if not self.dry_run: - mkpath(os.path.dirname(self.egg_output), dry_run=self.dry_run) - f = open(self.egg_output, 'w') - f.write(header) - f.close() - return 'a' + return 'w' def copy_metadata_to(self, target_dir): "Copy metadata (egg info) to the target_dir" -- cgit v1.2.1