Commit 58a658b2 authored by Vinay Sajip's avatar Vinay Sajip

Changes to support 2.x and 3.x in the same codebase.

--HG--
branch : distribute
extra : rebase_source : 7d3608edee54a43789f0574d702fb839628b5071
parent e63f3e7d
...@@ -14,12 +14,35 @@ method. ...@@ -14,12 +14,35 @@ method.
""" """
import sys, os, zipimport, time, re, imp, types import sys, os, zipimport, time, re, imp, types
from urlparse import urlparse, urlunparse try:
from urlparse import urlparse, urlunparse
except ImportError:
from urllib.parse import urlparse, urlunparse
try: try:
frozenset frozenset
except NameError: except NameError:
from sets import ImmutableSet as frozenset from sets import ImmutableSet as frozenset
try:
basestring
next = lambda o: o.next()
from cStringIO import StringIO
def exec_(code, globs=None, locs=None):
if globs is None:
frame = sys._getframe(1)
globs = frame.f_globals
if locs is None:
locs = frame.f_locals
del frame
elif locs is None:
locs = globs
exec("""exec code in globs, locs""")
except NameError:
basestring = str
from io import StringIO
exec_ = eval("exec")
def execfile(fn, globs, locs):
exec_(compile(open(fn).read(), fn, 'exec'), globs, locs)
# capture these to bypass sandboxing # capture these to bypass sandboxing
from os import utime from os import utime
...@@ -42,7 +65,7 @@ from os.path import isdir, split ...@@ -42,7 +65,7 @@ from os.path import isdir, split
# attribute is present to decide wether to reinstall the package # attribute is present to decide wether to reinstall the package
_distribute = True _distribute = True
def _bypass_ensure_directory(name, mode=0777): def _bypass_ensure_directory(name, mode=0x1FF): # 0777
# Sandbox-bypassing version of ensure_directory() # Sandbox-bypassing version of ensure_directory()
if not WRITE_SUPPORT: if not WRITE_SUPPORT:
raise IOError('"os.mkdir" not supported on this platform.') raise IOError('"os.mkdir" not supported on this platform.')
...@@ -56,20 +79,20 @@ _state_vars = {} ...@@ -56,20 +79,20 @@ _state_vars = {}
def _declare_state(vartype, **kw): def _declare_state(vartype, **kw):
g = globals() g = globals()
for name, val in kw.iteritems(): for name, val in kw.items():
g[name] = val g[name] = val
_state_vars[name] = vartype _state_vars[name] = vartype
def __getstate__(): def __getstate__():
state = {} state = {}
g = globals() g = globals()
for k, v in _state_vars.iteritems(): for k, v in _state_vars.items():
state[k] = g['_sget_'+v](g[k]) state[k] = g['_sget_'+v](g[k])
return state return state
def __setstate__(state): def __setstate__(state):
g = globals() g = globals()
for k, v in state.iteritems(): for k, v in state.items():
g['_sset_'+_state_vars[k]](k, g[k], v) g['_sset_'+_state_vars[k]](k, g[k], v)
return state return state
...@@ -639,7 +662,7 @@ class WorkingSet(object): ...@@ -639,7 +662,7 @@ class WorkingSet(object):
env = full_env + plugin_env env = full_env + plugin_env
shadow_set = self.__class__([]) shadow_set = self.__class__([])
map(shadow_set.add, self) # put all our entries in shadow_set list(map(shadow_set.add, self)) # put all our entries in shadow_set
for project_name in plugin_projects: for project_name in plugin_projects:
...@@ -650,7 +673,8 @@ class WorkingSet(object): ...@@ -650,7 +673,8 @@ class WorkingSet(object):
try: try:
resolvees = shadow_set.resolve(req, env, installer) resolvees = shadow_set.resolve(req, env, installer)
except ResolutionError,v: except ResolutionError:
v = sys.exc_info()[1]
error_info[dist] = v # save error info error_info[dist] = v # save error info
if fallback: if fallback:
continue # try the next older version of project continue # try the next older version of project
...@@ -658,7 +682,7 @@ class WorkingSet(object): ...@@ -658,7 +682,7 @@ class WorkingSet(object):
break # give up on this project, keep going break # give up on this project, keep going
else: else:
map(shadow_set.add, resolvees) list(map(shadow_set.add, resolvees))
distributions.update(dict.fromkeys(resolvees)) distributions.update(dict.fromkeys(resolvees))
# success, no need to try any more versions of this project # success, no need to try any more versions of this project
...@@ -708,7 +732,8 @@ class WorkingSet(object): ...@@ -708,7 +732,8 @@ class WorkingSet(object):
return (self.entries[:], self.entry_keys.copy(), self.by_key.copy(), return (self.entries[:], self.entry_keys.copy(), self.by_key.copy(),
self.callbacks[:]) self.callbacks[:])
def __setstate__(self, (entries, keys, by_key, callbacks)): def __setstate__(self, e_k_b_c):
entries, keys, by_key, callbacks = e_k_b_c
self.entries = entries[:] self.entries = entries[:]
self.entry_keys = keys.copy() self.entry_keys = keys.copy()
self.by_key = by_key.copy() self.by_key = by_key.copy()
...@@ -1021,7 +1046,7 @@ variable to point to an accessible directory. ...@@ -1021,7 +1046,7 @@ variable to point to an accessible directory.
if os.name == 'posix': if os.name == 'posix':
# Make the resource executable # Make the resource executable
mode = ((os.stat(tempname).st_mode) | 0555) & 07777 mode = ((os.stat(tempname).st_mode) | 0x16D) & 0xFFF # 0555, 07777
os.chmod(tempname, mode) os.chmod(tempname, mode)
...@@ -1239,7 +1264,7 @@ class NullProvider: ...@@ -1239,7 +1264,7 @@ class NullProvider:
len(script_text), 0, script_text.split('\n'), script_filename len(script_text), 0, script_text.split('\n'), script_filename
) )
script_code = compile(script_text,script_filename,'exec') script_code = compile(script_text,script_filename,'exec')
exec script_code in namespace, namespace exec_(script_code, namespace, namespace)
def _has(self, path): def _has(self, path):
raise NotImplementedError( raise NotImplementedError(
...@@ -1711,7 +1736,7 @@ def StringIO(*args, **kw): ...@@ -1711,7 +1736,7 @@ def StringIO(*args, **kw):
try: try:
from cStringIO import StringIO from cStringIO import StringIO
except ImportError: except ImportError:
from StringIO import StringIO from io import StringIO
return StringIO(*args,**kw) return StringIO(*args,**kw)
def find_nothing(importer, path_item, only=False): def find_nothing(importer, path_item, only=False):
...@@ -1999,8 +2024,8 @@ class EntryPoint(object): ...@@ -1999,8 +2024,8 @@ class EntryPoint(object):
def require(self, env=None, installer=None): def require(self, env=None, installer=None):
if self.extras and not self.dist: if self.extras and not self.dist:
raise UnknownExtra("Can't require() without a distribution", self) raise UnknownExtra("Can't require() without a distribution", self)
map(working_set.add, list(map(working_set.add,
working_set.resolve(self.dist.requires(self.extras),env,installer)) working_set.resolve(self.dist.requires(self.extras),env,installer)))
...@@ -2064,7 +2089,7 @@ class EntryPoint(object): ...@@ -2064,7 +2089,7 @@ class EntryPoint(object):
def parse_map(cls, data, dist=None): def parse_map(cls, data, dist=None):
"""Parse a map of entry point groups""" """Parse a map of entry point groups"""
if isinstance(data,dict): if isinstance(data,dict):
data = data.items() data = list(data.items())
else: else:
data = split_sections(data) data = split_sections(data)
maps = {} maps = {}
...@@ -2229,7 +2254,7 @@ class Distribution(object): ...@@ -2229,7 +2254,7 @@ class Distribution(object):
self.insert_on(path) self.insert_on(path)
if path is sys.path: if path is sys.path:
fixup_namespace_packages(self.location) fixup_namespace_packages(self.location)
map(declare_namespace, self._get_metadata('namespace_packages.txt')) list(map(declare_namespace, self._get_metadata('namespace_packages.txt')))
def egg_name(self): def egg_name(self):
...@@ -2258,7 +2283,7 @@ class Distribution(object): ...@@ -2258,7 +2283,7 @@ class Distribution(object):
def __getattr__(self,attr): def __getattr__(self,attr):
"""Delegate all unrecognized public attributes to .metadata provider""" """Delegate all unrecognized public attributes to .metadata provider"""
if attr.startswith('_'): if attr.startswith('_'):
raise AttributeError,attr raise AttributeError(attr)
return getattr(self._provider, attr) return getattr(self._provider, attr)
#@classmethod #@classmethod
...@@ -2337,7 +2362,7 @@ class Distribution(object): ...@@ -2337,7 +2362,7 @@ class Distribution(object):
nloc = _normalize_cached(loc) nloc = _normalize_cached(loc)
bdir = os.path.dirname(nloc) bdir = os.path.dirname(nloc)
npath= map(_normalize_cached, path) npath = list(map(_normalize_cached, path))
bp = None bp = None
for p, item in enumerate(npath): for p, item in enumerate(npath):
...@@ -2466,7 +2491,7 @@ def parse_requirements(strs): ...@@ -2466,7 +2491,7 @@ def parse_requirements(strs):
while not TERMINATOR(line,p): while not TERMINATOR(line,p):
if CONTINUE(line,p): if CONTINUE(line,p):
try: try:
line = lines.next(); p = 0 line = next(lines); p = 0
except StopIteration: except StopIteration:
raise ValueError( raise ValueError(
"\\ must not appear on the last nonblank line" "\\ must not appear on the last nonblank line"
...@@ -2558,7 +2583,7 @@ class Requirement: ...@@ -2558,7 +2583,7 @@ class Requirement:
def __contains__(self,item): def __contains__(self,item):
if isinstance(item,Distribution): if isinstance(item,Distribution):
if item.key <> self.key: return False if item.key != self.key: return False
if self.index: item = item.parsed_version # only get if we need it if self.index: item = item.parsed_version # only get if we need it
elif isinstance(item,basestring): elif isinstance(item,basestring):
item = parse_version(item) item = parse_version(item)
...@@ -2727,5 +2752,5 @@ run_main = run_script # backward compatibility ...@@ -2727,5 +2752,5 @@ run_main = run_script # backward compatibility
# all distributions added to the working set in the future (e.g. by # all distributions added to the working set in the future (e.g. by
# calling ``require()``) will get activated as well. # calling ``require()``) will get activated as well.
add_activation_listener(lambda dist: dist.activate()) add_activation_listener(lambda dist: dist.activate())
working_set.entries=[]; map(working_set.add_entry,sys.path) # match order working_set.entries=[]; list(map(working_set.add_entry,sys.path)) # match order
...@@ -4,7 +4,8 @@ import sys ...@@ -4,7 +4,8 @@ import sys
import os import os
src_root = None src_root = None
if sys.version_info >= (3,): do_2to3 = False
if sys.version_info >= (3,) and do_2to3:
tmp_src = os.path.join("build", "src") tmp_src = os.path.join("build", "src")
from distutils.filelist import FileList from distutils.filelist import FileList
from distutils import dir_util, file_util, util, log from distutils import dir_util, file_util, util, log
...@@ -66,7 +67,8 @@ class build_py(_build_py): ...@@ -66,7 +67,8 @@ class build_py(_build_py):
# previous version doesn't have convert_2to3_doctests) # previous version doesn't have convert_2to3_doctests)
if not hasattr(self.distribution, 'convert_2to3_doctests'): if not hasattr(self.distribution, 'convert_2to3_doctests'):
continue continue
if not do_2to3:
continue
if copied and srcfile in self.distribution.convert_2to3_doctests: if copied and srcfile in self.distribution.convert_2to3_doctests:
self.__doctests_2to3.append(outf) self.__doctests_2to3.append(outf)
......
...@@ -9,7 +9,7 @@ def shquote(arg): ...@@ -9,7 +9,7 @@ def shquote(arg):
"""Quote an argument for later parsing by shlex.split()""" """Quote an argument for later parsing by shlex.split()"""
for c in '"', "'", "\\", "#": for c in '"', "'", "\\", "#":
if c in arg: return repr(arg) if c in arg: return repr(arg)
if arg.split()<>[arg]: if arg.split() != [arg]:
return repr(arg) return repr(arg)
return arg return arg
...@@ -33,7 +33,7 @@ class alias(option_base): ...@@ -33,7 +33,7 @@ class alias(option_base):
def finalize_options(self): def finalize_options(self):
option_base.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( raise DistutilsOptionError(
"Must specify exactly one argument (the alias name) when " "Must specify exactly one argument (the alias name) when "
"using --remove" "using --remove"
...@@ -43,10 +43,10 @@ class alias(option_base): ...@@ -43,10 +43,10 @@ class alias(option_base):
aliases = self.distribution.get_option_dict('aliases') aliases = self.distribution.get_option_dict('aliases')
if not self.args: if not self.args:
print "Command Aliases" print("Command Aliases")
print "---------------" print("---------------")
for alias in aliases: for alias in aliases:
print "setup.py alias", format_alias(alias, aliases) print("setup.py alias", format_alias(alias, aliases))
return return
elif len(self.args)==1: elif len(self.args)==1:
...@@ -54,10 +54,10 @@ class alias(option_base): ...@@ -54,10 +54,10 @@ class alias(option_base):
if self.remove: if self.remove:
command = None command = None
elif alias in aliases: elif alias in aliases:
print "setup.py alias", format_alias(alias, aliases) print("setup.py alias", format_alias(alias, aliases))
return return
else: else:
print "No alias definition found for %r" % alias print("No alias definition found for %r" % alias)
return return
else: else:
alias = self.args[0] alias = self.args[0]
......
...@@ -17,6 +17,7 @@ from distutils.errors import DistutilsSetupError ...@@ -17,6 +17,7 @@ from distutils.errors import DistutilsSetupError
from pkg_resources import get_build_platform, Distribution, ensure_directory from pkg_resources import get_build_platform, Distribution, ensure_directory
from pkg_resources import EntryPoint from pkg_resources import EntryPoint
from types import CodeType from types import CodeType
from setuptools.compat import basestring, next
from setuptools.extension import Library from setuptools.extension import Library
def strip_module(filename): def strip_module(filename):
...@@ -379,7 +380,7 @@ NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) ...@@ -379,7 +380,7 @@ NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split())
def walk_egg(egg_dir): def walk_egg(egg_dir):
"""Walk an unpacked egg's contents, skipping the metadata directory""" """Walk an unpacked egg's contents, skipping the metadata directory"""
walker = os.walk(egg_dir) walker = os.walk(egg_dir)
base,dirs,files = walker.next() base,dirs,files = next(walker)
if 'EGG-INFO' in dirs: if 'EGG-INFO' in dirs:
dirs.remove('EGG-INFO') dirs.remove('EGG-INFO')
yield base,dirs,files yield base,dirs,files
...@@ -407,7 +408,7 @@ def write_safety_flag(egg_dir, safe): ...@@ -407,7 +408,7 @@ def write_safety_flag(egg_dir, safe):
for flag,fn in safety_flags.items(): for flag,fn in safety_flags.items():
fn = os.path.join(egg_dir, fn) fn = os.path.join(egg_dir, fn)
if os.path.exists(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) os.unlink(fn)
elif safe is not None and bool(safe)==flag: elif safe is not None and bool(safe)==flag:
f=open(fn,'wt'); f.write('\n'); f.close() f=open(fn,'wt'); f.write('\n'); f.close()
......
...@@ -25,6 +25,7 @@ from setuptools.archive_util import unpack_archive ...@@ -25,6 +25,7 @@ from setuptools.archive_util import unpack_archive
from setuptools.package_index import PackageIndex from setuptools.package_index import PackageIndex
from setuptools.package_index import URL_SCHEME from setuptools.package_index import URL_SCHEME
from setuptools.command import bdist_egg, egg_info 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, \ from pkg_resources import yield_lines, normalize_path, resource_string, \
ensure_directory, get_distribution, find_distributions, \ ensure_directory, get_distribution, find_distributions, \
Environment, Requirement, Distribution, \ Environment, Requirement, Distribution, \
...@@ -187,7 +188,7 @@ class easy_install(Command): ...@@ -187,7 +188,7 @@ class easy_install(Command):
def finalize_options(self): def finalize_options(self):
if self.version: if self.version:
print 'distribute %s' % get_distribution('distribute').version print('distribute %s' % get_distribution('distribute').version)
sys.exit() sys.exit()
py_version = sys.version.split()[0] py_version = sys.version.split()[0]
...@@ -367,7 +368,7 @@ class easy_install(Command): ...@@ -367,7 +368,7 @@ class easy_install(Command):
try: try:
pid = os.getpid() pid = os.getpid()
except: except:
pid = random.randint(0,sys.maxint) pid = random.randint(0, maxsize)
return os.path.join(self.install_dir, "test-easy-install-%s" % pid) return os.path.join(self.install_dir, "test-easy-install-%s" % pid)
def warn_deprecated_options(self): def warn_deprecated_options(self):
...@@ -412,7 +413,7 @@ class easy_install(Command): ...@@ -412,7 +413,7 @@ class easy_install(Command):
self.pth_file = None self.pth_file = None
PYTHONPATH = os.environ.get('PYTHONPATH','').split(os.pathsep) 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 # only PYTHONPATH dirs need a site.py, so pretend it's there
self.sitepy_installed = True self.sitepy_installed = True
elif self.multi_version and not os.path.exists(pth_file): 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. ...@@ -668,11 +669,13 @@ Please make the appropriate changes for your system and try again.
distros = WorkingSet([]).resolve( distros = WorkingSet([]).resolve(
[requirement], self.local_index, self.easy_install [requirement], self.local_index, self.easy_install
) )
except DistributionNotFound, e: except DistributionNotFound:
e = sys.exc_info()[1]
raise DistutilsError( raise DistutilsError(
"Could not find required distribution %s" % e.args "Could not find required distribution %s" % e.args
) )
except VersionConflict, e: except VersionConflict:
e = sys.exc_info()[1]
raise DistutilsError( raise DistutilsError(
"Installed distribution %s conflicts with requirement %s" "Installed distribution %s conflicts with requirement %s"
% e.args % e.args
...@@ -758,7 +761,7 @@ Please make the appropriate changes for your system and try again. ...@@ -758,7 +761,7 @@ Please make the appropriate changes for your system and try again.
f = open(target,"w"+mode) f = open(target,"w"+mode)
f.write(contents) f.write(contents)
f.close() f.close()
chmod(target,0755) chmod(target,0x1ED) # 0755
...@@ -872,7 +875,7 @@ Please make the appropriate changes for your system and try again. ...@@ -872,7 +875,7 @@ Please make the appropriate changes for your system and try again.
f = open(pkg_inf,'w') f = open(pkg_inf,'w')
f.write('Metadata-Version: 1.0\n') f.write('Metadata-Version: 1.0\n')
for k,v in cfg.items('metadata'): 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.write('%s: %s\n' % (k.replace('_','-').title(), v))
f.close() f.close()
script_dir = os.path.join(egg_info,'scripts') script_dir = os.path.join(egg_info,'scripts')
...@@ -1069,7 +1072,8 @@ See the setuptools documentation for the "develop" command for more info. ...@@ -1069,7 +1072,8 @@ See the setuptools documentation for the "develop" command for more info.
) )
try: try:
run_setup(setup_script, args) 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],)) raise DistutilsError("Setup script exited with %s" % (v.args[0],))
def build_and_install(self, setup_script, setup_base): def build_and_install(self, setup_script, setup_base):
...@@ -1149,7 +1153,7 @@ See the setuptools documentation for the "develop" command for more info. ...@@ -1149,7 +1153,7 @@ See the setuptools documentation for the "develop" command for more info.
self.byte_compile(to_compile) self.byte_compile(to_compile)
if not self.dry_run: if not self.dry_run:
for f in to_chmod: 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) chmod(f, mode)
def byte_compile(self, to_compile): def byte_compile(self, to_compile):
...@@ -1263,10 +1267,10 @@ Please make the appropriate changes for your system and try again.""" % ( ...@@ -1263,10 +1267,10 @@ Please make the appropriate changes for your system and try again.""" % (
if not self.user: if not self.user:
return return
home = convert_path(os.path.expanduser("~")) 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): if path.startswith(home) and not os.path.isdir(path):
self.debug_print("os.makedirs('%s', 0700)" % 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.""" % ( ...@@ -1317,7 +1321,8 @@ Please make the appropriate changes for your system and try again.""" % (
def get_site_dirs(): def get_site_dirs():
# return a list of '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] prefixes = [sys.prefix]
if sys.exec_prefix != sys.prefix: if sys.exec_prefix != sys.prefix:
prefixes.append(sys.exec_prefix) prefixes.append(sys.exec_prefix)
...@@ -1355,7 +1360,7 @@ def get_site_dirs(): ...@@ -1355,7 +1360,7 @@ def get_site_dirs():
if HAS_USER_SITE: if HAS_USER_SITE:
sitedirs.append(site.USER_SITE) sitedirs.append(site.USER_SITE)
sitedirs = map(normalize_path, sitedirs) sitedirs = list(map(normalize_path, sitedirs))
return sitedirs return sitedirs
...@@ -1417,7 +1422,8 @@ def extract_wininst_cfg(dist_filename): ...@@ -1417,7 +1422,8 @@ def extract_wininst_cfg(dist_filename):
return None return None
f.seek(prepended-12) 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)) tag, cfglen, bmlen = struct.unpack("<iii",f.read(12))
if tag not in (0x1234567A, 0x1234567B): if tag not in (0x1234567A, 0x1234567B):
return None # not a valid tag return None # not a valid tag
...@@ -1425,7 +1431,7 @@ def extract_wininst_cfg(dist_filename): ...@@ -1425,7 +1431,7 @@ def extract_wininst_cfg(dist_filename):
f.seek(prepended-(12+cfglen)) f.seek(prepended-(12+cfglen))
cfg = ConfigParser.RawConfigParser({'version':'','target_version':''}) cfg = ConfigParser.RawConfigParser({'version':'','target_version':''})
try: 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: except ConfigParser.Error:
return None return None
if not cfg.has_section('metadata') or not cfg.has_section('Setup'): if not cfg.has_section('metadata') or not cfg.has_section('Setup'):
...@@ -1460,7 +1466,7 @@ def get_exe_prefixes(exe_filename): ...@@ -1460,7 +1466,7 @@ def get_exe_prefixes(exe_filename):
if parts[1].endswith('.egg-info'): if parts[1].endswith('.egg-info'):
prefixes.insert(0,('/'.join(parts[:2]), 'EGG-INFO/')) prefixes.insert(0,('/'.join(parts[:2]), 'EGG-INFO/'))
break break
if len(parts)<>2 or not name.endswith('.pth'): if len(parts) != 2 or not name.endswith('.pth'):
continue continue
if name.endswith('-nspkg.pth'): if name.endswith('-nspkg.pth'):
continue continue
...@@ -1490,11 +1496,12 @@ class PthDistributions(Environment): ...@@ -1490,11 +1496,12 @@ class PthDistributions(Environment):
dirty = False dirty = False
def __init__(self, filename, sitedirs=()): 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.basedir = normalize_path(os.path.dirname(self.filename))
self._load(); Environment.__init__(self, [], None, None) self._load(); Environment.__init__(self, [], None, None)
for path in yield_lines(self.paths): 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): def _load(self):
self.paths = [] self.paths = []
...@@ -1623,7 +1630,7 @@ def auto_chmod(func, arg, exc): ...@@ -1623,7 +1630,7 @@ def auto_chmod(func, arg, exc):
chmod(arg, stat.S_IWRITE) chmod(arg, stat.S_IWRITE)
return func(arg) return func(arg)
exc = sys.exc_info() 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): def uncache_zipdir(path):
"""Ensure that the importer caches dont have stale info for `path`""" """Ensure that the importer caches dont have stale info for `path`"""
...@@ -1723,7 +1730,8 @@ def chmod(path, mode): ...@@ -1723,7 +1730,8 @@ def chmod(path, mode):
log.debug("changing mode of %s to %o", path, mode) log.debug("changing mode of %s to %o", path, mode)
try: try:
_chmod(path, mode) _chmod(path, mode)
except os.error, e: except os.error:
e = sys.exc_info()[1]
log.debug("chmod failed: %s", e) log.debug("chmod failed: %s", e)
def fix_jython_executable(executable, options): def fix_jython_executable(executable, options):
...@@ -1799,7 +1807,7 @@ def rmtree(path, ignore_errors=False, onerror=auto_chmod): ...@@ -1799,7 +1807,7 @@ def rmtree(path, ignore_errors=False, onerror=auto_chmod):
names = [] names = []
try: try:
names = os.listdir(path) names = os.listdir(path)
except os.error, err: except os.error:
onerror(os.listdir, path, sys.exc_info()) onerror(os.listdir, path, sys.exc_info())
for name in names: for name in names:
fullname = os.path.join(path, name) fullname = os.path.join(path, name)
...@@ -1812,7 +1820,7 @@ def rmtree(path, ignore_errors=False, onerror=auto_chmod): ...@@ -1812,7 +1820,7 @@ def rmtree(path, ignore_errors=False, onerror=auto_chmod):
else: else:
try: try:
os.remove(fullname) os.remove(fullname)
except os.error, err: except os.error:
onerror(os.remove, fullname, sys.exc_info()) onerror(os.remove, fullname, sys.exc_info())
try: try:
os.rmdir(path) os.rmdir(path)
......
...@@ -8,11 +8,12 @@ from setuptools import Command ...@@ -8,11 +8,12 @@ from setuptools import Command
from distutils.errors import * from distutils.errors import *
from distutils import log from distutils import log
from setuptools.command.sdist import sdist from setuptools.command.sdist import sdist
from setuptools.compat import basestring
from distutils.util import convert_path from distutils.util import convert_path
from distutils.filelist import FileList from distutils.filelist import FileList
from pkg_resources import parse_requirements, safe_name, parse_version, \ from pkg_resources import parse_requirements, safe_name, parse_version, \
safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename 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): class egg_info(Command):
description = "create a distribution's .egg-info directory" description = "create a distribution's .egg-info directory"
...@@ -51,7 +52,7 @@ class egg_info(Command): ...@@ -51,7 +52,7 @@ class egg_info(Command):
self.vtags = None self.vtags = None
def save_version_info(self, filename): def save_version_info(self, filename):
from setopt import edit_config from setuptools.command.setopt import edit_config
edit_config( edit_config(
filename, filename,
{'egg_info': {'egg_info':
...@@ -220,7 +221,7 @@ class egg_info(Command): ...@@ -220,7 +221,7 @@ class egg_info(Command):
f.close() f.close()
if data.startswith('10') or data.startswith('9') or data.startswith('8'): 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' del data[0][0] # get rid of the '8' or '9' or '10'
dirurl = data[0][3] dirurl = data[0][3]
localrev = max([int(d[9]) for d in data if len(d)>9 and d[9]]+[0]) 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): ...@@ -386,7 +387,8 @@ def write_pkg_info(cmd, basename, filename):
metadata.name, metadata.version = oldname, oldver metadata.name, metadata.version = oldname, oldver
safe = getattr(cmd.distribution,'zip_safe',None) 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): def warn_depends_obsolete(cmd, basename, filename):
if os.path.exists(filename): if os.path.exists(filename):
......
...@@ -49,5 +49,5 @@ class install_scripts(_install_scripts): ...@@ -49,5 +49,5 @@ class install_scripts(_install_scripts):
f = open(target,"w"+mode) f = open(target,"w"+mode)
f.write(contents) f.write(contents)
f.close() f.close()
chmod(target,0755) chmod(target,0x1ED) # 0755
import distutils, os import distutils, os
from setuptools import Command from setuptools import Command
from setuptools.compat import basestring
from distutils.util import convert_path from distutils.util import convert_path
from distutils import log from distutils import log
from distutils.errors import * from distutils.errors import *
......
...@@ -9,10 +9,9 @@ class saveopts(option_base): ...@@ -9,10 +9,9 @@ class saveopts(option_base):
def run(self): def run(self):
dist = self.distribution dist = self.distribution
commands = dist.command_options.keys()
settings = {} settings = {}
for cmd in commands: for cmd in dist.command_options:
if cmd=='saveopts': if cmd=='saveopts':
continue # don't save our own options! continue # don't save our own options!
......
...@@ -178,7 +178,7 @@ class sdist(_sdist): ...@@ -178,7 +178,7 @@ class sdist(_sdist):
optional = ['test/test*.py', 'setup.cfg'] optional = ['test/test*.py', 'setup.cfg']
for pattern in optional: for pattern in optional:
files = filter(os.path.isfile, glob(pattern)) files = list(filter(os.path.isfile, glob(pattern)))
if files: if files:
self.filelist.extend(files) self.filelist.extend(files)
......
...@@ -47,9 +47,9 @@ def edit_config(filename, settings, dry_run=False): ...@@ -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. while a dictionary lists settings to be changed or deleted in that section.
A setting of ``None`` means to delete that setting. 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) log.debug("Reading configuration from %s", filename)
opts = RawConfigParser() opts = ConfigParser.RawConfigParser()
opts.read([filename]) opts.read([filename])
for section, options in settings.items(): for section, options in settings.items():
if options is None: if options is None:
......
...@@ -11,13 +11,12 @@ try: ...@@ -11,13 +11,12 @@ try:
except ImportError: except ImportError:
from md5 import md5 from md5 import md5
import os import os
import sys
import socket import socket
import platform import platform
import ConfigParser
import httplib
import base64 import base64
import urlparse
import cStringIO as StringIO from setuptools.compat import urlparse, StringIO, httplib, ConfigParser
class upload(Command): class upload(Command):
...@@ -49,7 +48,7 @@ class upload(Command): ...@@ -49,7 +48,7 @@ class upload(Command):
raise DistutilsOptionError( raise DistutilsOptionError(
"Must use --sign for --identity to have meaning" "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') rc = os.path.join(os.environ['HOME'], '.pypirc')
if os.path.exists(rc): if os.path.exists(rc):
self.announce('Using PyPI login from %s' % rc) self.announce('Using PyPI login from %s' % rc)
...@@ -148,14 +147,14 @@ class upload(Command): ...@@ -148,14 +147,14 @@ class upload(Command):
# We can't use urllib2 since we need to send the Basic # We can't use urllib2 since we need to send the Basic
# auth right with the first request # auth right with the first request
schema, netloc, url, params, query, fragments = \ schema, netloc, url, params, query, fragments = \
urlparse.urlparse(self.repository) urlparse(self.repository)
assert not params and not query and not fragments assert not params and not query and not fragments
if schema == 'http': if schema == 'http':
http = httplib.HTTPConnection(netloc) http = httplib.HTTPConnection(netloc)
elif schema == 'https': elif schema == 'https':
http = httplib.HTTPSConnection(netloc) http = httplib.HTTPSConnection(netloc)
else: else:
raise AssertionError, "unsupported schema "+schema raise AssertionError("unsupported schema " + schema)
data = '' data = ''
loglevel = log.INFO loglevel = log.INFO
...@@ -168,7 +167,8 @@ class upload(Command): ...@@ -168,7 +167,8 @@ class upload(Command):
http.putheader('Authorization', auth) http.putheader('Authorization', auth)
http.endheaders() http.endheaders()
http.send(body) http.send(body)
except socket.error, e: except socket.error:
e = sys.exc_info()[1]
self.announce(str(e), log.ERROR) self.announce(str(e), log.ERROR)
return return
...@@ -180,4 +180,4 @@ class upload(Command): ...@@ -180,4 +180,4 @@ class upload(Command):
self.announce('Upload failed (%s): %s' % (r.status, r.reason), self.announce('Upload failed (%s): %s' % (r.status, r.reason),
log.ERROR) log.ERROR)
if self.show_response: if self.show_response:
print '-'*75, r.read(), '-'*75 print('-'*75, r.read(), '-'*75)
...@@ -8,9 +8,7 @@ PyPI's packages.python.org). ...@@ -8,9 +8,7 @@ PyPI's packages.python.org).
import os import os
import socket import socket
import zipfile import zipfile
import httplib
import base64 import base64
import urlparse
import tempfile import tempfile
import sys import sys
...@@ -22,6 +20,8 @@ try: ...@@ -22,6 +20,8 @@ try:
except ImportError: except ImportError:
from setuptools.command.upload import upload from setuptools.command.upload import upload
from setuptools.compat import httplib, urlparse
_IS_PYTHON3 = sys.version > '3' _IS_PYTHON3 = sys.version > '3'
try: try:
...@@ -137,7 +137,7 @@ class upload_docs(upload): ...@@ -137,7 +137,7 @@ class upload_docs(upload):
# We can't use urllib2 since we need to send the Basic # We can't use urllib2 since we need to send the Basic
# auth right with the first request # auth right with the first request
schema, netloc, url, params, query, fragments = \ schema, netloc, url, params, query, fragments = \
urlparse.urlparse(self.repository) urlparse(self.repository)
assert not params and not query and not fragments assert not params and not query and not fragments
if schema == 'http': if schema == 'http':
conn = httplib.HTTPConnection(netloc) conn = httplib.HTTPConnection(netloc)
...@@ -157,7 +157,8 @@ class upload_docs(upload): ...@@ -157,7 +157,8 @@ class upload_docs(upload):
conn.putheader('Authorization', auth) conn.putheader('Authorization', auth)
conn.endheaders() conn.endheaders()
conn.send(body) conn.send(body)
except socket.error, e: except socket.error:
e = sys.exc_info()[1]
self.announce(str(e), log.ERROR) self.announce(str(e), log.ERROR)
return return
...@@ -175,4 +176,4 @@ class upload_docs(upload): ...@@ -175,4 +176,4 @@ class upload_docs(upload):
self.announce('Upload failed (%s): %s' % (r.status, r.reason), self.announce('Upload failed (%s): %s' % (r.status, r.reason),
log.ERROR) log.ERROR)
if self.show_response: if self.show_response:
print '-'*75, r.read(), '-'*75 print('-'*75, r.read(), '-'*75)
import sys
if sys.version_info[0] < 3:
PY3 = False
basestring = basestring
import __builtin__ as builtins
import ConfigParser
from cStringIO import StringIO
BytesIO = StringIO
execfile = execfile
func_code = lambda o: o.func_code
func_globals = lambda o: o.func_globals
im_func = lambda o: o.im_func
from htmlentitydefs import name2codepoint
import httplib
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
iteritems = lambda o: o.iteritems
long_type = long
maxsize = sys.maxint
next = lambda o: o.next()
numeric_types = (int, long, float)
reduce = reduce
unichr = unichr
unicode = unicode
from urllib import url2pathname
import urllib2
from urllib2 import urlopen, HTTPError, URLError, unquote, splituser
from urlparse import urlparse, urlunparse, urljoin
xrange = xrange
def exec_(code, globs=None, locs=None):
if globs is None:
frame = sys._getframe(1)
globs = frame.f_globals
if locs is None:
locs = frame.f_locals
del frame
elif locs is None:
locs = globs
exec("""exec code in globs, locs""")
else:
PY3 = True
basestring = str
import builtins
import configparser as ConfigParser
exec_ = eval('exec')
from io import StringIO, BytesIO
func_code = lambda o: o.__code__
func_globals = lambda o: o.__globals__
im_func = lambda o: o.__func__
from html.entities import name2codepoint
import http.client as httplib
from http.server import HTTPServer, SimpleHTTPRequestHandler
iteritems = lambda o: o.items
long_type = int
maxsize = sys.maxsize
next = next
numeric_types = (int, float)
from functools import reduce
unichr = chr
unicode = str
from urllib.error import HTTPError, URLError
import urllib.request as urllib2
from urllib.request import urlopen, url2pathname
from urllib.parse import urlparse, urlunparse, unquote, splituser, urljoin
xrange = range
def execfile(fn, globs, locs):
exec_(compile(open(fn).read(), fn, 'exec'), globs, locs)
...@@ -36,7 +36,7 @@ class Require: ...@@ -36,7 +36,7 @@ class Require:
def version_ok(self,version): def version_ok(self,version):
"""Is 'version' sufficiently up-to-date?""" """Is 'version' sufficiently up-to-date?"""
return self.attribute is None or self.format is None or \ return self.attribute is None or self.format is None or \
str(version)<>"unknown" and version >= self.requested_version str(version) != "unknown" and version >= self.requested_version
def get_version(self, paths=None, default="unknown"): def get_version(self, paths=None, default="unknown"):
...@@ -103,7 +103,7 @@ def _iter_code(code): ...@@ -103,7 +103,7 @@ def _iter_code(code):
ptr += 3 ptr += 3
if op==EXTENDED_ARG: if op==EXTENDED_ARG:
extended_arg = arg * 65536L extended_arg = arg * long_type(65536)
continue continue
else: else:
......
__all__ = ['Distribution'] __all__ = ['Distribution']
import re import re
import sys
from distutils.core import Distribution as _Distribution from distutils.core import Distribution as _Distribution
from setuptools.depends import Require from setuptools.depends import Require
from setuptools.command.install import install from setuptools.command.install import install
from setuptools.command.sdist import sdist from setuptools.command.sdist import sdist
from setuptools.command.install_lib import install_lib from setuptools.command.install_lib import install_lib
from setuptools.compat import numeric_types, basestring
from distutils.errors import DistutilsOptionError, DistutilsPlatformError from distutils.errors import DistutilsOptionError, DistutilsPlatformError
from distutils.errors import DistutilsSetupError from distutils.errors import DistutilsSetupError
import setuptools, pkg_resources, distutils.core, distutils.dist, distutils.cmd import setuptools, pkg_resources, distutils.core, distutils.dist, distutils.cmd
...@@ -100,7 +102,8 @@ def check_entry_points(dist, attr, value): ...@@ -100,7 +102,8 @@ def check_entry_points(dist, attr, value):
"""Verify that entry_points map is parseable""" """Verify that entry_points map is parseable"""
try: try:
pkg_resources.EntryPoint.parse_map(value) pkg_resources.EntryPoint.parse_map(value)
except ValueError, e: except ValueError:
e = sys.exc_info()[1]
raise DistutilsSetupError(e) raise DistutilsSetupError(e)
def check_test_suite(dist, attr, value): def check_test_suite(dist, attr, value):
...@@ -223,7 +226,7 @@ class Distribution(_Distribution): ...@@ -223,7 +226,7 @@ class Distribution(_Distribution):
if not hasattr(self,ep.name): if not hasattr(self,ep.name):
setattr(self,ep.name,None) setattr(self,ep.name,None)
_Distribution.__init__(self,attrs) _Distribution.__init__(self,attrs)
if isinstance(self.metadata.version, (int,long,float)): if isinstance(self.metadata.version, numeric_types):
# Some people apparently take "version number" too literally :) # Some people apparently take "version number" too literally :)
self.metadata.version = str(self.metadata.version) self.metadata.version = str(self.metadata.version)
...@@ -526,7 +529,7 @@ class Distribution(_Distribution): ...@@ -526,7 +529,7 @@ class Distribution(_Distribution):
raise DistutilsSetupError( raise DistutilsSetupError(
"packages: setting must be a list or tuple (%r)" % (packages,) "packages: setting must be a list or tuple (%r)" % (packages,)
) )
map(self.exclude_package, packages) list(map(self.exclude_package, packages))
......
This diff is collapsed.
import os, sys, __builtin__, tempfile, operator, pkg_resources import os, sys, tempfile, operator, pkg_resources
_os = sys.modules[os.name] _os = sys.modules[os.name]
try: try:
_file = file _file = file
...@@ -6,6 +6,8 @@ except NameError: ...@@ -6,6 +6,8 @@ except NameError:
_file = None _file = None
_open = open _open = open
from distutils.errors import DistutilsError from distutils.errors import DistutilsError
from setuptools.compat import builtins, execfile, reduce
__all__ = [ __all__ = [
"AbstractSandbox", "DirectorySandbox", "SandboxViolation", "run_setup", "AbstractSandbox", "DirectorySandbox", "SandboxViolation", "run_setup",
] ]
...@@ -32,7 +34,8 @@ def run_setup(setup_script, args): ...@@ -32,7 +34,8 @@ def run_setup(setup_script, args):
{'__file__':setup_script, '__name__':'__main__'} {'__file__':setup_script, '__name__':'__main__'}
) )
) )
except SystemExit, v: except SystemExit:
v = sys.exc_info()[1]
if v.args and v.args[0]: if v.args and v.args[0]:
raise raise
# Normal exit, just return # Normal exit, just return
...@@ -66,15 +69,15 @@ class AbstractSandbox: ...@@ -66,15 +69,15 @@ class AbstractSandbox:
try: try:
self._copy(self) self._copy(self)
if _file: if _file:
__builtin__.file = self._file builtins.file = self._file
__builtin__.open = self._open builtins.open = self._open
self._active = True self._active = True
return func() return func()
finally: finally:
self._active = False self._active = False
if _file: if _file:
__builtin__.file = _file builtins.file = _file
__builtin__.open = _open builtins.open = _open
self._copy(_os) self._copy(_os)
...@@ -225,7 +228,7 @@ class DirectorySandbox(AbstractSandbox): ...@@ -225,7 +228,7 @@ class DirectorySandbox(AbstractSandbox):
self._violation(operation, src, dst, *args, **kw) self._violation(operation, src, dst, *args, **kw)
return (src,dst) return (src,dst)
def open(self, file, flags, mode=0777): def open(self, file, flags, mode=0x1FF): # 0777
"""Called for low-level os.open()""" """Called for low-level os.open()"""
if flags & WRITE_FLAGS and not self._ok(file): if flags & WRITE_FLAGS and not self._ok(file):
self._violation("os.open", file, flags, mode) self._violation("os.open", file, flags, mode)
......
...@@ -7,6 +7,7 @@ import setuptools, setuptools.dist ...@@ -7,6 +7,7 @@ import setuptools, setuptools.dist
from setuptools import Feature from setuptools import Feature
from distutils.core import Extension from distutils.core import Extension
extract_constant, get_module_constant = None, None extract_constant, get_module_constant = None, None
from setuptools.compat import func_code
from setuptools.depends import * from setuptools.depends import *
from distutils.version import StrictVersion, LooseVersion from distutils.version import StrictVersion, LooseVersion
from distutils.util import convert_path from distutils.util import convert_path
...@@ -50,17 +51,18 @@ class DependsTests(TestCase): ...@@ -50,17 +51,18 @@ class DependsTests(TestCase):
x = "test" x = "test"
y = z y = z
fc = func_code(f1)
# unrecognized name # unrecognized name
self.assertEqual(extract_constant(f1.func_code,'q', -1), None) self.assertEqual(extract_constant(fc,'q', -1), None)
# constant assigned # constant assigned
self.assertEqual(extract_constant(f1.func_code,'x', -1), "test") self.assertEqual(extract_constant(fc,'x', -1), "test")
# expression assigned # expression assigned
self.assertEqual(extract_constant(f1.func_code,'y', -1), -1) self.assertEqual(extract_constant(fc,'y', -1), -1)
# recognized name, not assigned # recognized name, not assigned
self.assertEqual(extract_constant(f1.func_code,'z', -1), None) self.assertEqual(extract_constant(fc,'z', -1), None)
def testFindModule(self): def testFindModule(self):
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
try: try:
basestring basestring
except NameError: except NameError:
basestring = str,unicode basestring = str
try: try:
enumerate enumerate
...@@ -109,7 +109,7 @@ import __future__ ...@@ -109,7 +109,7 @@ import __future__
import sys, traceback, inspect, linecache, os, re, types import sys, traceback, inspect, linecache, os, re, types
import unittest, difflib, pdb, tempfile import unittest, difflib, pdb, tempfile
import warnings import warnings
from StringIO import StringIO from setuptools.compat import StringIO, execfile, exec_, func_code, im_func
# Don't whine about the deprecated is_private function in this # Don't whine about the deprecated is_private function in this
# module's tests. # module's tests.
...@@ -240,7 +240,7 @@ def _normalize_module(module, depth=2): ...@@ -240,7 +240,7 @@ def _normalize_module(module, depth=2):
""" """
if inspect.ismodule(module): if inspect.ismodule(module):
return module return module
elif isinstance(module, (str, unicode)): elif isinstance(module, basestring):
return __import__(module, globals(), locals(), ["*"]) return __import__(module, globals(), locals(), ["*"])
elif module is None: elif module is None:
return sys.modules[sys._getframe(depth).f_globals['__name__']] return sys.modules[sys._getframe(depth).f_globals['__name__']]
...@@ -367,9 +367,9 @@ class _OutputRedirectingPdb(pdb.Pdb): ...@@ -367,9 +367,9 @@ class _OutputRedirectingPdb(pdb.Pdb):
# [XX] Normalize with respect to os.path.pardir? # [XX] Normalize with respect to os.path.pardir?
def _module_relative_path(module, path): def _module_relative_path(module, path):
if not inspect.ismodule(module): if not inspect.ismodule(module):
raise TypeError, 'Expected a module: %r' % module raise TypeError('Expected a module: %r' % module)
if path.startswith('/'): if path.startswith('/'):
raise ValueError, 'Module-relative files may not have absolute paths' raise ValueError('Module-relative files may not have absolute paths')
# Find the base directory for the path. # Find the base directory for the path.
if hasattr(module, '__file__'): if hasattr(module, '__file__'):
...@@ -877,7 +877,7 @@ class DocTestFinder: ...@@ -877,7 +877,7 @@ class DocTestFinder:
if module is None: if module is None:
return True return True
elif inspect.isfunction(object): elif inspect.isfunction(object):
return module.__dict__ is object.func_globals return module.__dict__ is func_globals(object)
elif inspect.isclass(object): elif inspect.isclass(object):
return module.__name__ == object.__module__ return module.__name__ == object.__module__
elif inspect.getmodule(object) is not None: elif inspect.getmodule(object) is not None:
...@@ -895,7 +895,7 @@ class DocTestFinder: ...@@ -895,7 +895,7 @@ class DocTestFinder:
add them to `tests`. add them to `tests`.
""" """
if self._verbose: if self._verbose:
print 'Finding tests in %s' % name print('Finding tests in %s' % name)
# If we've already processed this object, then ignore it. # If we've already processed this object, then ignore it.
if id(obj) in seen: if id(obj) in seen:
...@@ -948,7 +948,7 @@ class DocTestFinder: ...@@ -948,7 +948,7 @@ class DocTestFinder:
if isinstance(val, staticmethod): if isinstance(val, staticmethod):
val = getattr(obj, valname) val = getattr(obj, valname)
if isinstance(val, classmethod): if isinstance(val, classmethod):
val = getattr(obj, valname).im_func val = im_func(getattr(obj, valname))
# Recurse to methods, properties, and nested classes. # Recurse to methods, properties, and nested classes.
if ((inspect.isfunction(val) or inspect.isclass(val) or if ((inspect.isfunction(val) or inspect.isclass(val) or
...@@ -1020,8 +1020,8 @@ class DocTestFinder: ...@@ -1020,8 +1020,8 @@ class DocTestFinder:
break break
# Find the line number for functions & methods. # Find the line number for functions & methods.
if inspect.ismethod(obj): obj = obj.im_func if inspect.ismethod(obj): obj = im_func(obj)
if inspect.isfunction(obj): obj = obj.func_code if inspect.isfunction(obj): obj = func_code(obj)
if inspect.istraceback(obj): obj = obj.tb_frame if inspect.istraceback(obj): obj = obj.tb_frame
if inspect.isframe(obj): obj = obj.f_code if inspect.isframe(obj): obj = obj.f_code
if inspect.iscode(obj): if inspect.iscode(obj):
...@@ -1250,8 +1250,8 @@ class DocTestRunner: ...@@ -1250,8 +1250,8 @@ class DocTestRunner:
# keyboard interrupts.) # keyboard interrupts.)
try: try:
# Don't blink! This is where the user's code gets run. # Don't blink! This is where the user's code gets run.
exec compile(example.source, filename, "single", exec_(compile(example.source, filename, "single",
compileflags, 1) in test.globs compileflags, 1), test.globs)
self.debugger.set_continue() # ==== Example Finished ==== self.debugger.set_continue() # ==== Example Finished ====
exception = None exception = None
except KeyboardInterrupt: except KeyboardInterrupt:
...@@ -1335,7 +1335,7 @@ class DocTestRunner: ...@@ -1335,7 +1335,7 @@ class DocTestRunner:
if m and m.group('name') == self.test.name: if m and m.group('name') == self.test.name:
example = self.test.examples[int(m.group('examplenum'))] example = self.test.examples[int(m.group('examplenum'))]
return example.source.splitlines(True) return example.source.splitlines(True)
elif self.save_linecache_getlines.func_code.co_argcount>1: elif func_code(self.save_linecache_getlines).co_argcount > 1:
return self.save_linecache_getlines(filename, module_globals) return self.save_linecache_getlines(filename, module_globals)
else: else:
return self.save_linecache_getlines(filename) return self.save_linecache_getlines(filename)
...@@ -1427,28 +1427,28 @@ class DocTestRunner: ...@@ -1427,28 +1427,28 @@ class DocTestRunner:
failed.append(x) failed.append(x)
if verbose: if verbose:
if notests: if notests:
print len(notests), "items had no tests:" print(len(notests), "items had no tests:")
notests.sort() notests.sort()
for thing in notests: for thing in notests:
print " ", thing print(" ", thing)
if passed: if passed:
print len(passed), "items passed all tests:" print(len(passed), "items passed all tests:")
passed.sort() passed.sort()
for thing, count in passed: for thing, count in passed:
print " %3d tests in %s" % (count, thing) print(" %3d tests in %s" % (count, thing))
if failed: if failed:
print self.DIVIDER print(self.DIVIDER)
print len(failed), "items had failures:" print(len(failed), "items had failures:")
failed.sort() failed.sort()
for thing, (f, t) in failed: for thing, (f, t) in failed:
print " %3d of %3d in %s" % (f, t, thing) print(" %3d of %3d in %s" % (f, t, thing))
if verbose: if verbose:
print totalt, "tests in", len(self._name2ft), "items." print(totalt, "tests in", len(self._name2ft), "items.")
print totalt - totalf, "passed and", totalf, "failed." print(totalt - totalf, "passed and", totalf, "failed.")
if totalf: if totalf:
print "***Test Failed***", totalf, "failures." print("***Test Failed***", totalf, "failures.")
elif verbose: elif verbose:
print "Test passed." print("Test passed.")
return totalf, totalt return totalf, totalt
#///////////////////////////////////////////////////////////////// #/////////////////////////////////////////////////////////////////
...@@ -1458,8 +1458,8 @@ class DocTestRunner: ...@@ -1458,8 +1458,8 @@ class DocTestRunner:
d = self._name2ft d = self._name2ft
for name, (f, t) in other._name2ft.items(): for name, (f, t) in other._name2ft.items():
if name in d: if name in d:
print "*** DocTestRunner.merge: '" + name + "' in both" \ print("*** DocTestRunner.merge: '" + name + "' in both" \
" testers; summing outcomes." " testers; summing outcomes.")
f2, t2 = d[name] f2, t2 = d[name]
f = f + f2 f = f + f2
t = t + t2 t = t + t2
...@@ -2037,10 +2037,10 @@ class Tester: ...@@ -2037,10 +2037,10 @@ class Tester:
def runstring(self, s, name): def runstring(self, s, name):
test = DocTestParser().get_doctest(s, self.globs, name, None, None) test = DocTestParser().get_doctest(s, self.globs, name, None, None)
if self.verbose: if self.verbose:
print "Running string", name print("Running string", name)
(f,t) = self.testrunner.run(test) (f,t) = self.testrunner.run(test)
if self.verbose: if self.verbose:
print f, "of", t, "examples failed in string", name print(f, "of", t, "examples failed in string", name)
return (f,t) return (f,t)
def rundoc(self, object, name=None, module=None): def rundoc(self, object, name=None, module=None):
...@@ -2552,7 +2552,7 @@ def debug_script(src, pm=False, globs=None): ...@@ -2552,7 +2552,7 @@ def debug_script(src, pm=False, globs=None):
try: try:
execfile(srcfilename, globs, globs) execfile(srcfilename, globs, globs)
except: except:
print sys.exc_info()[1] print(sys.exc_info()[1])
pdb.post_mortem(sys.exc_info()[2]) pdb.post_mortem(sys.exc_info()[2])
else: else:
# Note that %r is vital here. '%s' instead can, e.g., cause # Note that %r is vital here. '%s' instead can, e.g., cause
......
"""Basic http server for tests to simulate PyPI or custom indexes """Basic http server for tests to simulate PyPI or custom indexes
""" """
import urllib2
import sys import sys
from threading import Thread from threading import Thread
from BaseHTTPServer import HTTPServer from setuptools.compat import (urllib2, URLError, HTTPServer,
from SimpleHTTPServer import SimpleHTTPRequestHandler SimpleHTTPRequestHandler)
class IndexServer(HTTPServer): class IndexServer(HTTPServer):
"""Basic single-threaded http server simulating a package index """Basic single-threaded http server simulating a package index
...@@ -39,7 +38,7 @@ class IndexServer(HTTPServer): ...@@ -39,7 +38,7 @@ class IndexServer(HTTPServer):
None, 5) None, 5)
else: else:
urllib2.urlopen('http://127.0.0.1:%s/' % self.server_port) urllib2.urlopen('http://127.0.0.1:%s/' % self.server_port)
except urllib2.URLError: except URLError:
pass pass
self.thread.join() self.thread.join()
......
...@@ -4,11 +4,11 @@ import sys ...@@ -4,11 +4,11 @@ import sys
import os, shutil, tempfile, unittest import os, shutil, tempfile, unittest
import tempfile import tempfile
import site import site
from StringIO import StringIO
from distutils.errors import DistutilsError from distutils.errors import DistutilsError
from setuptools.command.develop import develop from setuptools.command.develop import develop
from setuptools.command import easy_install as easy_install_pkg from setuptools.command import easy_install as easy_install_pkg
from setuptools.compat import StringIO
from setuptools.dist import Distribution from setuptools.dist import Distribution
SETUP_PY = """\ SETUP_PY = """\
...@@ -73,7 +73,8 @@ class TestDevelopTest(unittest.TestCase): ...@@ -73,7 +73,8 @@ class TestDevelopTest(unittest.TestCase):
try: try:
try: try:
dist = Distribution({'setup_requires': ['I_DONT_EXIST']}) dist = Distribution({'setup_requires': ['I_DONT_EXIST']})
except DistutilsError, e: except DistutilsError:
e = sys.exc_info()[1]
error = str(e) error = str(e)
if error == wanted: if error == wanted:
pass pass
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import sys import sys
import os, shutil, tempfile, unittest import os, shutil, tempfile, unittest
import site import site
from StringIO import StringIO from setuptools.compat import StringIO, next
from setuptools.command.easy_install import easy_install, get_script_args, main from setuptools.command.easy_install import easy_install, get_script_args, main
from setuptools.command.easy_install import PthDistributions from setuptools.command.easy_install import PthDistributions
from setuptools.command import easy_install as easy_install_pkg from setuptools.command import easy_install as easy_install_pkg
...@@ -67,7 +67,7 @@ class TestEasyInstallTest(unittest.TestCase): ...@@ -67,7 +67,7 @@ class TestEasyInstallTest(unittest.TestCase):
old_platform = sys.platform old_platform = sys.platform
try: try:
name, script = get_script_args(dist).next() name, script = next(get_script_args(dist))
finally: finally:
sys.platform = old_platform sys.platform = old_platform
...@@ -125,8 +125,7 @@ class TestEasyInstallTest(unittest.TestCase): ...@@ -125,8 +125,7 @@ class TestEasyInstallTest(unittest.TestCase):
cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok') cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
cmd.args = ['ok'] cmd.args = ['ok']
cmd.ensure_finalized() cmd.ensure_finalized()
keys = cmd.package_index.scanned_urls.keys() keys = sorted(cmd.package_index.scanned_urls.keys())
keys.sort()
self.assertEquals(keys, ['link1', 'link2']) self.assertEquals(keys, ['link1', 'link2'])
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
""" """
# More would be better! # More would be better!
import sys import sys
import os, shutil, tempfile, unittest, urllib2 import os, shutil, tempfile, unittest
import pkg_resources import pkg_resources
from setuptools.compat import urllib2, httplib, HTTPError
import setuptools.package_index import setuptools.package_index
from server import IndexServer from tests.server import IndexServer
class TestPackageIndex(unittest.TestCase): class TestPackageIndex(unittest.TestCase):
...@@ -14,10 +15,11 @@ class TestPackageIndex(unittest.TestCase): ...@@ -14,10 +15,11 @@ class TestPackageIndex(unittest.TestCase):
url = 'http://127.0.0.1:0/nonesuch/test_package_index' url = 'http://127.0.0.1:0/nonesuch/test_package_index'
try: try:
v = index.open_url(url) v = index.open_url(url)
except Exception, v: except Exception:
v = sys.exc_info()[1]
self.assert_(url in str(v)) self.assert_(url in str(v))
else: else:
self.assert_(isinstance(v,urllib2.HTTPError)) self.assert_(isinstance(v, HTTPError))
# issue 16 # issue 16
# easy_install inquant.contentmirror.plone breaks because of a typo # easy_install inquant.contentmirror.plone breaks because of a typo
...@@ -29,13 +31,13 @@ class TestPackageIndex(unittest.TestCase): ...@@ -29,13 +31,13 @@ class TestPackageIndex(unittest.TestCase):
url = 'url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunk' url = 'url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunk'
try: try:
v = index.open_url(url) v = index.open_url(url)
except Exception, v: except Exception:
v = sys.exc_info()[1]
self.assert_(url in str(v)) self.assert_(url in str(v))
else: else:
self.assert_(isinstance(v, urllib2.HTTPError)) self.assert_(isinstance(v, HTTPError))
def _urlopen(*args): def _urlopen(*args):
import httplib
raise httplib.BadStatusLine('line') raise httplib.BadStatusLine('line')
old_urlopen = urllib2.urlopen old_urlopen = urllib2.urlopen
...@@ -44,7 +46,8 @@ class TestPackageIndex(unittest.TestCase): ...@@ -44,7 +46,8 @@ class TestPackageIndex(unittest.TestCase):
try: try:
try: try:
v = index.open_url(url) v = index.open_url(url)
except Exception, v: except Exception:
v = sys.exc_info()[1]
self.assert_('line' in str(v)) self.assert_('line' in str(v))
else: else:
raise AssertionError('Should have raise here!') raise AssertionError('Should have raise here!')
...@@ -55,7 +58,8 @@ class TestPackageIndex(unittest.TestCase): ...@@ -55,7 +58,8 @@ class TestPackageIndex(unittest.TestCase):
url = 'http://http://svn.pythonpaste.org/Paste/wphp/trunk' url = 'http://http://svn.pythonpaste.org/Paste/wphp/trunk'
try: try:
index.open_url(url) index.open_url(url)
except Exception, v: except Exception:
v = sys.exc_info()[1]
self.assert_('nonnumeric port' in str(v)) self.assert_('nonnumeric port' in str(v))
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
# NOTE: the shebang and encoding lines are for ScriptHeaderTests; do not remove # NOTE: the shebang and encoding lines are for ScriptHeaderTests; do not remove
from unittest import TestCase, makeSuite; from pkg_resources import * from unittest import TestCase, makeSuite; from pkg_resources import *
from setuptools.command.easy_install import get_script_header, is_sh from setuptools.command.easy_install import get_script_header, is_sh
import os, pkg_resources, sys, StringIO, tempfile, shutil from setuptools.compat import StringIO, iteritems
import os, pkg_resources, sys, tempfile, shutil
try: frozenset try: frozenset
except NameError: except NameError:
from sets import ImmutableSet as frozenset from sets import ImmutableSet as frozenset
...@@ -139,7 +140,7 @@ class DistroTests(TestCase): ...@@ -139,7 +140,7 @@ class DistroTests(TestCase):
for i in range(3): for i in range(3):
targets = list(ws.resolve(parse_requirements("Foo"), ad)) targets = list(ws.resolve(parse_requirements("Foo"), ad))
self.assertEqual(targets, [Foo]) self.assertEqual(targets, [Foo])
map(ws.add,targets) list(map(ws.add,targets))
self.assertRaises(VersionConflict, ws.resolve, self.assertRaises(VersionConflict, ws.resolve,
parse_requirements("Foo==0.9"), ad) parse_requirements("Foo==0.9"), ad)
ws = WorkingSet([]) # reset ws = WorkingSet([]) # reset
...@@ -262,7 +263,7 @@ class EntryPointTests(TestCase): ...@@ -262,7 +263,7 @@ class EntryPointTests(TestCase):
def checkSubMap(self, m): def checkSubMap(self, m):
self.assertEqual(len(m), len(self.submap_expect)) self.assertEqual(len(m), len(self.submap_expect))
for key, ep in self.submap_expect.iteritems(): for key, ep in iteritems(self.submap_expect):
self.assertEqual(repr(m.get(key)), repr(ep)) self.assertEqual(repr(m.get(key)), repr(ep))
submap_expect = dict( submap_expect = dict(
...@@ -286,10 +287,10 @@ class EntryPointTests(TestCase): ...@@ -286,10 +287,10 @@ class EntryPointTests(TestCase):
def testParseMap(self): def testParseMap(self):
m = EntryPoint.parse_map({'xyz':self.submap_str}) m = EntryPoint.parse_map({'xyz':self.submap_str})
self.checkSubMap(m['xyz']) self.checkSubMap(m['xyz'])
self.assertEqual(m.keys(),['xyz']) self.assertEqual(list(m.keys()),['xyz'])
m = EntryPoint.parse_map("[xyz]\n"+self.submap_str) m = EntryPoint.parse_map("[xyz]\n"+self.submap_str)
self.checkSubMap(m['xyz']) self.checkSubMap(m['xyz'])
self.assertEqual(m.keys(),['xyz']) self.assertEqual(list(m.keys()),['xyz'])
self.assertRaises(ValueError, EntryPoint.parse_map, ["[xyz]", "[xyz]"]) self.assertRaises(ValueError, EntryPoint.parse_map, ["[xyz]", "[xyz]"])
self.assertRaises(ValueError, EntryPoint.parse_map, self.submap_str) self.assertRaises(ValueError, EntryPoint.parse_map, self.submap_str)
...@@ -549,12 +550,12 @@ class ScriptHeaderTests(TestCase): ...@@ -549,12 +550,12 @@ class ScriptHeaderTests(TestCase):
# Ensure we generate what is basically a broken shebang line # Ensure we generate what is basically a broken shebang line
# when there's options, with a warning emitted # when there's options, with a warning emitted
sys.stdout = sys.stderr = StringIO.StringIO() sys.stdout = sys.stderr = StringIO()
self.assertEqual(get_script_header('#!/usr/bin/python -x', self.assertEqual(get_script_header('#!/usr/bin/python -x',
executable=exe), executable=exe),
'#!%s -x\n' % exe) '#!%s -x\n' % exe)
self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue()) self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue())
sys.stdout = sys.stderr = StringIO.StringIO() sys.stdout = sys.stderr = StringIO()
self.assertEqual(get_script_header('#!/usr/bin/python', self.assertEqual(get_script_header('#!/usr/bin/python',
executable=self.non_ascii_exe), executable=self.non_ascii_exe),
'#!%s -x\n' % self.non_ascii_exe) '#!%s -x\n' % self.non_ascii_exe)
...@@ -606,7 +607,7 @@ class NamespaceTests(TestCase): ...@@ -606,7 +607,7 @@ class NamespaceTests(TestCase):
self.assertTrue("pkg1" in pkg_resources._namespace_packages.keys()) self.assertTrue("pkg1" in pkg_resources._namespace_packages.keys())
try: try:
import pkg1.pkg2 import pkg1.pkg2
except ImportError, e: except ImportError:
self.fail("Distribute tried to import the parent namespace package") self.fail("Distribute tried to import the parent namespace package")
# check the _namespace_packages dict # check the _namespace_packages dict
self.assertTrue("pkg1.pkg2" in pkg_resources._namespace_packages.keys()) self.assertTrue("pkg1.pkg2" in pkg_resources._namespace_packages.keys())
......
import urllib2
import sys import sys
import os import os
from setuptools.compat import urllib2
if os.path.exists('distribute_setup.py'): if os.path.exists('distribute_setup.py'):
print 'distribute_setup.py exists in the current dir, aborting' print('distribute_setup.py exists in the current dir, aborting')
sys.exit(2) sys.exit(2)
print '**** Starting Test' print('**** Starting Test')
print '\n\n' print('\n\n')
is_jython = sys.platform.startswith('java') is_jython = sys.platform.startswith('java')
if is_jython: if is_jython:
import subprocess import subprocess
print 'Downloading bootstrap' print('Downloading bootstrap')
file = urllib2.urlopen('http://nightly.ziade.org/distribute_setup.py') file = urllib2.urlopen('http://nightly.ziade.org/distribute_setup.py')
f = open('distribute_setup.py', 'w') f = open('distribute_setup.py', 'w')
f.write(file.read()) f.write(file.read())
...@@ -27,7 +27,7 @@ else: ...@@ -27,7 +27,7 @@ else:
res = os.spawnv(os.P_WAIT, sys.executable, args) res = os.spawnv(os.P_WAIT, sys.executable, args)
if res != 0: if res != 0:
print '**** Test failed, please send me the output at tarek@ziade.org' print('**** Test failed, please send me the output at tarek@ziade.org')
os.remove('distribute_setup.py') os.remove('distribute_setup.py')
sys.exit(2) sys.exit(2)
...@@ -63,11 +63,11 @@ try: ...@@ -63,11 +63,11 @@ try:
else: else:
res = os.spawnv(os.P_WAIT, sys.executable, args) res = os.spawnv(os.P_WAIT, sys.executable, args)
print '\n\n' print('\n\n')
if res: if res:
print '**** Test is OK' print('**** Test is OK')
else: else:
print '**** Test failed, please send me the output at tarek@ziade.org' print('**** Test failed, please send me the output at tarek@ziade.org')
finally: finally:
if os.path.exists(script_name): if os.path.exists(script_name):
os.remove(script_name) os.remove(script_name)
......
...@@ -9,7 +9,7 @@ import shutil ...@@ -9,7 +9,7 @@ import shutil
import tempfile import tempfile
from distutils.command.install import INSTALL_SCHEMES from distutils.command.install import INSTALL_SCHEMES
from string import Template from string import Template
from urllib2 import urlopen from setuptools.compat import urlopen
try: try:
import subprocess import subprocess
......
...@@ -17,7 +17,7 @@ import distribute_setup ...@@ -17,7 +17,7 @@ import distribute_setup
class TestSetup(unittest.TestCase): class TestSetup(unittest.TestCase):
def urlopen(self, url): def urlopen(self, url):
return open(self.tarball) return open(self.tarball, 'rb')
def setUp(self): def setUp(self):
self.old_sys_path = copy.copy(sys.path) self.old_sys_path = copy.copy(sys.path)
...@@ -28,7 +28,7 @@ class TestSetup(unittest.TestCase): ...@@ -28,7 +28,7 @@ class TestSetup(unittest.TestCase):
"--dist-dir", "%s" % self.tmpdir) "--dist-dir", "%s" % self.tmpdir)
tarball = os.listdir(self.tmpdir)[0] tarball = os.listdir(self.tmpdir)[0]
self.tarball = os.path.join(self.tmpdir, tarball) self.tarball = os.path.join(self.tmpdir, tarball)
import urllib2 from setuptools.compat import urllib2
urllib2.urlopen = self.urlopen urllib2.urlopen = self.urlopen
def tearDown(self): def tearDown(self):
...@@ -38,7 +38,7 @@ class TestSetup(unittest.TestCase): ...@@ -38,7 +38,7 @@ class TestSetup(unittest.TestCase):
def test_build_egg(self): def test_build_egg(self):
# making it an egg # making it an egg
egg = _build_egg(self.tarball, self.tmpdir) egg = _build_egg('Egg to be built', self.tarball, self.tmpdir)
# now trying to import it # now trying to import it
sys.path[0] = egg sys.path[0] = egg
......
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