aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools
diff options
context:
space:
mode:
authorPJ Eby <distutils-sig@python.org>2005-12-14 20:49:36 +0000
committerPJ Eby <distutils-sig@python.org>2005-12-14 20:49:36 +0000
commit207ddcbad2db42f7f94099ab501ab46351e56f4d (patch)
tree05f90aa9c61a5414411adcca818bfdf15d57d2be /setuptools
parent13e9b3d6cbdc9c7a8bda76a7d7029e790c02507b (diff)
downloadexternal_python_setuptools-207ddcbad2db42f7f94099ab501ab46351e56f4d.tar.gz
external_python_setuptools-207ddcbad2db42f7f94099ab501ab46351e56f4d.tar.bz2
external_python_setuptools-207ddcbad2db42f7f94099ab501ab46351e56f4d.zip
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
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/command/bdist_egg.py42
-rwxr-xr-xsetuptools/command/easy_install.py32
-rwxr-xr-xsetuptools/command/egg_info.py7
3 files changed, 40 insertions, 41 deletions
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"""
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 20bdbe89..c09e597b 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -145,7 +145,7 @@ class easy_install(Command):
site_dirs = [
os.path.expanduser(s.strip()) for s in self.site_dirs.split(',')
]
- for d in site_dirs:
+ for d in site_dirs:
if not os.path.isdir(d):
log.warn("%s (in --site-dirs) does not exist", d)
elif normalize_path(d) not in normpath:
@@ -637,12 +637,13 @@ class easy_install(Command):
self.exe_to_egg(dist_filename, egg_tmp)
# Write EGG-INFO/PKG-INFO
- f = open(pkg_inf,'w')
- f.write('Metadata-Version: 1.0\n')
- for k,v in cfg.items('metadata'):
- if k<>'target_version':
- f.write('%s: %s\n' % (k.replace('_','-').title(), v))
- f.close()
+ if not os.path.exists(pkg_inf):
+ f = open(pkg_inf,'w')
+ f.write('Metadata-Version: 1.0\n')
+ for k,v in cfg.items('metadata'):
+ if k<>'target_version':
+ f.write('%s: %s\n' % (k.replace('_','-').title(), v))
+ f.close()
# Build .egg file from tmpdir
bdist_egg.make_zipfile(
@@ -653,7 +654,6 @@ class easy_install(Command):
# install the .egg
return self.install_egg(egg_path, tmpdir)
-
def exe_to_egg(self, dist_filename, egg_tmp):
"""Extract a bdist_wininst to the directories an egg would use"""
# Check for .pth file and set up prefix translations
@@ -692,14 +692,14 @@ class easy_install(Command):
bdist_egg.write_stub(resource, pyfile)
self.byte_compile(to_compile) # compile .py's
- bdist_egg.write_safety_flag(egg_tmp,
+ bdist_egg.write_safety_flag(os.path.join(egg_tmp,'EGG-INFO'),
bdist_egg.analyze_egg(egg_tmp, stubs)) # write zip-safety flag
for name in 'top_level','native_libs':
if locals()[name]:
txt = os.path.join(egg_tmp, 'EGG-INFO', name+'.txt')
- open(txt,'w').write('\n'.join(locals()[name])+'\n')
-
+ if not os.path.exists(txt):
+ open(txt,'w').write('\n'.join(locals()[name])+'\n')
def check_conflicts(self, dist):
"""Verify that there are no conflicting "old-style" packages"""
@@ -1076,10 +1076,12 @@ def get_exe_prefixes(exe_filename):
try:
for info in z.infolist():
name = info.filename
- if not name.endswith('.pth'):
- continue
parts = name.split('/')
- if len(parts)<>2:
+ if len(parts)==3 and parts[2]=='PKG-INFO':
+ if parts[1].endswith('.egg-info'):
+ prefixes.insert(0,('/'.join(parts[:2]), 'EGG-INFO/'))
+ break
+ if len(parts)<>2 or not name.endswith('.pth'):
continue
if parts[0] in ('PURELIB','PLATLIB'):
pth = z.read(name).strip()
@@ -1103,8 +1105,6 @@ def parse_requirement_arg(spec):
-
-
class PthDistributions(Environment):
"""A .pth file with Distribution paths in it"""
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index 2879d5da..1c5ed53a 100755
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -285,7 +285,6 @@ class manifest_maker(sdist):
-
def write_pkg_info(cmd, basename, filename):
log.info("writing %s", filename)
if not cmd.dry_run:
@@ -299,6 +298,9 @@ def write_pkg_info(cmd, basename, filename):
finally:
metadata.name, metadata.version = oldname, oldver
+ safe = getattr(cmd.distribution,'zip_safe',None)
+ import bdist_egg; bdist_egg.write_safety_flag(cmd.egg_info, safe)
+
def warn_depends_obsolete(cmd, basename, filename):
if os.path.exists(filename):
log.warn(
@@ -324,9 +326,6 @@ def write_toplevel_names(cmd, basename, filename):
-
-
-
def write_arg(cmd, basename, filename):
argname = os.path.splitext(basename)[0]
value = getattr(cmd.distribution, argname, None)