Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
b59a01e0
Commit
b59a01e0
authored
Jun 29, 2013
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Plain Diff
Merge 0.6.46 with native Python 3 code
--HG-- branch : distribute
parents
1ce8f258
3c86c861
Changes
34
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
452 additions
and
311 deletions
+452
-311
pkg_resources.py
pkg_resources.py
+51
-22
setup.py
setup.py
+4
-2
setuptools/command/alias.py
setuptools/command/alias.py
+7
-7
setuptools/command/bdist_egg.py
setuptools/command/bdist_egg.py
+3
-2
setuptools/command/easy_install.py
setuptools/command/easy_install.py
+34
-25
setuptools/command/egg_info.py
setuptools/command/egg_info.py
+6
-4
setuptools/command/install_scripts.py
setuptools/command/install_scripts.py
+1
-1
setuptools/command/rotate.py
setuptools/command/rotate.py
+1
-0
setuptools/command/saveopts.py
setuptools/command/saveopts.py
+1
-2
setuptools/command/sdist.py
setuptools/command/sdist.py
+1
-1
setuptools/command/setopt.py
setuptools/command/setopt.py
+2
-2
setuptools/command/upload.py
setuptools/command/upload.py
+9
-10
setuptools/command/upload_docs.py
setuptools/command/upload_docs.py
+7
-5
setuptools/compat.py
setuptools/compat.py
+94
-0
setuptools/depends.py
setuptools/depends.py
+2
-2
setuptools/dist.py
setuptools/dist.py
+6
-3
setuptools/package_index.py
setuptools/package_index.py
+47
-39
setuptools/sandbox.py
setuptools/sandbox.py
+10
-7
setuptools/tests/__init__.py
setuptools/tests/__init__.py
+6
-4
setuptools/tests/doctest.py
setuptools/tests/doctest.py
+29
-29
setuptools/tests/server.py
setuptools/tests/server.py
+6
-6
setuptools/tests/test_bdist_egg.py
setuptools/tests/test_bdist_egg.py
+1
-1
setuptools/tests/test_develop.py
setuptools/tests/test_develop.py
+13
-9
setuptools/tests/test_dist_info.py
setuptools/tests/test_dist_info.py
+23
-20
setuptools/tests/test_easy_install.py
setuptools/tests/test_easy_install.py
+9
-10
setuptools/tests/test_packageindex.py
setuptools/tests/test_packageindex.py
+12
-10
setuptools/tests/test_resources.py
setuptools/tests/test_resources.py
+9
-8
setuptools/tests/test_sdist.py
setuptools/tests/test_sdist.py
+13
-11
setuptools/tests/test_test.py
setuptools/tests/test_test.py
+7
-7
setuptools/tests/win_script_wrapper.txt
setuptools/tests/win_script_wrapper.txt
+21
-45
tests/api_tests.txt
tests/api_tests.txt
+4
-4
tests/install_test.py
tests/install_test.py
+9
-9
tests/manual_test.py
tests/manual_test.py
+1
-1
tests/test_distribute_setup.py
tests/test_distribute_setup.py
+3
-3
No files found.
pkg_resources.py
View file @
b59a01e0
...
...
@@ -16,12 +16,39 @@ method.
import
sys
,
os
,
time
,
re
,
imp
,
types
,
zipfile
,
zipimport
import
warnings
import
stat
from
urlparse
import
urlparse
,
urlunparse
try
:
from
urlparse
import
urlparse
,
urlunparse
except
ImportError
:
from
urllib.parse
import
urlparse
,
urlunparse
try
:
frozenset
except
NameError
:
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
=
None
,
locs
=
None
):
if
globs
is
None
:
globs
=
globals
()
if
locs
is
None
:
locs
=
globs
exec_
(
compile
(
open
(
fn
).
read
(),
fn
,
'exec'
),
globs
,
locs
)
# capture these to bypass sandboxing
from
os
import
utime
...
...
@@ -50,7 +77,7 @@ else:
# attribute is present to decide wether to reinstall the package
_distribute
=
True
def
_bypass_ensure_directory
(
name
,
mode
=
0
777
):
def
_bypass_ensure_directory
(
name
,
mode
=
0
x1FF
):
# 0777
# Sandbox-bypassing version of ensure_directory()
if
not
WRITE_SUPPORT
:
raise
IOError
(
'"os.mkdir" not supported on this platform.'
)
...
...
@@ -64,20 +91,20 @@ _state_vars = {}
def
_declare_state
(
vartype
,
**
kw
):
g
=
globals
()
for
name
,
val
in
kw
.
ite
rite
ms
():
for
name
,
val
in
kw
.
items
():
g
[
name
]
=
val
_state_vars
[
name
]
=
vartype
def
__getstate__
():
state
=
{}
g
=
globals
()
for
k
,
v
in
_state_vars
.
ite
rite
ms
():
for
k
,
v
in
_state_vars
.
items
():
state
[
k
]
=
g
[
'_sget_'
+
v
](
g
[
k
])
return
state
def
__setstate__
(
state
):
g
=
globals
()
for
k
,
v
in
state
.
ite
rite
ms
():
for
k
,
v
in
state
.
items
():
g
[
'_sset_'
+
_state_vars
[
k
]](
k
,
g
[
k
],
v
)
return
state
...
...
@@ -651,7 +678,7 @@ class WorkingSet(object):
env = full_env + plugin_env
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:
...
...
@@ -662,7 +689,8 @@ class WorkingSet(object):
try:
resolvees = shadow_set.resolve(req, env, installer)
except ResolutionError,v:
except ResolutionError:
v = sys.exc_info()[1]
error_info[dist] = v # save error info
if fallback:
continue # try the next older version of project
...
...
@@ -670,7 +698,7 @@ class WorkingSet(object):
break # give up on this project, keep going
else:
map(shadow_set.add, resolvees
)
list(map(shadow_set.add, resolvees)
)
distributions.update(dict.fromkeys(resolvees))
# success, no need to try any more versions of this project
...
...
@@ -720,7 +748,8 @@ class WorkingSet(object):
return (self.entries[:], self.entry_keys.copy(), self.by_key.copy(),
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.entry_keys = keys.copy()
self.by_key = by_key.copy()
...
...
@@ -1057,7 +1086,7 @@ variable to point to an accessible directory.
if os.name == 'posix':
# Make the resource executable
mode = ((os.stat(tempname).st_mode) | 0
555) &
07777
mode = ((os.stat(tempname).st_mode) | 0
x16D) & 0xFFF # 0555,
07777
os.chmod(tempname, mode)
...
...
@@ -1275,7 +1304,7 @@ class NullProvider:
len(script_text), 0, script_text.split('\n'), script_filename
)
script_code = compile(script_text,script_filename,'exec')
exec
script_code in namespace, namespace
exec
_(script_code, namespace, namespace)
def _has(self, path):
raise NotImplementedError(
...
...
@@ -1795,7 +1824,7 @@ def StringIO(*args, **kw):
try:
from cStringIO import StringIO
except ImportError:
from
StringIO
import StringIO
from
io
import StringIO
return StringIO(*args,**kw)
def find_nothing(importer, path_item, only=False):
...
...
@@ -2094,8 +2123,8 @@ class EntryPoint(object):
def require(self, env=None, installer=None):
if self.extras and not self.dist:
raise UnknownExtra("
Can
't require() without a distribution", self)
map(working_set.add,
working_set.resolve(self.dist.requires(self.extras),env,installer))
list(
map(working_set.add,
working_set.resolve(self.dist.requires(self.extras),env,installer))
)
...
...
@@ -2159,7 +2188,7 @@ class EntryPoint(object):
def parse_map(cls, data, dist=None):
"""Parse a map of entry point groups"""
if isinstance(data,dict):
data =
data.items(
)
data =
list(data.items()
)
else:
data = split_sections(data)
maps = {}
...
...
@@ -2328,7 +2357,7 @@ class Distribution(object):
self
.
insert_on
(
path
)
if
path
is
sys
.
path
:
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
):
...
...
@@ -2357,7 +2386,7 @@ class Distribution(object):
def
__getattr__
(
self
,
attr
):
"""Delegate all unrecognized public attributes to .metadata provider"""
if
attr
.
startswith
(
'_'
):
raise
AttributeError
,
attr
raise
AttributeError
(
attr
)
return
getattr
(
self
.
_provider
,
attr
)
#@classmethod
...
...
@@ -2436,7 +2465,7 @@ class Distribution(object):
nloc
=
_normalize_cached
(
loc
)
bdir
=
os
.
path
.
dirname
(
nloc
)
npath
=
map
(
_normalize_cached
,
path
)
npath
=
list
(
map
(
_normalize_cached
,
path
)
)
bp
=
None
for
p
,
item
in
enumerate
(
npath
):
...
...
@@ -2558,7 +2587,7 @@ class DistInfoDistribution(Distribution):
# Including any condition expressions
for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
distvers, mark = self._preparse_requirement(req)
parsed =
parse_requirements(distvers).next(
)
parsed =
next(parse_requirements(distvers)
)
parsed.marker_fn = compile_marker(mark)
reqs.append(parsed)
...
...
@@ -2633,7 +2662,7 @@ def parse_requirements(strs):
while not TERMINATOR(line,p):
if CONTINUE(line,p):
try:
line =
lines.next(
); p = 0
line =
next(lines
); p = 0
except StopIteration:
raise ValueError(
"
\\
must
not
appear
on
the
last
nonblank
line
"
...
...
@@ -2725,7 +2754,7 @@ class Requirement:
def __contains__(self,item):
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
elif isinstance(item,basestring):
item = parse_version(item)
...
...
@@ -2894,6 +2923,6 @@ run_main = run_script # backward compatibility
# all distributions added to the working set in the future (e.g. by
# calling ``require()``) will get activated as well.
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
setup.py
View file @
b59a01e0
...
...
@@ -9,7 +9,8 @@ import re
os
.
chdir
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
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"
)
from
distutils.filelist
import
FileList
from
distutils
import
dir_util
,
file_util
,
util
,
log
...
...
@@ -75,7 +76,8 @@ class build_py(_build_py):
# previous version doesn't have convert_2to3_doctests)
if
not
hasattr
(
self
.
distribution
,
'convert_2to3_doctests'
):
continue
if
not
do_2to3
:
continue
if
copied
and
srcfile
in
self
.
distribution
.
convert_2to3_doctests
:
self
.
__doctests_2to3
.
append
(
outf
)
...
...
setuptools/command/alias.py
View file @
b59a01e0
...
...
@@ -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
]
...
...
setuptools/command/bdist_egg.py
View file @
b59a01e0
...
...
@@ -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
()
...
...
setuptools/command/easy_install.py
View file @
b59a01e0
...
...
@@ -36,6 +36,8 @@ 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
,
reraise
)
from
pkg_resources
import
yield_lines
,
normalize_path
,
resource_string
,
\
ensure_directory
,
get_distribution
,
find_distributions
,
\
Environment
,
Requirement
,
Distribution
,
\
...
...
@@ -202,7 +204,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
]
...
...
@@ -382,7 +384,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
):
...
...
@@ -427,7 +429,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
):
...
...
@@ -687,11 +689,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
...
...
@@ -782,7 +786,7 @@ Please make the appropriate changes for your system and try again.
f
=
open
(
target
,
"w"
+
mode
)
f
.
write
(
contents
)
f
.
close
()
chmod
(
target
,
0
777
-
mask
)
chmod
(
target
,
0
x1FF
-
mask
)
# 0777
...
...
@@ -896,7 +900,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'
)
...
...
@@ -1093,7 +1097,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
):
...
...
@@ -1135,7 +1140,7 @@ See the setuptools documentation for the "develop" command for more info.
'site_dirs'
,
'allow_hosts'
,
)
fetch_options
=
{}
for
key
,
val
in
ei_opts
.
ite
rite
ms
():
for
key
,
val
in
ei_opts
.
items
():
if
key
not
in
fetch_directives
:
continue
fetch_options
[
key
.
replace
(
'_'
,
'-'
)]
=
val
[
1
]
# create a settings dictionary suitable for `edit_config`
...
...
@@ -1200,7 +1205,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
])
|
0
555
)
&
07755
mode
=
((
os
.
stat
(
f
)[
stat
.
ST_MODE
])
|
0
x16D
)
&
0xFED
# 0555,
07755
chmod
(
f
,
mode
)
def
byte_compile
(
self
,
to_compile
):
...
...
@@ -1314,10 +1319,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
,
0
700
)
os
.
makedirs
(
path
,
0
x1C0
)
# 0700
...
...
@@ -1368,7 +1373,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
)
...
...
@@ -1406,7 +1412,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
...
...
@@ -1468,7 +1474,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
...
...
@@ -1488,7 +1495,7 @@ def extract_wininst_cfg(dist_filename):
# unicode for the RawConfigParser, so decode it. Is this the
# right encoding?
config
=
config
.
decode
(
'ascii'
)
cfg
.
readfp
(
StringIO
.
StringIO
(
config
))
cfg
.
readfp
(
StringIO
(
config
))
except
ConfigParser
.
Error
:
return
None
if
not
cfg
.
has_section
(
'metadata'
)
or
not
cfg
.
has_section
(
'Setup'
):
...
...
@@ -1523,7 +1530,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
...
...
@@ -1556,11 +1563,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
=
[]
...
...
@@ -1688,8 +1696,8 @@ def auto_chmod(func, arg, exc):
if
func
is
os
.
remove
and
os
.
name
==
'nt'
:
chmod
(
arg
,
stat
.
S_IWRITE
)
return
func
(
arg
)
e
xc
=
sys
.
exc_info
()
r
aise
exc
[
0
],
(
exc
[
1
][
0
],
exc
[
1
][
1
]
+
(
" %s %s"
%
(
func
,
arg
)))
e
t
,
ev
,
_
=
sys
.
exc_info
()
r
eraise
(
et
,
(
ev
[
0
],
ev
[
1
]
+
(
" %s %s"
%
(
func
,
arg
)
)))
def
uncache_zipdir
(
path
):
"""Ensure that the importer caches dont have stale info for `path`"""
...
...
@@ -1789,7 +1797,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
):
...
...
@@ -1903,7 +1912,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
)
...
...
@@ -1916,7 +1925,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
)
...
...
@@ -1924,7 +1933,7 @@ def rmtree(path, ignore_errors=False, onerror=auto_chmod):
onerror
(
os
.
rmdir
,
path
,
sys
.
exc_info
())
def
current_umask
():
tmp
=
os
.
umask
(
0
22
)
tmp
=
os
.
umask
(
0
x12
)
# 022
os
.
umask
(
tmp
)
return
tmp
...
...
setuptools/command/egg_info.py
View file @
b59a01e0
...
...
@@ -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
as
_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
s
etuptools.command.s
dist
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
set
uptools.command.set
opt
import
edit_config
edit_config
(
filename
,
{
'egg_info'
:
...
...
@@ -225,7 +226,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
])
...
...
@@ -415,7 +416,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
):
...
...
setuptools/command/install_scripts.py
View file @
b59a01e0
...
...
@@ -50,5 +50,5 @@ class install_scripts(_install_scripts):
f
=
open
(
target
,
"w"
+
mode
)
f
.
write
(
contents
)
f
.
close
()
chmod
(
target
,
0
777
-
mask
)
chmod
(
target
,
0
x1FF
-
mask
)
# 0777
setuptools/command/rotate.py
View file @
b59a01e0
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
*
...
...
setuptools/command/saveopts.py
View file @
b59a01e0
...
...
@@ -9,10 +9,9 @@ class saveopts(option_base):
def
run
(
self
):
dist
=
self
.
distribution
commands
=
dist
.
command_options
.
keys
()
settings
=
{}
for
cmd
in
command
s
:
for
cmd
in
dist
.
command_option
s
:
if
cmd
==
'saveopts'
:
continue
# don't save our own options!
...
...
setuptools/command/sdist.py
View file @
b59a01e0
...
...
@@ -190,7 +190,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)
...
...
setuptools/command/setopt.py
View file @
b59a01e0
...
...
@@ -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
Raw
ConfigParser
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
:
...
...
setuptools/command/upload.py
View file @
b59a01e0
...
...
@@ -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
)
...
...
@@ -149,14 +148,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
...
...
@@ -169,7 +168,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
...
...
@@ -181,5 +181,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
)
setuptools/command/upload_docs.py
View file @
b59a01e0
...
...
@@ -8,8 +8,6 @@ PyPI's packages.python.org).
import
os
import
socket
import
zipfile
import
httplib
import
urlparse
import
tempfile
import
sys
import
shutil
...
...
@@ -25,6 +23,9 @@ try:
except
ImportError
:
from
setuptools.command.upload
import
upload
from
setuptools.compat
import
httplib
,
urlparse
_IS_PYTHON3
=
sys
.
version
>
'3'
# This is not just a replacement for byte literals
# but works as a general purpose encoder
...
...
@@ -154,7 +155,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
)
...
...
@@ -174,7 +175,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
...
...
@@ -192,4 +194,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
)
setuptools/compat.py
0 → 100644
View file @
b59a01e0
import
sys
import
itertools
if
sys
.
version_info
[
0
]
<
3
:
PY3
=
False
basestring
=
basestring
import
__builtin__
as
builtins
import
ConfigParser
from
StringIO
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
from
BaseHTTPServer
import
BaseHTTPRequestHandler
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
filterfalse
=
itertools
.
ifilterfalse
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"""
)
exec_
(
"""def reraise(tp, value, tb=None):
raise tp, value, tb"""
)
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
from
http.server
import
BaseHTTPRequestHandler
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
filterfalse
=
itertools
.
filterfalse
def
execfile
(
fn
,
globs
=
None
,
locs
=
None
):
if
globs
is
None
:
globs
=
globals
()
if
locs
is
None
:
locs
=
globs
f
=
open
(
fn
)
try
:
source
=
f
.
read
()
finally
:
f
.
close
()
exec_
(
compile
(
source
,
fn
,
'exec'
),
globs
,
locs
)
def
reraise
(
tp
,
value
,
tb
=
None
):
if
value
.
__traceback__
is
not
tb
:
raise
value
.
with_traceback
(
tb
)
raise
value
setuptools/depends.py
View file @
b59a01e0
...
...
@@ -36,7 +36,7 @@ class Require:
def
version_ok
(
self
,
version
):
"""Is 'version' sufficiently up-to-date?"""
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"
):
...
...
@@ -103,7 +103,7 @@ def _iter_code(code):
ptr
+=
3
if
op
==
EXTENDED_ARG
:
extended_arg
=
arg
*
65536L
extended_arg
=
arg
*
long_type
(
65536
)
continue
else
:
...
...
setuptools/dist.py
View file @
b59a01e0
__all__
=
[
'Distribution'
]
import
re
import
sys
from
distutils.core
import
Distribution
as
_Distribution
from
setuptools.depends
import
Require
from
setuptools.command.install
import
install
from
setuptools.command.sdist
import
sdist
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
DistutilsSetupError
import
setuptools
,
pkg_resources
,
distutils
.
core
,
distutils
.
dist
,
distutils
.
cmd
...
...
@@ -100,7 +102,8 @@ def check_entry_points(dist, attr, value):
"""Verify that entry_points map is parseable"""
try
:
pkg_resources
.
EntryPoint
.
parse_map
(
value
)
except
ValueError
,
e
:
except
ValueError
:
e
=
sys
.
exc_info
()[
1
]
raise
DistutilsSetupError
(
e
)
def
check_test_suite
(
dist
,
attr
,
value
):
...
...
@@ -223,7 +226,7 @@ class Distribution(_Distribution):
if
not
hasattr
(
self
,
ep
.
name
):
setattr
(
self
,
ep
.
name
,
None
)
_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 :)
self
.
metadata
.
version
=
str
(
self
.
metadata
.
version
)
...
...
@@ -527,7 +530,7 @@ class Distribution(_Distribution):
raise
DistutilsSetupError
(
"packages: setting must be a list or tuple (%r)"
%
(
packages
,)
)
map
(
self
.
exclude_package
,
packages
)
list
(
map
(
self
.
exclude_package
,
packages
)
)
...
...
setuptools/package_index.py
View file @
b59a01e0
This diff is collapsed.
Click to expand it.
setuptools/sandbox.py
View file @
b59a01e0
import
os
,
sys
,
__builtin__
,
tempfile
,
operator
,
pkg_resources
import
os
,
sys
,
tempfile
,
operator
,
pkg_resources
if
os
.
name
==
"java"
:
import
org.python.modules.posix.PosixModule
as
_os
else
:
...
...
@@ -9,6 +9,8 @@ except NameError:
_file
=
None
_open
=
open
from
distutils.errors
import
DistutilsError
from
setuptools.compat
import
builtins
,
execfile
,
reduce
__all__
=
[
"AbstractSandbox"
,
"DirectorySandbox"
,
"SandboxViolation"
,
"run_setup"
,
]
...
...
@@ -35,7 +37,8 @@ def run_setup(setup_script, args):
{
'__file__'
:
setup_script
,
'__name__'
:
'__main__'
}
)
)
except
SystemExit
,
v
:
except
SystemExit
:
v
=
sys
.
exc_info
()[
1
]
if
v
.
args
and
v
.
args
[
0
]:
raise
# Normal exit, just return
...
...
@@ -75,15 +78,15 @@ class AbstractSandbox:
try
:
self
.
_copy
(
self
)
if
_file
:
__builtin__
.
file
=
self
.
_file
__builtin__
.
open
=
self
.
_open
builtins
.
file
=
self
.
_file
builtins
.
open
=
self
.
_open
self
.
_active
=
True
return
func
()
finally
:
self
.
_active
=
False
if
_file
:
__builtin__
.
file
=
_file
__builtin__
.
open
=
_open
builtins
.
file
=
_file
builtins
.
open
=
_open
self
.
_copy
(
_os
)
...
...
@@ -234,7 +237,7 @@ class DirectorySandbox(AbstractSandbox):
self
.
_violation
(
operation
,
src
,
dst
,
*
args
,
**
kw
)
return
(
src
,
dst
)
def
open
(
self
,
file
,
flags
,
mode
=
0
777
):
def
open
(
self
,
file
,
flags
,
mode
=
0
x1FF
):
# 0777
"""Called for low-level os.open()"""
if
flags
&
WRITE_FLAGS
and
not
self
.
_ok
(
file
):
self
.
_violation
(
"os.open"
,
file
,
flags
,
mode
)
...
...
setuptools/tests/__init__.py
View file @
b59a01e0
...
...
@@ -9,6 +9,7 @@ from distutils.errors import DistutilsOptionError, DistutilsPlatformError
from
distutils.errors
import
DistutilsSetupError
from
distutils.core
import
Extension
from
distutils.version
import
LooseVersion
from
setuptools.compat
import
func_code
import
setuptools.dist
import
setuptools.depends
as
dep
...
...
@@ -53,17 +54,18 @@ class DependsTests(unittest.TestCase):
x
=
"test"
y
=
z
fc
=
func_code
(
f1
)
# unrecognized name
self
.
assertEqual
(
dep
.
extract_constant
(
f
1
.
func_code
,
'q'
,
-
1
),
None
)
self
.
assertEqual
(
dep
.
extract_constant
(
f
c
,
'q'
,
-
1
),
None
)
# constant assigned
self
.
assertEqual
(
dep
.
extract_constant
(
f
1
.
func_code
,
'x'
,
-
1
),
"test"
)
self
.
assertEqual
(
dep
.
extract_constant
(
f
c
,
'x'
,
-
1
),
"test"
)
# expression assigned
self
.
assertEqual
(
dep
.
extract_constant
(
f
1
.
func_code
,
'y'
,
-
1
),
-
1
)
self
.
assertEqual
(
dep
.
extract_constant
(
f
c
,
'y'
,
-
1
),
-
1
)
# recognized name, not assigned
self
.
assertEqual
(
dep
.
extract_constant
(
f
1
.
func_code
,
'z'
,
-
1
),
None
)
self
.
assertEqual
(
dep
.
extract_constant
(
f
c
,
'z'
,
-
1
),
None
)
def
testFindModule
(
self
):
self
.
assertRaises
(
ImportError
,
dep
.
find_module
,
'no-such.-thing'
)
...
...
setuptools/tests/doctest.py
View file @
b59a01e0
...
...
@@ -9,7 +9,7 @@
try
:
basestring
except
NameError
:
basestring
=
str
,
unicode
basestring
=
str
try
:
enumerate
...
...
@@ -109,7 +109,7 @@ import __future__
import
sys
,
traceback
,
inspect
,
linecache
,
os
,
re
,
types
import
unittest
,
difflib
,
pdb
,
tempfile
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
# module's tests.
...
...
@@ -240,7 +240,7 @@ def _normalize_module(module, depth=2):
"""
if
inspect
.
ismodule
(
module
):
return
module
elif
isinstance
(
module
,
(
str
,
unicode
)
):
elif
isinstance
(
module
,
basestring
):
return
__import__
(
module
,
globals
(),
locals
(),
[
"*"
])
elif
module
is
None
:
return
sys
.
modules
[
sys
.
_getframe
(
depth
).
f_globals
[
'__name__'
]]
...
...
@@ -367,9 +367,9 @@ class _OutputRedirectingPdb(pdb.Pdb):
# [XX] Normalize with respect to os.path.pardir?
def
_module_relative_path
(
module
,
path
):
if
not
inspect
.
ismodule
(
module
):
raise
TypeError
,
'Expected a module: %r'
%
module
raise
TypeError
(
'Expected a module: %r'
%
module
)
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.
if
hasattr
(
module
,
'__file__'
):
...
...
@@ -877,7 +877,7 @@ class DocTestFinder:
if
module
is
None
:
return
True
elif
inspect
.
isfunction
(
object
):
return
module
.
__dict__
is
object
.
func_globals
return
module
.
__dict__
is
func_globals
(
object
)
elif
inspect
.
isclass
(
object
):
return
module
.
__name__
==
object
.
__module__
elif
inspect
.
getmodule
(
object
)
is
not
None
:
...
...
@@ -895,7 +895,7 @@ class DocTestFinder:
add them to `tests`.
"""
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
id
(
obj
)
in
seen
:
...
...
@@ -948,7 +948,7 @@ class DocTestFinder:
if
isinstance
(
val
,
staticmethod
):
val
=
getattr
(
obj
,
valname
)
if
isinstance
(
val
,
classmethod
):
val
=
getattr
(
obj
,
valname
).
im_func
val
=
im_func
(
getattr
(
obj
,
valname
))
# Recurse to methods, properties, and nested classes.
if
((
inspect
.
isfunction
(
val
)
or
inspect
.
isclass
(
val
)
or
...
...
@@ -1020,8 +1020,8 @@ class DocTestFinder:
break
# Find the line number for functions & methods.
if
inspect
.
ismethod
(
obj
):
obj
=
obj
.
im_func
if
inspect
.
isfunction
(
obj
):
obj
=
obj
.
func_code
if
inspect
.
ismethod
(
obj
):
obj
=
im_func
(
obj
)
if
inspect
.
isfunction
(
obj
):
obj
=
func_code
(
obj
)
if
inspect
.
istraceback
(
obj
):
obj
=
obj
.
tb_frame
if
inspect
.
isframe
(
obj
):
obj
=
obj
.
f_code
if
inspect
.
iscode
(
obj
):
...
...
@@ -1250,8 +1250,8 @@ class DocTestRunner:
# keyboard interrupts.)
try
:
# Don't blink! This is where the user's code gets run.
exec
compile
(
example
.
source
,
filename
,
"single"
,
compileflags
,
1
)
in
test
.
globs
exec
_
(
compile
(
example
.
source
,
filename
,
"single"
,
compileflags
,
1
),
test
.
globs
)
self
.
debugger
.
set_continue
()
# ==== Example Finished ====
exception
=
None
except
KeyboardInterrupt
:
...
...
@@ -1335,7 +1335,7 @@ class DocTestRunner:
if
m
and
m
.
group
(
'name'
)
==
self
.
test
.
name
:
example
=
self
.
test
.
examples
[
int
(
m
.
group
(
'examplenum'
))]
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
)
else
:
return
self
.
save_linecache_getlines
(
filename
)
...
...
@@ -1427,28 +1427,28 @@ class DocTestRunner:
failed
.
append
(
x
)
if
verbose
:
if
notests
:
print
len
(
notests
),
"items had no tests:"
print
(
len
(
notests
),
"items had no tests:"
)
notests
.
sort
()
for
thing
in
notests
:
print
" "
,
thing
print
(
" "
,
thing
)
if
passed
:
print
len
(
passed
),
"items passed all tests:"
print
(
len
(
passed
),
"items passed all tests:"
)
passed
.
sort
()
for
thing
,
count
in
passed
:
print
" %3d tests in %s"
%
(
count
,
thing
)
print
(
" %3d tests in %s"
%
(
count
,
thing
)
)
if
failed
:
print
self
.
DIVIDER
print
len
(
failed
),
"items had failures:"
print
(
self
.
DIVIDER
)
print
(
len
(
failed
),
"items had failures:"
)
failed
.
sort
()
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
:
print
totalt
,
"tests in"
,
len
(
self
.
_name2ft
),
"items."
print
totalt
-
totalf
,
"passed and"
,
totalf
,
"failed."
print
(
totalt
,
"tests in"
,
len
(
self
.
_name2ft
),
"items."
)
print
(
totalt
-
totalf
,
"passed and"
,
totalf
,
"failed."
)
if
totalf
:
print
"***Test Failed***"
,
totalf
,
"failures."
print
(
"***Test Failed***"
,
totalf
,
"failures."
)
elif
verbose
:
print
"Test passed."
print
(
"Test passed."
)
return
totalf
,
totalt
#/////////////////////////////////////////////////////////////////
...
...
@@ -1458,8 +1458,8 @@ class DocTestRunner:
d
=
self
.
_name2ft
for
name
,
(
f
,
t
)
in
other
.
_name2ft
.
items
():
if
name
in
d
:
print
"*** DocTestRunner.merge: '"
+
name
+
"' in both"
\
" testers; summing outcomes."
print
(
"*** DocTestRunner.merge: '"
+
name
+
"' in both"
\
" testers; summing outcomes."
)
f2
,
t2
=
d
[
name
]
f
=
f
+
f2
t
=
t
+
t2
...
...
@@ -2039,10 +2039,10 @@ class Tester:
def
runstring
(
self
,
s
,
name
):
test
=
DocTestParser
().
get_doctest
(
s
,
self
.
globs
,
name
,
None
,
None
)
if
self
.
verbose
:
print
"Running string"
,
name
print
(
"Running string"
,
name
)
(
f
,
t
)
=
self
.
testrunner
.
run
(
test
)
if
self
.
verbose
:
print
f
,
"of"
,
t
,
"examples failed in string"
,
name
print
(
f
,
"of"
,
t
,
"examples failed in string"
,
name
)
return
(
f
,
t
)
def
rundoc
(
self
,
object
,
name
=
None
,
module
=
None
):
...
...
@@ -2556,7 +2556,7 @@ def debug_script(src, pm=False, globs=None):
try
:
execfile
(
srcfilename
,
globs
,
globs
)
except
:
print
sys
.
exc_info
()[
1
]
print
(
sys
.
exc_info
()[
1
])
pdb
.
post_mortem
(
sys
.
exc_info
()[
2
])
else
:
# Note that %r is vital here. '%s' instead can, e.g., cause
...
...
setuptools/tests/server.py
View file @
b59a01e0
"""Basic http server for tests to simulate PyPI or custom indexes
"""
import
urllib2
import
sys
import
time
import
threading
import
BaseHTTPServ
er
from
BaseHTTPServer
import
HTTPServer
from
SimpleHTTPServer
import
SimpleHTTPRequestHandler
from
setuptools.compat
import
BaseHTTPRequestHandl
er
from
setuptools.compat
import
(
urllib2
,
URLError
,
HTTPServer
,
SimpleHTTPRequestHandler
)
class
IndexServer
(
HTTPServer
):
"""Basic single-threaded http server simulating a package index
...
...
@@ -48,16 +47,17 @@ class IndexServer(HTTPServer):
urllib2
.
urlopen
(
url
,
timeout
=
5
)
else
:
urllib2
.
urlopen
(
url
)
except
urllib2
.
URLError
:
except
URLError
:
# ignore any errors; all that's important is the request
pass
self
.
thread
.
join
()
self
.
socket
.
close
()
def
base_url
(
self
):
port
=
self
.
server_port
return
'http://127.0.0.1:%s/setuptools/tests/indexes/'
%
port
class
RequestRecorder
(
BaseHTTP
Server
.
BaseHTTP
RequestHandler
):
class
RequestRecorder
(
BaseHTTPRequestHandler
):
def
do_GET
(
self
):
requests
=
vars
(
self
.
server
).
setdefault
(
'requests'
,
[])
requests
.
append
(
self
)
...
...
setuptools/tests/test_bdist_egg.py
View file @
b59a01e0
...
...
@@ -4,9 +4,9 @@ import sys
import
os
,
re
,
shutil
,
tempfile
,
unittest
import
tempfile
import
site
from
StringIO
import
StringIO
from
distutils.errors
import
DistutilsError
from
setuptools.compat
import
StringIO
from
setuptools.command.bdist_egg
import
bdist_egg
from
setuptools.command
import
easy_install
as
easy_install_pkg
from
setuptools.dist
import
Distribution
...
...
setuptools/tests/test_develop.py
View file @
b59a01e0
...
...
@@ -4,11 +4,11 @@ import sys
import
os
,
shutil
,
tempfile
,
unittest
import
tempfile
import
site
from
StringIO
import
StringIO
from
distutils.errors
import
DistutilsError
from
setuptools.command.develop
import
develop
from
setuptools.command
import
easy_install
as
easy_install_pkg
from
setuptools.compat
import
StringIO
from
setuptools.dist
import
Distribution
SETUP_PY
=
"""
\
...
...
@@ -43,7 +43,7 @@ class TestDevelopTest(unittest.TestCase):
f
=
open
(
init
,
'w'
)
f
.
write
(
INIT_PY
)
f
.
close
()
os
.
chdir
(
self
.
dir
)
self
.
old_base
=
site
.
USER_BASE
site
.
USER_BASE
=
tempfile
.
mkdtemp
()
...
...
@@ -53,7 +53,7 @@ class TestDevelopTest(unittest.TestCase):
def
tearDown
(
self
):
if
sys
.
version
<
"2.6"
or
hasattr
(
sys
,
'real_prefix'
):
return
os
.
chdir
(
self
.
old_cwd
)
shutil
.
rmtree
(
self
.
dir
)
shutil
.
rmtree
(
site
.
USER_BASE
)
...
...
@@ -90,11 +90,15 @@ class TestDevelopTest(unittest.TestCase):
# Check that we are using the right code.
egg_link_file
=
open
(
os
.
path
.
join
(
site
.
USER_SITE
,
'foo.egg-link'
),
'rt'
)
path
=
egg_link_file
.
read
().
split
()[
0
].
strip
()
egg_link_file
.
close
()
try
:
path
=
egg_link_file
.
read
().
split
()[
0
].
strip
()
finally
:
egg_link_file
.
close
()
init_file
=
open
(
os
.
path
.
join
(
path
,
'foo'
,
'__init__.py'
),
'rt'
)
init
=
init_file
.
read
().
strip
()
init_file
.
close
()
try
:
init
=
init_file
.
read
().
strip
()
finally
:
init_file
.
close
()
if
sys
.
version
<
"3"
:
self
.
assertEqual
(
init
,
'print "foo"'
)
else
:
...
...
@@ -109,10 +113,10 @@ class TestDevelopTest(unittest.TestCase):
try
:
try
:
dist
=
Distribution
({
'setup_requires'
:
[
'I_DONT_EXIST'
]})
except
DistutilsError
,
e
:
except
DistutilsError
:
e
=
sys
.
exc_info
()[
1
]
error
=
str
(
e
)
if
error
==
wanted
:
pass
finally
:
os
.
chdir
(
old_dir
)
setuptools/tests/test_dist_info.py
View file @
b59a01e0
...
...
@@ -51,30 +51,33 @@ class TestDistInfo(unittest.TestCase):
'VersionedDistribution-2.718.dist-info'
)
os
.
mkdir
(
versioned
)
metadata_file
=
open
(
os
.
path
.
join
(
versioned
,
'METADATA'
),
'w+'
)
metadata_file
.
write
(
DALS
(
"""
Metadata-Version: 1.2
Name: VersionedDistribution
Requires-Dist: splort (4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
"""
))
metadata_file
.
close
()
try
:
metadata_file
.
write
(
DALS
(
"""
Metadata-Version: 1.2
Name: VersionedDistribution
Requires-Dist: splort (4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
"""
))
finally
:
metadata_file
.
close
()
unversioned
=
os
.
path
.
join
(
self
.
tmpdir
,
'UnversionedDistribution.dist-info'
)
os
.
mkdir
(
unversioned
)
metadata_file
=
open
(
os
.
path
.
join
(
unversioned
,
'METADATA'
),
'w+'
)
metadata_file
.
write
(
DALS
(
"""
Metadata-Version: 1.2
Name: UnversionedDistribution
Version: 0.3
Requires-Dist: splort (==4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
"""
))
metadata_file
.
close
()
try
:
metadata_file
.
write
(
DALS
(
"""
Metadata-Version: 1.2
Name: UnversionedDistribution
Version: 0.3
Requires-Dist: splort (==4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
"""
))
finally
:
metadata_file
.
close
()
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
tmpdir
)
setuptools/tests/test_easy_install.py
View file @
b59a01e0
...
...
@@ -6,10 +6,10 @@ import shutil
import
tempfile
import
unittest
import
site
from
setuptools.compat
import
StringIO
,
BytesIO
,
next
from
setuptools.compat
import
urlparse
import
textwrap
import
tarfile
import
urlparse
import
StringIO
import
distutils.core
from
setuptools.sandbox
import
run_setup
,
SandboxViolation
...
...
@@ -78,7 +78,7 @@ class TestEasyInstallTest(unittest.TestCase):
old_platform
=
sys
.
platform
try
:
name
,
script
=
[
i
for
i
in
get_script_args
(
dist
).
next
(
)][
0
:
2
]
name
,
script
=
[
i
for
i
in
next
(
get_script_args
(
dist
)
)][
0
:
2
]
finally
:
sys
.
platform
=
old_platform
...
...
@@ -139,8 +139,7 @@ class TestEasyInstallTest(unittest.TestCase):
cmd
.
install_dir
=
os
.
path
.
join
(
tempfile
.
mkdtemp
(),
'ok'
)
cmd
.
args
=
[
'ok'
]
cmd
.
ensure_finalized
()
keys
=
cmd
.
package_index
.
scanned_urls
.
keys
()
keys
.
sort
()
keys
=
sorted
(
cmd
.
package_index
.
scanned_urls
.
keys
())
self
.
assertEqual
(
keys
,
[
'link1'
,
'link2'
])
...
...
@@ -304,8 +303,8 @@ class TestUserInstallTest(unittest.TestCase):
old_stdout
=
sys
.
stdout
old_stderr
=
sys
.
stderr
sys
.
stdout
=
StringIO
.
StringIO
()
sys
.
stderr
=
StringIO
.
StringIO
()
sys
.
stdout
=
StringIO
()
sys
.
stderr
=
StringIO
()
try
:
reset_setup_stop_context
(
lambda
:
run_setup
(
test_setup_py
,
[
'install'
])
...
...
@@ -329,7 +328,7 @@ class TestSetupRequires(unittest.TestCase):
p_index
=
setuptools
.
tests
.
server
.
MockServer
()
p_index
.
start
()
netloc
=
1
p_index_loc
=
urlparse
.
urlparse
(
p_index
.
url
)[
netloc
]
p_index_loc
=
urlparse
(
p_index
.
url
)[
netloc
]
if
p_index_loc
.
endswith
(
':0'
):
# Some platforms (Jython) don't find a port to which to bind,
# so skip this test for them.
...
...
@@ -396,9 +395,9 @@ def make_trivial_sdist(dist_path, setup_py):
setup_py_file
=
tarfile
.
TarInfo
(
name
=
'setup.py'
)
try
:
# Python 3 (StringIO gets converted to io module)
MemFile
=
StringIO
.
BytesIO
MemFile
=
BytesIO
except
AttributeError
:
MemFile
=
StringIO
.
StringIO
MemFile
=
StringIO
setup_py_bytes
=
MemFile
(
setup_py
.
encode
(
'utf-8'
))
setup_py_file
.
size
=
len
(
setup_py_bytes
.
getvalue
())
dist
=
tarfile
.
open
(
dist_path
,
'w:gz'
)
...
...
setuptools/tests/test_packageindex.py
View file @
b59a01e0
...
...
@@ -2,12 +2,11 @@
"""
import
sys
import
unittest
import
urllib2
import
pkg_resources
import
httplib
from
setuptools.compat
import
urllib2
,
httplib
,
HTTPError
,
unicode
import
distutils.errors
import
setuptools.package_index
from
server
import
IndexServer
from
se
tuptools.tests.se
rver
import
IndexServer
class
TestPackageIndex
(
unittest
.
TestCase
):
...
...
@@ -16,10 +15,11 @@ class TestPackageIndex(unittest.TestCase):
url
=
'http://127.0.0.1:0/nonesuch/test_package_index'
try
:
v
=
index
.
open_url
(
url
)
except
Exception
,
v
:
except
Exception
:
v
=
sys
.
exc_info
()[
1
]
self
.
assertTrue
(
url
in
str
(
v
))
else
:
self
.
assertTrue
(
isinstance
(
v
,
urllib2
.
HTTPError
))
self
.
assertTrue
(
isinstance
(
v
,
HTTPError
))
def
test_bad_url_typo
(
self
):
# issue 16
...
...
@@ -32,10 +32,11 @@ class TestPackageIndex(unittest.TestCase):
url
=
'url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunk'
try
:
v
=
index
.
open_url
(
url
)
except
Exception
,
v
:
except
Exception
:
v
=
sys
.
exc_info
()[
1
]
self
.
assertTrue
(
url
in
str
(
v
))
else
:
self
.
assertTrue
(
isinstance
(
v
,
urllib2
.
HTTPError
))
self
.
assertTrue
(
isinstance
(
v
,
HTTPError
))
def
test_bad_url_bad_status_line
(
self
):
index
=
setuptools
.
package_index
.
PackageIndex
(
...
...
@@ -43,7 +44,6 @@ class TestPackageIndex(unittest.TestCase):
)
def
_urlopen
(
*
args
):
import
httplib
raise
httplib
.
BadStatusLine
(
'line'
)
old_urlopen
=
urllib2
.
urlopen
...
...
@@ -52,7 +52,8 @@ class TestPackageIndex(unittest.TestCase):
try
:
try
:
v
=
index
.
open_url
(
url
)
except
Exception
,
v
:
except
Exception
:
v
=
sys
.
exc_info
()[
1
]
self
.
assertTrue
(
'line'
in
str
(
v
))
else
:
raise
AssertionError
(
'Should have raise here!'
)
...
...
@@ -71,7 +72,8 @@ class TestPackageIndex(unittest.TestCase):
url
=
'http://http://svn.pythonpaste.org/Paste/wphp/trunk'
try
:
index
.
open_url
(
url
)
except
distutils
.
errors
.
DistutilsError
,
error
:
except
distutils
.
errors
.
DistutilsError
:
error
=
sys
.
exc_info
()[
1
]
msg
=
unicode
(
error
)
assert
'nonnumeric port'
in
msg
or
'getaddrinfo failed'
in
msg
or
'Name or service not known'
in
msg
return
...
...
setuptools/tests/test_resources.py
View file @
b59a01e0
...
...
@@ -3,7 +3,8 @@
# NOTE: the shebang and encoding lines are for ScriptHeaderTests; do not remove
from
unittest
import
TestCase
,
makeSuite
;
from
pkg_resources
import
*
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
except
NameError
:
from
sets
import
ImmutableSet
as
frozenset
...
...
@@ -149,7 +150,7 @@ class DistroTests(TestCase):
for
i
in
range
(
3
):
targets
=
list
(
ws
.
resolve
(
parse_requirements
(
"Foo"
),
ad
))
self
.
assertEqual
(
targets
,
[
Foo
])
map
(
ws
.
add
,
targets
)
list
(
map
(
ws
.
add
,
targets
)
)
self
.
assertRaises
(
VersionConflict
,
ws
.
resolve
,
parse_requirements
(
"Foo==0.9"
),
ad
)
ws
=
WorkingSet
([])
# reset
...
...
@@ -272,7 +273,7 @@ class EntryPointTests(TestCase):
def
checkSubMap
(
self
,
m
):
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
))
submap_expect
=
dict
(
...
...
@@ -296,10 +297,10 @@ class EntryPointTests(TestCase):
def
testParseMap
(
self
):
m
=
EntryPoint
.
parse_map
({
'xyz'
:
self
.
submap_str
})
self
.
checkSubMap
(
m
[
'xyz'
])
self
.
assertEqual
(
m
.
keys
(
),[
'xyz'
])
self
.
assertEqual
(
list
(
m
.
keys
()
),[
'xyz'
])
m
=
EntryPoint
.
parse_map
(
"[xyz]
\
n
"
+
self
.
submap_str
)
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
,
self
.
submap_str
)
...
...
@@ -568,12 +569,12 @@ class ScriptHeaderTests(TestCase):
# Ensure we generate what is basically a broken shebang line
# 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'
,
executable
=
exe
),
'#!%s -x
\
n
'
%
exe
)
self
.
assertTrue
(
'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'
,
executable
=
self
.
non_ascii_exe
),
'#!%s -x
\
n
'
%
self
.
non_ascii_exe
)
...
...
@@ -633,7 +634,7 @@ class NamespaceTests(TestCase):
self
.
_assertIn
(
"pkg1"
,
pkg_resources
.
_namespace_packages
.
keys
())
try
:
import
pkg1.pkg2
except
ImportError
,
e
:
except
ImportError
:
self
.
fail
(
"Distribute tried to import the parent namespace package"
)
# check the _namespace_packages dict
self
.
_assertIn
(
"pkg1.pkg2"
,
pkg_resources
.
_namespace_packages
.
keys
())
...
...
setuptools/tests/test_sdist.py
View file @
b59a01e0
...
...
@@ -7,11 +7,9 @@ import shutil
import
sys
import
tempfile
import
unittest
import
urllib
import
unicodedata
from
StringIO
import
StringIO
from
setuptools.compat
import
StringIO
,
unicode
from
setuptools.command.sdist
import
sdist
from
setuptools.command.egg_info
import
manifest_maker
from
setuptools.dist
import
Distribution
...
...
@@ -57,7 +55,7 @@ def b(s, encoding='utf-8'):
# Convert to POSIX path
def
posix
(
path
):
if
sys
.
version_info
>=
(
3
,)
and
not
isinstance
(
path
,
unicode
):
if
sys
.
version_info
>=
(
3
,)
and
not
isinstance
(
path
,
str
):
return
path
.
replace
(
os
.
sep
.
encode
(
'ascii'
),
b
(
'/'
))
else
:
return
path
.
replace
(
os
.
sep
,
'/'
)
...
...
@@ -149,7 +147,8 @@ class TestSdistTest(unittest.TestCase):
# The manifest should be UTF-8 encoded
try
:
u_contents
=
contents
.
decode
(
'UTF-8'
)
except
UnicodeDecodeError
,
e
:
except
UnicodeDecodeError
:
e
=
sys
.
exc_info
()[
1
]
self
.
fail
(
e
)
# The manifest should contain the UTF-8 filename
...
...
@@ -190,7 +189,8 @@ class TestSdistTest(unittest.TestCase):
# The manifest should be UTF-8 encoded
try
:
contents
.
decode
(
'UTF-8'
)
except
UnicodeDecodeError
,
e
:
except
UnicodeDecodeError
:
e
=
sys
.
exc_info
()[
1
]
self
.
fail
(
e
)
# The manifest should contain the UTF-8 filename
...
...
@@ -228,7 +228,8 @@ class TestSdistTest(unittest.TestCase):
# The manifest should be UTF-8 encoded
try
:
contents
.
decode
(
'UTF-8'
)
except
UnicodeDecodeError
,
e
:
except
UnicodeDecodeError
:
e
=
sys
.
exc_info
()[
1
]
self
.
fail
(
e
)
# The Latin-1 filename should have been skipped
...
...
@@ -307,7 +308,8 @@ class TestSdistTest(unittest.TestCase):
try
:
try
:
cmd
.
read_manifest
()
except
UnicodeDecodeError
,
e
:
except
UnicodeDecodeError
:
e
=
sys
.
exc_info
()[
1
]
self
.
fail
(
e
)
finally
:
unquiet
()
...
...
@@ -339,7 +341,7 @@ class TestSdistTest(unittest.TestCase):
if
sys
.
version_info
>=
(
3
,):
fs_enc
=
sys
.
getfilesystemencoding
()
if
sys
.
platform
==
'win32'
:
if
sys
.
platform
==
'win32'
:
if
fs_enc
==
'cp1252'
:
# Python 3 mangles the UTF-8 filename
filename
=
filename
.
decode
(
'cp1252'
)
...
...
@@ -374,14 +376,14 @@ class TestSdistTest(unittest.TestCase):
if
sys
.
version_info
>=
(
3
,):
#not all windows systems have a default FS encoding of cp1252
if
sys
.
platform
==
'win32'
:
# Latin-1 is similar to Windows-1252 however
# Latin-1 is similar to Windows-1252 however
# on mbcs filesys it is not in latin-1 encoding
fs_enc
=
sys
.
getfilesystemencoding
()
if
fs_enc
==
'mbcs'
:
filename
=
filename
.
decode
(
'mbcs'
)
else
:
filename
=
filename
.
decode
(
'latin-1'
)
self
.
assertTrue
(
filename
in
cmd
.
filelist
.
files
)
else
:
# The Latin-1 filename should have been skipped
...
...
setuptools/tests/test_test.py
View file @
b59a01e0
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
"""develop tests
"""
...
...
@@ -6,9 +6,9 @@ import sys
import
os
,
shutil
,
tempfile
,
unittest
import
tempfile
import
site
from
StringIO
import
StringIO
from
distutils.errors
import
DistutilsError
from
setuptools.compat
import
StringIO
from
setuptools.command.test
import
test
from
setuptools.command
import
easy_install
as
easy_install_pkg
from
setuptools.dist
import
Distribution
...
...
@@ -23,7 +23,7 @@ setup(name='foo',
)
"""
NS_INIT
=
"""# -*- coding: Latin-1 -*-
NS_INIT
=
"""# -*- coding: Latin-1 -*-
# Söme Arbiträry Ünicode to test Issüé 310
try:
__import__('pkg_resources').declare_namespace(__name__)
...
...
@@ -77,7 +77,7 @@ class TestTestTest(unittest.TestCase):
f
=
open
(
init
,
'wt'
)
f
.
write
(
TEST_PY
)
f
.
close
()
os
.
chdir
(
self
.
dir
)
self
.
old_base
=
site
.
USER_BASE
site
.
USER_BASE
=
tempfile
.
mkdtemp
()
...
...
@@ -87,7 +87,7 @@ class TestTestTest(unittest.TestCase):
def
tearDown
(
self
):
if
sys
.
version
<
"2.6"
or
hasattr
(
sys
,
'real_prefix'
):
return
os
.
chdir
(
self
.
old_cwd
)
shutil
.
rmtree
(
self
.
dir
)
shutil
.
rmtree
(
site
.
USER_BASE
)
...
...
@@ -98,7 +98,7 @@ class TestTestTest(unittest.TestCase):
def
test_test
(
self
):
if
sys
.
version
<
"2.6"
or
hasattr
(
sys
,
'real_prefix'
):
return
dist
=
Distribution
(
dict
(
name
=
'foo'
,
packages
=
[
'name'
,
'name.space'
,
'name.space.tests'
],
...
...
@@ -121,4 +121,4 @@ class TestTestTest(unittest.TestCase):
pass
finally
:
sys
.
stdout
=
old_stdout
\ No newline at end of file
setuptools/tests/win_script_wrapper.txt
View file @
b59a01e0
...
...
@@ -49,37 +49,16 @@ GUI programs, the suffix '-script-pyw' is added.) This is why we
named out script the way we did. Now we can run out script by running
the wrapper:
>>> from subprocess import Popen, PIPE, STDOUT
>>> try:
... unicode=unicode
... except:
... unicode=str
>>> def popen4(cmd, *args):
... if hasattr(os, 'popen4'):
... input, output = os.popen4(cmd + " ".join(args))
... return input, output
... else:
... #emulate popen4 in python 3
... if cmd[0] == '"' and cmd[-1] != '"':
... cmd = cmd[1:]
... cmd += " ".join(args)
... p = Popen(cmd, shell=True, bufsize=0,
... stdin=PIPE, stdout=PIPE, stderr=STDOUT)
... return p.stdin, p.stdout
>>> input, output = popen4('"' + nt_quote_arg(os.path.join(sample_directory, 'foo.exe')),
... r' arg1', r'"arg 2"', r'"arg \"2\\\""', r'"arg 4\\"', r'"arg5 a\\b"')
>>> bytes_written = input.write('hello\nworld\n'.encode('utf-8'))
>>> input.close()
>>> # This is needed for line ending differences between py2 and py3 on win32
>>> msg = unicode(output.read(), encoding='utf-8').split("\n")
>>> for line in msg:
... print(line.strip())
>>> import subprocess
>>> cmd = [os.path.join(sample_directory, 'foo.exe'), 'arg1', 'arg 2',
... 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
>>> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
>>> stdout, stderr = proc.communicate('hello\nworld\n'.encode('ascii'))
>>> bytes = sys.stdout.write(stdout.decode('ascii').replace('\r\n', '\n'))
\foo-script.py
['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
'hello\nworld\n'
non-optimized
<BLANKLINE>
This example was a little pathological in that it exercised windows
(MS C runtime) quoting rules:
...
...
@@ -115,18 +94,14 @@ enter the interpreter after running the script, you could use -Oi:
... sys.ps1 = '---'
... """ % dict(python_exe=nt_quote_arg(sys.executable)))
>>> f.close()
>>> input, output = popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe')))
>>> input.close()
>>> # This is needed for line ending differences between py2 and py3 on win32
>>> msg = unicode(output.read(), encoding='utf-8').split("\n")
>>> for line in msg:
... print(line.strip())
>>> cmd = [os.path.join(sample_directory, 'foo.exe')]
>>> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
>>> stdout, stderr = proc.communicate()
>>> bytes = sys.stdout.write(stdout.decode('ascii').replace('\r\n', '\n'))
\foo-script.py
[]
''
---
<BLANKLINE>
Testing the GUI Version
-----------------------
...
...
@@ -157,18 +132,19 @@ We'll also copy gui.exe to the sample-directory with the name bar.exe:
Finally, we'll run the script and check the result:
>>> input, output = popen4('"'+nt_quote_arg(os.path.join(sample_directory, 'bar.exe')),
... r' "%s" "Test Argument"' % os.path.join(sample_directory, 'test_output.txt'))
>>> input.close()
>>> # This is needed for line ending differences between py2 and py3 on win32
>>> msg = unicode(output.read(), encoding='utf-8').split("\n")
>>> for line in msg:
... print(line.strip())
>>> cmd = [
... os.path.join(sample_directory, 'bar.exe'),
... os.path.join(sample_directory, 'test_output.txt'),
... 'Test Argument',
... ]
>>> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
>>> stdout, stderr = proc.communicate()
>>> print(stdout.decode('ascii'))
<BLANKLINE>
>>> f = open(os.path.join(sample_directory, 'test_output.txt'), 'rb')
>>> print(
unicode(f.read(), encoding='utf-8
'))
>>> f
_out
= open(os.path.join(sample_directory, 'test_output.txt'), 'rb')
>>> print(
f_out.read().decode('ascii
'))
'Test Argument'
>>> f.close()
>>> f
_out
.close()
We're done with the sample_directory:
...
...
tests/api_tests.txt
View file @
b59a01e0
...
...
@@ -39,7 +39,7 @@ Distributions have various introspectable attributes::
>>> dist.py_version == sys.version[:3]
True
>>> print
dist.platform
>>> print
(dist.platform)
None
Including various computed attributes::
...
...
@@ -199,7 +199,7 @@ shows up once when iterating the working set:
You can ask a WorkingSet to ``find()`` a distribution matching a requirement::
>>> from pkg_resources import Requirement
>>> print
ws.find(Requirement.parse("Foo==1.0"))
# no match, return None
>>> print
(ws.find(Requirement.parse("Foo==1.0")))
# no match, return None
None
>>> ws.find(Requirement.parse("Bar==0.9")) # match, return distribution
...
...
@@ -211,7 +211,7 @@ working set triggers a ``pkg_resources.VersionConflict`` error:
>>> try:
... ws.find(Requirement.parse("Bar==1.0"))
... except VersionConflict:
... print
'ok'
... print
('ok')
ok
You can subscribe a callback function to receive notifications whenever a new
...
...
@@ -219,7 +219,7 @@ distribution is added to a working set. The callback is immediately invoked
once for each existing distribution in the working set, and then is called
again for new distributions added thereafter::
>>> def added(dist): print
"Added", dist
>>> def added(dist): print
("Added %s" % dist)
>>> ws.subscribe(added)
Added Bar 0.9
>>> foo12 = Distribution(project_name="Foo", version="1.2", location="f12")
...
...
tests/install_test.py
View file @
b59a01e0
import
urllib2
import
sys
import
os
from
setuptools.compat
import
urllib2
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
)
print
'**** Starting Test'
print
'
\
n
\
n
'
print
(
'**** Starting Test'
)
print
(
'
\
n
\
n
'
)
is_jython
=
sys
.
platform
.
startswith
(
'java'
)
if
is_jython
:
import
subprocess
print
'Downloading bootstrap'
print
(
'Downloading bootstrap'
)
file
=
urllib2
.
urlopen
(
'http://nightly.ziade.org/distribute_setup.py'
)
f
=
open
(
'distribute_setup.py'
,
'w'
)
f
.
write
(
file
.
read
())
...
...
@@ -27,7 +27,7 @@ else:
res
=
os
.
spawnv
(
os
.
P_WAIT
,
sys
.
executable
,
args
)
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'
)
sys
.
exit
(
2
)
...
...
@@ -63,11 +63,11 @@ try:
else
:
res
=
os
.
spawnv
(
os
.
P_WAIT
,
sys
.
executable
,
args
)
print
'
\
n
\
n
'
print
(
'
\
n
\
n
'
)
if
res
:
print
'**** Test is OK'
print
(
'**** Test is OK'
)
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
:
if
os
.
path
.
exists
(
script_name
):
os
.
remove
(
script_name
)
...
...
tests/manual_test.py
View file @
b59a01e0
...
...
@@ -9,7 +9,7 @@ import shutil
import
tempfile
from
distutils.command.install
import
INSTALL_SCHEMES
from
string
import
Template
from
urllib2
import
urlopen
from
setuptools.compat
import
urlopen
try
:
import
subprocess
...
...
tests/test_distribute_setup.py
View file @
b59a01e0
...
...
@@ -17,7 +17,7 @@ import distribute_setup
class
TestSetup
(
unittest
.
TestCase
):
def
urlopen
(
self
,
url
):
return
open
(
self
.
tarball
)
return
open
(
self
.
tarball
,
'rb'
)
def
setUp
(
self
):
self
.
old_sys_path
=
copy
.
copy
(
sys
.
path
)
...
...
@@ -28,7 +28,7 @@ class TestSetup(unittest.TestCase):
"--dist-dir"
,
"%s"
%
self
.
tmpdir
)
tarball
=
os
.
listdir
(
self
.
tmpdir
)[
0
]
self
.
tarball
=
os
.
path
.
join
(
self
.
tmpdir
,
tarball
)
import
urllib2
from
setuptools.compat
import
urllib2
urllib2
.
urlopen
=
self
.
urlopen
def
tearDown
(
self
):
...
...
@@ -38,7 +38,7 @@ class TestSetup(unittest.TestCase):
def
test_build_egg
(
self
):
# 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
sys
.
path
[
0
]
=
egg
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment