[Checkins] SVN: zc.buildout/branches/regebro-python3/ dev.py now runs under Python 2.4 and 2.5 as well.
Lennart Regebro
regebro at gmail.com
Sun Nov 21 10:11:31 EST 2010
Log message for revision 118517:
dev.py now runs under Python 2.4 and 2.5 as well.
Changed:
U zc.buildout/branches/regebro-python3/dev.py
U zc.buildout/branches/regebro-python3/src/zc/buildout/buildout.py
U zc.buildout/branches/regebro-python3/src/zc/buildout/easy_install.py
A zc.buildout/branches/regebro-python3/src/zc/buildout/pycompat.py
U zc.buildout/branches/regebro-python3/src/zc/buildout/rmtree.py
-=-
Modified: zc.buildout/branches/regebro-python3/dev.py
===================================================================
--- zc.buildout/branches/regebro-python3/dev.py 2010-11-21 14:54:16 UTC (rev 118516)
+++ zc.buildout/branches/regebro-python3/dev.py 2010-11-21 15:11:30 UTC (rev 118517)
@@ -36,6 +36,16 @@
else:
quote = str
+# Utility to make a binary variable, used like the b'' literal
+# b('foo') will return str undet Python 2 and bytes under Python 3.
+if sys.version < '3':
+ def b(x):
+ return x
+else:
+ import codecs
+ def b(x):
+ return codecs.latin_1_encode(x)[0]
+
# Detect https://bugs.launchpad.net/virtualenv/+bug/572545 .
has_broken_dash_S = subprocess.call(
[sys.executable, '-Sc', 'import pprint'])
@@ -107,7 +117,7 @@
raise ImportError
import setuptools # A flag. Sometimes pkg_resources is installed alone.
except ImportError:
- ez_code = urlopen(setup_source).read().replace(b'\r\n', b'\n')
+ ez_code = urlopen(setup_source).read().replace(b('\r\n'), b('\n'))
ez = {}
exec(ez_code, ez)
setup_args = dict(to_dir='eggs', download_delay=0)
Modified: zc.buildout/branches/regebro-python3/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/regebro-python3/src/zc/buildout/buildout.py 2010-11-21 14:54:16 UTC (rev 118516)
+++ zc.buildout/branches/regebro-python3/src/zc/buildout/buildout.py 2010-11-21 15:11:30 UTC (rev 118517)
@@ -14,7 +14,7 @@
"""Buildout main script
"""
-from .rmtree import rmtree
+from zc.buildout.rmtree import rmtree
try:
from hashlib import md5
except ImportError:
@@ -647,7 +647,7 @@
recipe, 'zc.buildout.uninstall', entry, self)
self._logger.info('Running uninstall recipe.')
uninstaller(part, installed_part_options[part])
- except (ImportError, pkg_resources.DistributionNotFound) as v:
+ except (ImportError, pkg_resources.DistributionNotFound):
pass
# remove created files and directories
@@ -1110,11 +1110,11 @@
return pkg_resources.load_entry_point(
req.project_name, group, entry)
- except Exception as v:
+ except Exception:
buildout._logger.log(
1,
"Could't load %s entry point %s\nfrom %s:\n%s.",
- group, entry, spec, v)
+ group, entry, spec, sys.exc_info()[1])
raise
@@ -1824,7 +1824,7 @@
getattr(buildout, command)(args)
except SystemExit:
pass
- except Exception as v:
+ except Exception:
_doing()
exc_info = sys.exc_info()
import pdb, traceback
@@ -1833,6 +1833,7 @@
sys.stderr.write('\nStarting pdb:\n')
pdb.post_mortem(exc_info[2])
else:
+ v = exc_info[1]
if isinstance(v, (zc.buildout.UserError,
distutils.errors.DistutilsError
)
Modified: zc.buildout/branches/regebro-python3/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/regebro-python3/src/zc/buildout/easy_install.py 2010-11-21 14:54:16 UTC (rev 118516)
+++ zc.buildout/branches/regebro-python3/src/zc/buildout/easy_install.py 2010-11-21 15:11:30 UTC (rev 118517)
@@ -35,6 +35,7 @@
import tempfile
import warnings
import zc.buildout
+from zc.buildout.pycompat import b
import zipimport
_oprp = getattr(os.path, 'realpath', lambda path: path)
@@ -924,8 +925,8 @@
if dist is None:
try:
dist = best[req.key] = env.best_match(req, ws)
- except pkg_resources.VersionConflict as err:
- raise VersionConflict(err, ws)
+ except pkg_resources.VersionConflict:
+ raise VersionConflict(sys.exc_info()[1], ws)
if dist is None or (
dist.location in self._site_packages and not
self.allow_site_package_egg(dist.project_name)):
@@ -1459,7 +1460,7 @@
if changed:
open(script_name, 'w').write(contents)
try:
- os.chmod(script_name, 0o755)
+ os.chmod(script_name, 493) #Octal: 755
except (AttributeError, os.error):
pass
logger.info("Generated %s %r.", logged_type, full_name)
@@ -1591,7 +1592,7 @@
return None
# else: ...
res = stdout.strip()
- if res.endswith(b'.pyc') or res.endswith(b'.pyo'):
+ if res.endswith(b('.pyc')) or res.endswith(b('.pyo')):
raise RuntimeError('Cannot find uncompiled version of %s' % (name,))
if not os.path.exists(res):
raise RuntimeError(
Added: zc.buildout/branches/regebro-python3/src/zc/buildout/pycompat.py
===================================================================
--- zc.buildout/branches/regebro-python3/src/zc/buildout/pycompat.py (rev 0)
+++ zc.buildout/branches/regebro-python3/src/zc/buildout/pycompat.py 2010-11-21 15:11:30 UTC (rev 118517)
@@ -0,0 +1,11 @@
+# A file that holds various utilities to make compatibility between
+# different versions of Python easier:
+
+import sys
+if sys.version < '3':
+ def b(x):
+ return x
+else:
+ import codecs
+ def b(x):
+ return codecs.latin_1_encode(x)[0]
Modified: zc.buildout/branches/regebro-python3/src/zc/buildout/rmtree.py
===================================================================
--- zc.buildout/branches/regebro-python3/src/zc/buildout/rmtree.py 2010-11-21 14:54:16 UTC (rev 118516)
+++ zc.buildout/branches/regebro-python3/src/zc/buildout/rmtree.py 2010-11-21 15:11:30 UTC (rev 118517)
@@ -54,7 +54,7 @@
0
"""
def retry_writeable (func, path, exc):
- os.chmod (path, 0o600)
+ os.chmod (path, 384) # Octal: 600
func (path)
shutil.rmtree (path, onerror = retry_writeable)
More information about the checkins
mailing list