diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-06-20 22:55:16 +0100 |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-06-20 22:55:16 +0100 |
commit | 58a658b26d1c95b31d02050dcccd648d2e4ce27b (patch) | |
tree | b9d3e7de6f6d23b91a7afecde3491e99d8cc7069 /setuptools/command | |
parent | e63f3e7d864b26529d6b197e053b4084be20decf (diff) | |
download | external_python_setuptools-58a658b26d1c95b31d02050dcccd648d2e4ce27b.tar.gz external_python_setuptools-58a658b26d1c95b31d02050dcccd648d2e4ce27b.tar.bz2 external_python_setuptools-58a658b26d1c95b31d02050dcccd648d2e4ce27b.zip |
Changes to support 2.x and 3.x in the same codebase.
--HG--
branch : distribute
extra : rebase_source : 7d3608edee54a43789f0574d702fb839628b5071
Diffstat (limited to 'setuptools/command')
-rwxr-xr-x | setuptools/command/alias.py | 14 | ||||
-rw-r--r-- | setuptools/command/bdist_egg.py | 5 | ||||
-rwxr-xr-x | setuptools/command/easy_install.py | 52 | ||||
-rwxr-xr-x | setuptools/command/egg_info.py | 10 | ||||
-rwxr-xr-x | setuptools/command/install_scripts.py | 2 | ||||
-rwxr-xr-x | setuptools/command/rotate.py | 1 | ||||
-rwxr-xr-x | setuptools/command/saveopts.py | 3 | ||||
-rwxr-xr-x | setuptools/command/sdist.py | 2 | ||||
-rwxr-xr-x | setuptools/command/setopt.py | 4 | ||||
-rwxr-xr-x | setuptools/command/upload.py | 18 | ||||
-rw-r--r-- | setuptools/command/upload_docs.py | 11 |
11 files changed, 67 insertions, 55 deletions
diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index f5368b29..52384e1a 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -9,7 +9,7 @@ def shquote(arg): """Quote an argument for later parsing by shlex.split()""" for c in '"', "'", "\\", "#": if c in arg: return repr(arg) - if arg.split()<>[arg]: + if arg.split() != [arg]: return repr(arg) return arg @@ -33,7 +33,7 @@ class alias(option_base): def finalize_options(self): option_base.finalize_options(self) - if self.remove and len(self.args)<>1: + if self.remove and len(self.args) != 1: raise DistutilsOptionError( "Must specify exactly one argument (the alias name) when " "using --remove" @@ -43,10 +43,10 @@ class alias(option_base): aliases = self.distribution.get_option_dict('aliases') if not self.args: - print "Command Aliases" - print "---------------" + print("Command Aliases") + print("---------------") for alias in aliases: - print "setup.py alias", format_alias(alias, aliases) + print("setup.py alias", format_alias(alias, aliases)) return elif len(self.args)==1: @@ -54,10 +54,10 @@ class alias(option_base): if self.remove: command = None elif alias in aliases: - print "setup.py alias", format_alias(alias, aliases) + print("setup.py alias", format_alias(alias, aliases)) return else: - print "No alias definition found for %r" % alias + print("No alias definition found for %r" % alias) return else: alias = self.args[0] diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 68ca15c7..007f3ba9 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -17,6 +17,7 @@ from distutils.errors import DistutilsSetupError from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import EntryPoint from types import CodeType +from setuptools.compat import basestring, next from setuptools.extension import Library def strip_module(filename): @@ -379,7 +380,7 @@ NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" walker = os.walk(egg_dir) - base,dirs,files = walker.next() + base,dirs,files = next(walker) if 'EGG-INFO' in dirs: dirs.remove('EGG-INFO') yield base,dirs,files @@ -407,7 +408,7 @@ def write_safety_flag(egg_dir, safe): 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: + if safe is None or bool(safe) != flag: os.unlink(fn) elif safe is not None and bool(safe)==flag: f=open(fn,'wt'); f.write('\n'); f.close() diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 58e7ab39..b8a10346 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -25,6 +25,7 @@ from setuptools.archive_util import unpack_archive from setuptools.package_index import PackageIndex from setuptools.package_index import URL_SCHEME from setuptools.command import bdist_egg, egg_info +from setuptools.compat import iteritems, maxsize, xrange, basestring, unicode from pkg_resources import yield_lines, normalize_path, resource_string, \ ensure_directory, get_distribution, find_distributions, \ Environment, Requirement, Distribution, \ @@ -187,7 +188,7 @@ class easy_install(Command): def finalize_options(self): if self.version: - print 'distribute %s' % get_distribution('distribute').version + print('distribute %s' % get_distribution('distribute').version) sys.exit() py_version = sys.version.split()[0] @@ -367,7 +368,7 @@ class easy_install(Command): try: pid = os.getpid() except: - pid = random.randint(0,sys.maxint) + pid = random.randint(0, maxsize) return os.path.join(self.install_dir, "test-easy-install-%s" % pid) def warn_deprecated_options(self): @@ -412,7 +413,7 @@ class easy_install(Command): self.pth_file = None PYTHONPATH = os.environ.get('PYTHONPATH','').split(os.pathsep) - if instdir not in map(normalize_path, filter(None,PYTHONPATH)): + if instdir not in map(normalize_path, [_f for _f in PYTHONPATH if _f]): # only PYTHONPATH dirs need a site.py, so pretend it's there self.sitepy_installed = True elif self.multi_version and not os.path.exists(pth_file): @@ -668,11 +669,13 @@ Please make the appropriate changes for your system and try again. distros = WorkingSet([]).resolve( [requirement], self.local_index, self.easy_install ) - except DistributionNotFound, e: + except DistributionNotFound: + e = sys.exc_info()[1] raise DistutilsError( "Could not find required distribution %s" % e.args ) - except VersionConflict, e: + except VersionConflict: + e = sys.exc_info()[1] raise DistutilsError( "Installed distribution %s conflicts with requirement %s" % e.args @@ -758,7 +761,7 @@ Please make the appropriate changes for your system and try again. f = open(target,"w"+mode) f.write(contents) f.close() - chmod(target,0755) + chmod(target,0x1ED) # 0755 @@ -872,7 +875,7 @@ Please make the appropriate changes for your system and try again. f = open(pkg_inf,'w') f.write('Metadata-Version: 1.0\n') for k,v in cfg.items('metadata'): - if k<>'target_version': + if k != 'target_version': f.write('%s: %s\n' % (k.replace('_','-').title(), v)) f.close() script_dir = os.path.join(egg_info,'scripts') @@ -1069,7 +1072,8 @@ See the setuptools documentation for the "develop" command for more info. ) try: run_setup(setup_script, args) - except SystemExit, v: + except SystemExit: + v = sys.exc_info()[1] raise DistutilsError("Setup script exited with %s" % (v.args[0],)) def build_and_install(self, setup_script, setup_base): @@ -1149,7 +1153,7 @@ See the setuptools documentation for the "develop" command for more info. self.byte_compile(to_compile) if not self.dry_run: for f in to_chmod: - mode = ((os.stat(f)[stat.ST_MODE]) | 0555) & 07755 + mode = ((os.stat(f)[stat.ST_MODE]) | 0x16D) & 0xFED # 0555, 07755 chmod(f, mode) def byte_compile(self, to_compile): @@ -1263,10 +1267,10 @@ Please make the appropriate changes for your system and try again.""" % ( if not self.user: return home = convert_path(os.path.expanduser("~")) - for name, path in self.config_vars.iteritems(): + for name, path in iteritems(self.config_vars): if path.startswith(home) and not os.path.isdir(path): self.debug_print("os.makedirs('%s', 0700)" % path) - os.makedirs(path, 0700) + os.makedirs(path, 0x1C0) # 0700 @@ -1317,7 +1321,8 @@ Please make the appropriate changes for your system and try again.""" % ( def get_site_dirs(): # return a list of 'site' dirs - sitedirs = filter(None,os.environ.get('PYTHONPATH','').split(os.pathsep)) + sitedirs = [_f for _f in os.environ.get('PYTHONPATH', + '').split(os.pathsep) if _f] prefixes = [sys.prefix] if sys.exec_prefix != sys.prefix: prefixes.append(sys.exec_prefix) @@ -1355,7 +1360,7 @@ def get_site_dirs(): if HAS_USER_SITE: sitedirs.append(site.USER_SITE) - sitedirs = map(normalize_path, sitedirs) + sitedirs = list(map(normalize_path, sitedirs)) return sitedirs @@ -1417,7 +1422,8 @@ def extract_wininst_cfg(dist_filename): return None f.seek(prepended-12) - import struct, StringIO, ConfigParser + from setuptools.compat import StringIO, ConfigParser + import struct tag, cfglen, bmlen = struct.unpack("<iii",f.read(12)) if tag not in (0x1234567A, 0x1234567B): return None # not a valid tag @@ -1425,7 +1431,7 @@ def extract_wininst_cfg(dist_filename): f.seek(prepended-(12+cfglen)) cfg = ConfigParser.RawConfigParser({'version':'','target_version':''}) try: - cfg.readfp(StringIO.StringIO(f.read(cfglen).split(chr(0),1)[0])) + cfg.readfp(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'): @@ -1460,7 +1466,7 @@ def get_exe_prefixes(exe_filename): if parts[1].endswith('.egg-info'): prefixes.insert(0,('/'.join(parts[:2]), 'EGG-INFO/')) break - if len(parts)<>2 or not name.endswith('.pth'): + if len(parts) != 2 or not name.endswith('.pth'): continue if name.endswith('-nspkg.pth'): continue @@ -1490,11 +1496,12 @@ class PthDistributions(Environment): dirty = False def __init__(self, filename, sitedirs=()): - self.filename = filename; self.sitedirs=map(normalize_path, sitedirs) + self.filename = filename + self.sitedirs = list(map(normalize_path, sitedirs)) self.basedir = normalize_path(os.path.dirname(self.filename)) self._load(); Environment.__init__(self, [], None, None) for path in yield_lines(self.paths): - map(self.add, find_distributions(path, True)) + list(map(self.add, find_distributions(path, True))) def _load(self): self.paths = [] @@ -1623,7 +1630,7 @@ def auto_chmod(func, arg, exc): 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))) + raise exc[0](exc[1][0], exc[1][1] + (" %s %s" % (func,arg))) def uncache_zipdir(path): """Ensure that the importer caches dont have stale info for `path`""" @@ -1723,7 +1730,8 @@ def chmod(path, mode): log.debug("changing mode of %s to %o", path, mode) try: _chmod(path, mode) - except os.error, e: + except os.error: + e = sys.exc_info()[1] log.debug("chmod failed: %s", e) def fix_jython_executable(executable, options): @@ -1799,7 +1807,7 @@ def rmtree(path, ignore_errors=False, onerror=auto_chmod): names = [] try: names = os.listdir(path) - except os.error, err: + except os.error: onerror(os.listdir, path, sys.exc_info()) for name in names: fullname = os.path.join(path, name) @@ -1812,7 +1820,7 @@ def rmtree(path, ignore_errors=False, onerror=auto_chmod): else: try: os.remove(fullname) - except os.error, err: + except os.error: onerror(os.remove, fullname, sys.exc_info()) try: os.rmdir(path) diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 46cdf4e0..9ccbe68f 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -8,11 +8,12 @@ from setuptools import Command from distutils.errors import * from distutils import log from setuptools.command.sdist import sdist +from setuptools.compat import basestring from distutils.util import convert_path from distutils.filelist import FileList from pkg_resources import parse_requirements, safe_name, parse_version, \ safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename -from sdist import walk_revctrl +from setuptools.command.sdist import walk_revctrl class egg_info(Command): description = "create a distribution's .egg-info directory" @@ -51,7 +52,7 @@ class egg_info(Command): self.vtags = None def save_version_info(self, filename): - from setopt import edit_config + from setuptools.command.setopt import edit_config edit_config( filename, {'egg_info': @@ -220,7 +221,7 @@ class egg_info(Command): f.close() if data.startswith('10') or data.startswith('9') or data.startswith('8'): - data = map(str.splitlines,data.split('\n\x0c\n')) + data = list(map(str.splitlines,data.split('\n\x0c\n'))) del data[0][0] # get rid of the '8' or '9' or '10' dirurl = data[0][3] localrev = max([int(d[9]) for d in data if len(d)>9 and d[9]]+[0]) @@ -386,7 +387,8 @@ def write_pkg_info(cmd, basename, filename): 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) + from setuptools.command import bdist_egg + bdist_egg.write_safety_flag(cmd.egg_info, safe) def warn_depends_obsolete(cmd, basename, filename): if os.path.exists(filename): diff --git a/setuptools/command/install_scripts.py b/setuptools/command/install_scripts.py index 6ce1b993..251190ba 100755 --- a/setuptools/command/install_scripts.py +++ b/setuptools/command/install_scripts.py @@ -49,5 +49,5 @@ class install_scripts(_install_scripts): f = open(target,"w"+mode) f.write(contents) f.close() - chmod(target,0755) + chmod(target,0x1ED) # 0755 diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index 11b6eae8..b10acfb4 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -1,5 +1,6 @@ import distutils, os from setuptools import Command +from setuptools.compat import basestring from distutils.util import convert_path from distutils import log from distutils.errors import * diff --git a/setuptools/command/saveopts.py b/setuptools/command/saveopts.py index 1180a440..7209be4c 100755 --- a/setuptools/command/saveopts.py +++ b/setuptools/command/saveopts.py @@ -9,10 +9,9 @@ class saveopts(option_base): def run(self): dist = self.distribution - commands = dist.command_options.keys() settings = {} - for cmd in commands: + for cmd in dist.command_options: if cmd=='saveopts': continue # don't save our own options! diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index 3442fe4b..499a3fb9 100755 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -178,7 +178,7 @@ class sdist(_sdist): optional = ['test/test*.py', 'setup.cfg'] for pattern in optional: - files = filter(os.path.isfile, glob(pattern)) + files = list(filter(os.path.isfile, glob(pattern))) if files: self.filelist.extend(files) diff --git a/setuptools/command/setopt.py b/setuptools/command/setopt.py index dbf3a94e..aa468c88 100755 --- a/setuptools/command/setopt.py +++ b/setuptools/command/setopt.py @@ -47,9 +47,9 @@ def edit_config(filename, settings, dry_run=False): while a dictionary lists settings to be changed or deleted in that section. A setting of ``None`` means to delete that setting. """ - from ConfigParser import RawConfigParser + from setuptools.compat import ConfigParser log.debug("Reading configuration from %s", filename) - opts = RawConfigParser() + opts = ConfigParser.RawConfigParser() opts.read([filename]) for section, options in settings.items(): if options is None: diff --git a/setuptools/command/upload.py b/setuptools/command/upload.py index 1f49745e..6b18d761 100755 --- a/setuptools/command/upload.py +++ b/setuptools/command/upload.py @@ -11,13 +11,12 @@ try: except ImportError: from md5 import md5 import os +import sys import socket import platform -import ConfigParser -import httplib import base64 -import urlparse -import cStringIO as StringIO + +from setuptools.compat import urlparse, StringIO, httplib, ConfigParser class upload(Command): @@ -49,7 +48,7 @@ class upload(Command): raise DistutilsOptionError( "Must use --sign for --identity to have meaning" ) - if os.environ.has_key('HOME'): + if 'HOME' in os.environ: rc = os.path.join(os.environ['HOME'], '.pypirc') if os.path.exists(rc): self.announce('Using PyPI login from %s' % rc) @@ -148,14 +147,14 @@ class upload(Command): # We can't use urllib2 since we need to send the Basic # auth right with the first request schema, netloc, url, params, query, fragments = \ - urlparse.urlparse(self.repository) + urlparse(self.repository) assert not params and not query and not fragments if schema == 'http': http = httplib.HTTPConnection(netloc) elif schema == 'https': http = httplib.HTTPSConnection(netloc) else: - raise AssertionError, "unsupported schema "+schema + raise AssertionError("unsupported schema " + schema) data = '' loglevel = log.INFO @@ -168,7 +167,8 @@ class upload(Command): http.putheader('Authorization', auth) http.endheaders() http.send(body) - except socket.error, e: + except socket.error: + e = sys.exc_info()[1] self.announce(str(e), log.ERROR) return @@ -180,4 +180,4 @@ class upload(Command): self.announce('Upload failed (%s): %s' % (r.status, r.reason), log.ERROR) if self.show_response: - print '-'*75, r.read(), '-'*75 + print('-'*75, r.read(), '-'*75) diff --git a/setuptools/command/upload_docs.py b/setuptools/command/upload_docs.py index 213f7b58..505ddadb 100644 --- a/setuptools/command/upload_docs.py +++ b/setuptools/command/upload_docs.py @@ -8,9 +8,7 @@ PyPI's packages.python.org). import os import socket import zipfile -import httplib import base64 -import urlparse import tempfile import sys @@ -22,6 +20,8 @@ try: except ImportError: from setuptools.command.upload import upload +from setuptools.compat import httplib, urlparse + _IS_PYTHON3 = sys.version > '3' try: @@ -137,7 +137,7 @@ class upload_docs(upload): # We can't use urllib2 since we need to send the Basic # auth right with the first request schema, netloc, url, params, query, fragments = \ - urlparse.urlparse(self.repository) + urlparse(self.repository) assert not params and not query and not fragments if schema == 'http': conn = httplib.HTTPConnection(netloc) @@ -157,7 +157,8 @@ class upload_docs(upload): conn.putheader('Authorization', auth) conn.endheaders() conn.send(body) - except socket.error, e: + except socket.error: + e = sys.exc_info()[1] self.announce(str(e), log.ERROR) return @@ -175,4 +176,4 @@ class upload_docs(upload): self.announce('Upload failed (%s): %s' % (r.status, r.reason), log.ERROR) if self.show_response: - print '-'*75, r.read(), '-'*75 + print('-'*75, r.read(), '-'*75) |