[Python-checkins] python/nondist/sandbox/setuptools/setuptools/command bdist_egg.py, 1.26, 1.27 easy_install.py, 1.8, 1.9

pje@users.sourceforge.net pje at users.sourceforge.net
Wed Jul 13 01:43:24 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20931/setuptools/command

Modified Files:
	bdist_egg.py easy_install.py 
Log Message:
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.


Index: bdist_egg.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/bdist_egg.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- bdist_egg.py	11 Jul 2005 04:12:48 -0000	1.26
+++ bdist_egg.py	12 Jul 2005 23:43:21 -0000	1.27
@@ -332,14 +332,11 @@
     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 @@
         ]:
             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 @@
             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
 

Index: easy_install.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/easy_install.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- easy_install.py	11 Jul 2005 04:12:48 -0000	1.8
+++ easy_install.py	12 Jul 2005 23:43:22 -0000	1.9
@@ -508,10 +508,12 @@
         # 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 @@
         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 @@
         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 @@
         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 @@
 
         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'):



More information about the Python-checkins mailing list