Commit 207ddcba authored by PJ Eby's avatar PJ Eby

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
parent 13e9b3d6
......@@ -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"""
......
......@@ -637,6 +637,7 @@ class easy_install(Command):
self.exe_to_egg(dist_filename, egg_tmp)
# Write EGG-INFO/PKG-INFO
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'):
......@@ -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,15 +692,15 @@ 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')
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"""
......
......@@ -283,7 +283,6 @@ class manifest_maker(sdist):
def write_pkg_info(cmd, basename, filename):
......@@ -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)
......
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