Commit b9c686a4 authored by PJ Eby's avatar PJ Eby

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
parent f09fb93d
......@@ -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
......
......@@ -508,10 +508,12 @@ class easy_install(Command):
# Convert the .exe to an unpacked egg
egg_path = dist.path = os.path.join(tmpdir, dist.egg_name()+'.egg')
egg_tmp = egg_path+'.tmp'
pkg_inf = os.path.join(egg_tmp, 'EGG-INFO', 'PKG-INFO')
ensure_directory(pkg_inf) # make sure EGG-INFO dir exists
self.exe_to_egg(dist_filename, egg_tmp)
# Write EGG-INFO/PKG-INFO
pkg_inf = os.path.join(egg_tmp, 'EGG-INFO', 'PKG-INFO')
f = open(pkg_inf,'w')
f.write('Metadata-Version: 1.0\n')
for k,v in cfg.items('metadata'):
......@@ -529,8 +531,6 @@ class easy_install(Command):
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
......@@ -575,9 +575,9 @@ class easy_install(Command):
for name in 'top_level','native_libs':
if locals()[name]:
txt = os.path.join(egg_tmp, 'EGG-INFO', name+'.txt')
ensure_directory(txt)
open(txt,'w').write('\n'.join(locals()[name])+'\n')
def check_conflicts(self, dist):
"""Verify that there are no conflicting "old-style" packages"""
......@@ -708,7 +708,7 @@ PYTHONPATH, or by being added to sys.path by your code.)
if self.dry_run:
args.insert(0,'-n')
dist_dir = tempfile.mkdtemp(prefix='egg-dist-tmp-', dir=setup_base)
dist_dir = tempfile.mkdtemp(prefix='egg-dist-tmp-', dir=os.path.dirname(setup_script))
try:
args.append(dist_dir)
log.info(
......@@ -877,13 +877,13 @@ def extract_wininst_cfg(dist_filename):
import struct, StringIO, ConfigParser
tag, cfglen, bmlen = struct.unpack("<iii",f.read(12))
if tag<>0x1234567A:
if tag not in (0x1234567A, 0x1234567B):
return None # not a valid tag
f.seek(prepended-(12+cfglen+bmlen))
cfg = ConfigParser.RawConfigParser({'version':'','target_version':''})
try:
cfg.readfp(StringIO.StringIO(f.read(cfglen)))
cfg.readfp(StringIO.StringIO(f.read(cfglen).split(chr(0),1)[0]))
except ConfigParser.Error:
return None
if not cfg.has_section('metadata') or not cfg.has_section('Setup'):
......
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