Commit 4d159b9c authored by Jason R. Coombs's avatar Jason R. Coombs

Update bdist_egg for style

parent 90f4ab45
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
Build .egg distributions""" Build .egg distributions"""
# This module should be kept compatible with Python 2.3 # 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 setuptools import Command
from distutils.dir_util import remove_tree, mkpath from distutils.dir_util import remove_tree, mkpath
try: try:
...@@ -33,22 +35,21 @@ def strip_module(filename): ...@@ -33,22 +35,21 @@ def strip_module(filename):
def write_stub(resource, pyfile): def write_stub(resource, pyfile):
f = open(pyfile,'w') f = open(pyfile,'w')
f.write('\n'.join([ f.write(
"def __bootstrap__():", '\n'.join([
" global __bootstrap__, __loader__, __file__", "def __bootstrap__():",
" import sys, pkg_resources, imp", " global __bootstrap__, __loader__, __file__",
" __file__ = pkg_resources.resource_filename(__name__,%r)" " import sys, pkg_resources, imp",
% resource, " __file__ = pkg_resources.resource_filename(__name__,%r)"
" __loader__ = None; del __bootstrap__, __loader__", % resource,
" imp.load_dynamic(__name__,__file__)", " __loader__ = None; del __bootstrap__, __loader__",
"__bootstrap__()", " imp.load_dynamic(__name__,__file__)",
"" # terminal \n "__bootstrap__()",
])) "" # terminal \n
]))
f.close() f.close()
class bdist_egg(Command): class bdist_egg(Command):
description = "create an \"egg\" distribution" description = "create an \"egg\" distribution"
...@@ -56,41 +57,24 @@ class bdist_egg(Command): ...@@ -56,41 +57,24 @@ class bdist_egg(Command):
user_options = [ user_options = [
('bdist-dir=', 'b', ('bdist-dir=', 'b',
"temporary directory for creating the distribution"), "temporary directory for creating the distribution"),
('plat-name=', 'p', ('plat-name=', 'p', "platform name to embed in generated filenames "
"platform name to embed in generated filenames " "(default: %s)" % get_build_platform()),
"(default: %s)" % get_build_platform()),
('exclude-source-files', None, ('exclude-source-files', None,
"remove all .py files from the generated egg"), "remove all .py files from the generated egg"),
('keep-temp', 'k', ('keep-temp', 'k',
"keep the pseudo-installation tree around after " + "keep the pseudo-installation tree around after " +
"creating the distribution archive"), "creating the distribution archive"),
('dist-dir=', 'd', ('dist-dir=', 'd',
"directory to put final built distributions in"), "directory to put final built distributions in"),
('skip-build', None, ('skip-build', None,
"skip rebuilding everything (for testing/debugging)"), "skip rebuilding everything (for testing/debugging)"),
] ]
boolean_options = [ boolean_options = [
'keep-temp', 'skip-build', 'exclude-source-files' 'keep-temp', 'skip-build', 'exclude-source-files'
] ]
def initialize_options(self):
def initialize_options (self):
self.bdist_dir = None self.bdist_dir = None
self.plat_name = None self.plat_name = None
self.keep_temp = 0 self.keep_temp = 0
...@@ -99,7 +83,6 @@ class bdist_egg(Command): ...@@ -99,7 +83,6 @@ class bdist_egg(Command):
self.egg_output = None self.egg_output = None
self.exclude_source_files = None self.exclude_source_files = None
def finalize_options(self): def finalize_options(self):
ei_cmd = 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 self.egg_info = ei_cmd.egg_info
...@@ -124,13 +107,6 @@ class bdist_egg(Command): ...@@ -124,13 +107,6 @@ class bdist_egg(Command):
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): def do_install_data(self):
# Hack for packages that install data to install's --install-lib # Hack for packages that install data to install's --install-lib
self.get_finalized_command('install').install_lib = self.bdist_dir self.get_finalized_command('install').install_lib = self.bdist_dir
...@@ -156,11 +132,9 @@ class bdist_egg(Command): ...@@ -156,11 +132,9 @@ class bdist_egg(Command):
finally: finally:
self.distribution.data_files = old self.distribution.data_files = old
def get_outputs(self): def get_outputs(self):
return [self.egg_output] return [self.egg_output]
def call_command(self,cmdname,**kw): def call_command(self,cmdname,**kw):
"""Invoke reinitialized command `cmdname` with keyword args""" """Invoke reinitialized command `cmdname` with keyword args"""
for dirname in INSTALL_DIRECTORY_ATTRS: for dirname in INSTALL_DIRECTORY_ATTRS:
...@@ -171,7 +145,6 @@ class bdist_egg(Command): ...@@ -171,7 +145,6 @@ class bdist_egg(Command):
self.run_command(cmdname) self.run_command(cmdname)
return cmd return cmd
def run(self): def run(self):
# Generate metadata first # Generate metadata first
self.run_command("egg_info") self.run_command("egg_info")
...@@ -179,7 +152,8 @@ class bdist_egg(Command): ...@@ -179,7 +152,8 @@ class bdist_egg(Command):
# pull their data path from the install_lib command. # 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') 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: if self.distribution.has_c_libraries() and not self.skip_build:
self.run_command('build_clib') self.run_command('build_clib')
cmd = self.call_command('install_lib', warn_dir=0) cmd = self.call_command('install_lib', warn_dir=0)
...@@ -242,7 +216,7 @@ class bdist_egg(Command): ...@@ -242,7 +216,7 @@ class bdist_egg(Command):
# Make the archive # Make the archive
make_zipfile(self.egg_output, archive_root, verbose=self.verbose, 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: if not self.keep_temp:
remove_tree(self.bdist_dir, dry_run=self.dry_run) remove_tree(self.bdist_dir, dry_run=self.dry_run)
...@@ -250,9 +224,6 @@ class bdist_egg(Command): ...@@ -250,9 +224,6 @@ class bdist_egg(Command):
getattr(self.distribution,'dist_files',[]).append( getattr(self.distribution,'dist_files',[]).append(
('bdist_egg',get_python_version(),self.egg_output)) ('bdist_egg',get_python_version(),self.egg_output))
def zap_pyfiles(self): def zap_pyfiles(self):
log.info("Removing .py files from temporary directory") 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):
...@@ -269,8 +240,6 @@ class bdist_egg(Command): ...@@ -269,8 +240,6 @@ class bdist_egg(Command):
log.warn("zip_safe flag not set; analyzing archive contents...") log.warn("zip_safe flag not set; analyzing archive contents...")
return analyze_egg(self.bdist_dir, self.stubs) return analyze_egg(self.bdist_dir, self.stubs)
def gen_header(self): def gen_header(self):
epm = EntryPoint.parse_map(self.distribution.entry_points or '') epm = EntryPoint.parse_map(self.distribution.entry_points or '')
ep = epm.get('setuptools.installation',{}).get('eggsecutable') ep = epm.get('setuptools.installation',{}).get('eggsecutable')
...@@ -311,7 +280,6 @@ class bdist_egg(Command): ...@@ -311,7 +280,6 @@ class bdist_egg(Command):
f.close() f.close()
return 'a' return 'a'
def copy_metadata_to(self, target_dir): def copy_metadata_to(self, target_dir):
"Copy metadata (egg info) to the target_dir" "Copy metadata (egg info) to the target_dir"
# normalize the path (so that a forward-slash in egg_info will # normalize the path (so that a forward-slash in egg_info will
...@@ -355,8 +323,6 @@ class bdist_egg(Command): ...@@ -355,8 +323,6 @@ class bdist_egg(Command):
NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split())
def walk_egg(egg_dir): def walk_egg(egg_dir):
"""Walk an unpacked egg's contents, skipping the metadata directory""" """Walk an unpacked egg's contents, skipping the metadata directory"""
walker = os.walk(egg_dir) walker = os.walk(egg_dir)
...@@ -391,7 +357,9 @@ def write_safety_flag(egg_dir, safe): ...@@ -391,7 +357,9 @@ def write_safety_flag(egg_dir, safe):
if safe is None or bool(safe) != flag: if safe is None or bool(safe) != flag:
os.unlink(fn) os.unlink(fn)
elif safe is not None and bool(safe)==flag: 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 = { safety_flags = {
True: 'zip-safe', True: 'zip-safe',
...@@ -410,8 +378,10 @@ def scan_module(egg_dir, base, name, stubs): ...@@ -410,8 +378,10 @@ def scan_module(egg_dir, base, name, stubs):
skip = 8 # skip magic & date skip = 8 # skip magic & date
else: else:
skip = 12 # skip magic & date & file size skip = 12 # skip magic & date & file size
f = open(filename,'rb'); f.read(skip) f = open(filename,'rb')
code = marshal.load(f); f.close() f.read(skip)
code = marshal.load(f)
f.close()
safe = True safe = True
symbols = dict.fromkeys(iter_symbols(code)) symbols = dict.fromkeys(iter_symbols(code))
for bad in ['__file__', '__path__']: for bad in ['__file__', '__path__']:
...@@ -451,39 +421,6 @@ def can_scan(): ...@@ -451,39 +421,6 @@ def can_scan():
log.warn("Please ask the author to include a 'zip_safe'" log.warn("Please ask the author to include a 'zip_safe'"
" setting (either True or False) in the package's setup.py") " setting (either True or False) in the package's setup.py")
# Attribute names of options for commands that might need to be convinced to # Attribute names of options for commands that might need to be convinced to
# install to the egg build directory # install to the egg build directory
...@@ -492,8 +429,7 @@ INSTALL_DIRECTORY_ATTRS = [ ...@@ -492,8 +429,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=None,
mode='w' mode='w'):
):
"""Create a zip file from all the files under 'base_dir'. The output """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" zip file will be named 'base_dir' + ".zip". Uses either the "zipfile"
Python module (if available) or the InfoZIP "zip" utility (if installed 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, ...@@ -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): for dirname, dirs, files in os.walk(base_dir):
visit(None, dirname, files) visit(None, dirname, files)
return zip_filename return zip_filename
#
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment