Commit 7c4938d5 authored by PJ Eby's avatar PJ Eby

chmod/test cleanups and Jython compatibility (backport from trunk)

--HG--
branch : setuptools-0.6
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4060062
parent ce75692a
......@@ -1241,6 +1241,10 @@ Release Notes/Change History
* Fixed not picking up dependency links from recursive dependencies.
* Only make ``.py``, ``.dll`` and ``.so`` files executable when unpacking eggs
* Changes for Jython compatibility
0.6c7
* ``ftp:`` download URLs now work correctly.
......
......@@ -2618,6 +2618,8 @@ Release Notes/Change History
* Updated Pyrex support to work with Pyrex 0.9.6 and higher.
* Minor changes for Jython compatibility
0.6c7
* Fixed ``distutils.filelist.findall()`` crashing on broken symlinks, and
``egg_info`` command failing on new, uncommitted SVN directories.
......
......@@ -382,7 +382,7 @@ def analyze_egg(egg_dir, stubs):
for flag,fn in safety_flags.items():
if os.path.exists(os.path.join(egg_dir,'EGG-INFO',fn)):
return flag
if not can_scan(): return False
safe = True
for base, dirs, files in walk_egg(egg_dir):
for name in files:
......@@ -448,6 +448,47 @@ def iter_symbols(code):
elif isinstance(const,CodeType):
for name in iter_symbols(const):
yield name
def can_scan():
if not sys.platform.startswith('java') and sys.platform != 'cli':
# CPython, PyPy, etc.
return True
log.warn("Unable to analyze compiled code on this platform.")
log.warn("Please ask the author to include a 'zip_safe'"
" setting (either True or False) in the package's setup.py")
# Attribute names of options for commands that might need to be convinced to
# install to the egg build directory
......
......@@ -608,10 +608,10 @@ Please make the appropriate changes for your system and try again.
f = open(target,"w"+mode)
f.write(contents)
f.close()
try:
os.chmod(target,0755)
except (AttributeError, os.error):
pass
chmod(target,0755)
def install_eggs(self, spec, dist_filename, tmpdir):
# .egg dirs or files are already built, so just return them
......@@ -988,18 +988,18 @@ See the setuptools documentation for the "develop" command for more info.
def pf(src,dst):
if dst.endswith('.py') and not src.startswith('EGG-INFO/'):
to_compile.append(dst)
self.unpack_progress(src,dst); to_chmod.append(dst)
to_chmod.append(dst)
elif dst.endswith('.dll') or dst.endswith('.so'):
to_chmod.append(dst)
self.unpack_progress(src,dst)
return not self.dry_run and dst or None
unpack_archive(egg_path, destination, pf)
self.byte_compile(to_compile)
if not self.dry_run:
flags = stat.S_IXGRP|stat.S_IXGRP
for f in to_chmod:
mode = ((os.stat(f)[stat.ST_MODE]) | 0555) & 07777
log.debug("changing mode of %s to %o", f, mode)
os.chmod(f, mode)
mode = ((os.stat(f)[stat.ST_MODE]) | 0555) & 07755
chmod(f, mode)
def byte_compile(self, to_compile):
from distutils.util import byte_compile
......@@ -1435,7 +1435,7 @@ def get_script_header(script_text, executable=sys_executable, wininst=False):
def auto_chmod(func, arg, exc):
if func is os.remove and os.name=='nt':
os.chmod(arg, stat.S_IWRITE)
chmod(arg, stat.S_IWRITE)
return func(arg)
exc = sys.exc_info()
raise exc[0], (exc[1][0], exc[1][1] + (" %s %s" % (func,arg)))
......@@ -1530,18 +1530,18 @@ def is_python_script(script_text, filename):
return False # Not any Python I can recognize
try:
from os import chmod as _chmod
except ImportError:
# Jython compatibility
def _chmod(*args): pass
def chmod(path, mode):
log.debug("changing mode of %s to %o", path, mode)
try:
_chmod(path, mode)
except os.error, e:
log.debug("chmod failed: %s", e)
......
from distutils.command.install_scripts import install_scripts \
as _install_scripts
from easy_install import get_script_args, sys_executable
from easy_install import get_script_args, sys_executable, chmod
from pkg_resources import Distribution, PathMetadata, ensure_directory
import os
from distutils import log
......@@ -50,10 +50,10 @@ class install_scripts(_install_scripts):
f = open(target,"w"+mode)
f.write(contents)
f.close()
try:
os.chmod(target,0755)
except (AttributeError, os.error):
pass
chmod(target,0755)
......
......@@ -2,7 +2,7 @@
"""
# More would be better!
import os, shutil, tempfile, unittest
import os, shutil, tempfile, unittest, urllib2
import pkg_resources
import setuptools.package_index
......@@ -12,8 +12,8 @@ class TestPackageIndex(unittest.TestCase):
index = setuptools.package_index.PackageIndex()
url = 'http://127.0.0.1/nonesuch/test_package_index'
try:
index.open_url(url)
v = index.open_url(url)
except Exception, v:
self.assert_(url in str(v))
else:
self.assert_(False)
self.assert_(isinstance(v,urllib2.HTTPError))
......@@ -39,8 +39,6 @@ class DistroTests(TestCase):
# But only 1 package
self.assertEqual(list(ad), ['foopkg'])
# Distributions sort by version
self.assertEqual(
[dist.version for dist in ad['FooPkg']], ['1.4','1.3-1','1.2']
......@@ -255,14 +253,15 @@ class EntryPointTests(TestCase):
else: raise AssertionError("Should've been bad", ep)
def checkSubMap(self, m):
self.assertEqual(str(m),
"{'feature2': EntryPoint.parse("
"'feature2 = another.module:SomeClass [extra1,extra2]'), "
"'feature3': EntryPoint.parse('feature3 = this.module [something]'), "
"'feature1': EntryPoint.parse("
"'feature1 = somemodule:somefunction')}"
)
self.assertEqual(len(m), len(self.submap_expect))
for key, ep in self.submap_expect.iteritems():
self.assertEqual(repr(m.get(key)), repr(ep))
submap_expect = dict(
feature1=EntryPoint('feature1', 'somemodule', ['somefunction']),
feature2=EntryPoint('feature2', 'another.module', ['SomeClass'], ['extra1','extra2']),
feature3=EntryPoint('feature3', 'this.module', extras=['something'])
)
submap_str = """
# define features for blah blah
feature1 = somemodule:somefunction
......@@ -286,7 +285,6 @@ class EntryPointTests(TestCase):
self.assertRaises(ValueError, EntryPoint.parse_map, ["[xyz]", "[xyz]"])
self.assertRaises(ValueError, EntryPoint.parse_map, self.submap_str)
class RequirementsTests(TestCase):
def testBasics(self):
......
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