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
8567ca65
Commit
8567ca65
authored
May 17, 2014
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use PY3 and PY2 throughout
parent
3c85da71
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
44 additions
and
43 deletions
+44
-43
setuptools/command/develop.py
setuptools/command/develop.py
+5
-3
setuptools/command/easy_install.py
setuptools/command/easy_install.py
+5
-5
setuptools/command/egg_info.py
setuptools/command/egg_info.py
+1
-1
setuptools/command/sdist.py
setuptools/command/sdist.py
+2
-1
setuptools/command/test.py
setuptools/command/test.py
+4
-5
setuptools/dist.py
setuptools/dist.py
+2
-2
setuptools/svn_utils.py
setuptools/svn_utils.py
+9
-9
setuptools/tests/test_resources.py
setuptools/tests/test_resources.py
+2
-3
setuptools/tests/test_sdist.py
setuptools/tests/test_sdist.py
+12
-12
setuptools/tests/test_test.py
setuptools/tests/test_test.py
+2
-2
No files found.
setuptools/command/develop.py
View file @
8567ca65
...
...
@@ -5,6 +5,8 @@ from distutils import log
from
distutils.errors
import
DistutilsError
,
DistutilsOptionError
import
os
,
sys
,
setuptools
,
glob
from
setuptools.compat
import
PY3
class
develop
(
easy_install
):
"""Set up package for development"""
...
...
@@ -84,7 +86,7 @@ class develop(easy_install):
" installation directory"
,
p
,
normalize_path
(
os
.
curdir
))
def
install_for_development
(
self
):
if
sys
.
version_info
>=
(
3
,)
and
getattr
(
self
.
distribution
,
'use_2to3'
,
False
):
if
PY3
and
getattr
(
self
.
distribution
,
'use_2to3'
,
False
):
# If we run 2to3 we can not do this inplace:
# Ensure metadata is up-to-date
...
...
@@ -99,7 +101,7 @@ class develop(easy_install):
self
.
reinitialize_command
(
'build_ext'
,
inplace
=
0
)
self
.
run_command
(
'build_ext'
)
# Fixup egg-link and easy-install.pth
ei_cmd
=
self
.
get_finalized_command
(
"egg_info"
)
self
.
egg_path
=
build_path
...
...
@@ -112,7 +114,7 @@ class develop(easy_install):
# Build extensions in-place
self
.
reinitialize_command
(
'build_ext'
,
inplace
=
1
)
self
.
run_command
(
'build_ext'
)
self
.
install_site_py
()
# ensure that target dir is site-safe
if
setuptools
.
bootstrap_install_from
:
self
.
easy_install
(
setuptools
.
bootstrap_install_from
)
...
...
setuptools/command/easy_install.py
View file @
8567ca65
...
...
@@ -47,7 +47,7 @@ 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
,
basestring
,
unicode
,
reraise
)
reraise
,
PY2
,
PY3
)
from
pkg_resources
import
(
yield_lines
,
normalize_path
,
resource_string
,
ensure_directory
,
get_distribution
,
find_distributions
,
Environment
,
Requirement
,
...
...
@@ -75,7 +75,7 @@ def samefile(p1, p2):
norm_p2
=
os
.
path
.
normpath
(
os
.
path
.
normcase
(
p2
))
return
norm_p1
==
norm_p2
if
sys
.
version_info
<=
(
3
,)
:
if
PY2
:
def
_to_ascii
(
s
):
return
s
def
isascii
(
s
):
...
...
@@ -1187,7 +1187,7 @@ Please make the appropriate changes for your system and try again."""
f
=
open
(
sitepy
,
'rb'
)
current
=
f
.
read
()
# we want str, not bytes
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
current
=
current
.
decode
()
f
.
close
()
...
...
@@ -1409,7 +1409,7 @@ def get_exe_prefixes(exe_filename):
continue
if
parts
[
0
].
upper
()
in
(
'PURELIB'
,
'PLATLIB'
):
contents
=
z
.
read
(
name
)
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
contents
=
contents
.
decode
()
for
pth
in
yield_lines
(
contents
):
pth
=
pth
.
strip
().
replace
(
'
\
\
'
,
'/'
)
...
...
@@ -1855,7 +1855,7 @@ def get_win_launcher(type):
def
load_launcher_manifest
(
name
):
manifest
=
pkg_resources
.
resource_string
(
__name__
,
'launcher manifest.xml'
)
if
sys
.
version_info
[
0
]
<
3
:
if
PY2
:
return
manifest
%
vars
()
else
:
return
manifest
.
decode
(
'utf-8'
)
%
vars
()
...
...
setuptools/command/egg_info.py
View file @
8567ca65
...
...
@@ -128,7 +128,7 @@ class egg_info(Command):
to the file.
"""
log
.
info
(
"writing %s to %s"
,
what
,
filename
)
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
data
=
data
.
encode
(
"utf-8"
)
if
not
self
.
dry_run
:
f
=
open
(
filename
,
'wb'
)
...
...
setuptools/command/sdist.py
View file @
8567ca65
...
...
@@ -8,6 +8,7 @@ import distutils.command.sdist as orig
from
distutils.util
import
convert_path
from
distutils
import
log
from
setuptools
import
svn_utils
from
setuptools.compat
import
PY3
READMES
=
(
'README'
,
'README.rst'
,
'README.txt'
)
...
...
@@ -230,7 +231,7 @@ class sdist(orig.sdist):
manifest = open(self.manifest, 'rbU')
for line in manifest:
# The manifest must contain UTF-8. See #303.
if
sys.version_info >= (3,)
:
if
PY3
:
try:
line = line.decode('UTF-8')
except UnicodeDecodeError:
...
...
setuptools/command/test.py
View file @
8567ca65
...
...
@@ -8,6 +8,7 @@ from pkg_resources import (resource_listdir, resource_exists,
normalize_path
,
working_set
,
_namespace_packages
,
add_activation_listener
,
require
,
EntryPoint
)
from
setuptools.compat
import
PY3
from
setuptools.py31compat
import
unittest_main
...
...
@@ -87,10 +88,8 @@ class test(Command):
self
.
test_runner
=
getattr
(
self
.
distribution
,
'test_runner'
,
None
)
def
with_project_on_sys_path
(
self
,
func
):
with_2to3
=
(
sys
.
version_info
>=
(
3
,)
and
getattr
(
self
.
distribution
,
'use_2to3'
,
False
)
)
with_2to3
=
PY3
and
getattr
(
self
.
distribution
,
'use_2to3'
,
False
)
if
with_2to3
:
# If we run 2to3 we can not do this inplace:
...
...
@@ -149,7 +148,7 @@ class test(Command):
# Purge modules under test from sys.modules. The test loader will
# re-import them from the build location. Required when 2to3 is used
# with namespace packages.
if
sys
.
version_info
>=
(
3
,)
and
getattr
(
self
.
distribution
,
'use_2to3'
,
False
):
if
PY3
and
getattr
(
self
.
distribution
,
'use_2to3'
,
False
):
module
=
self
.
test_args
[
-
1
].
split
(
'.'
)[
0
]
if
module
in
_namespace_packages
:
del_modules
=
[]
...
...
setuptools/dist.py
View file @
8567ca65
...
...
@@ -13,7 +13,7 @@ from distutils.errors import (DistutilsOptionError, DistutilsPlatformError,
DistutilsSetupError
)
from
setuptools.depends
import
Require
from
setuptools.compat
import
numeric_types
,
basestring
from
setuptools.compat
import
numeric_types
,
basestring
,
PY2
import
pkg_resources
def
_get_unpatched
(
cls
):
...
...
@@ -629,7 +629,7 @@ class Distribution(_Distribution):
"""
import
sys
if
sys
.
version_info
<
(
3
,)
or
self
.
help_commands
:
if
PY2
or
self
.
help_commands
:
return
_Distribution
.
handle_display_options
(
self
,
option_order
)
# Stdout may be StringIO (e.g. in tests)
...
...
setuptools/svn_utils.py
View file @
8567ca65
...
...
@@ -8,7 +8,7 @@ import locale
import
codecs
import
unicodedata
import
warnings
from
setuptools.compat
import
unicode
from
setuptools.compat
import
unicode
,
PY2
from
setuptools.py31compat
import
TemporaryDirectory
from
xml.sax.saxutils
import
unescape
...
...
@@ -60,7 +60,7 @@ def _get_target_property(target):
def
_get_xml_data
(
decoded_str
):
if
sys
.
version_info
<
(
3
,
0
)
:
if
PY2
:
#old versions want an encoded string
data
=
decoded_str
.
encode
(
'utf-8'
)
else
:
...
...
@@ -180,12 +180,12 @@ def parse_external_prop(lines):
if
not
line
:
continue
if
sys
.
version_info
<
(
3
,
0
)
:
if
PY2
:
#shlex handles NULLs just fine and shlex in 2.7 tries to encode
#as ascii automatiically
line
=
line
.
encode
(
'utf-8'
)
line
=
shlex
.
split
(
line
)
if
sys
.
version_info
<
(
3
,
0
)
:
if
PY2
:
line
=
[
x
.
decode
(
'utf-8'
)
for
x
in
line
]
#EXT_FOLDERNAME is either the first or last depending on where
...
...
@@ -232,13 +232,13 @@ class SvnInfo(object):
@
staticmethod
def
get_svn_version
():
# Temp config directory should be enough to check for repository
# This is needed because .svn always creates .subversion and
# This is needed because .svn always creates .subversion and
# some operating systems do not handle dot directory correctly.
# Real queries in real svn repos with be concerned with it creation
with
TemporaryDirectory
()
as
tempdir
:
code
,
data
=
_run_command
([
'svn'
,
code
,
data
=
_run_command
([
'svn'
,
'--config-dir'
,
tempdir
,
'--version'
,
'--version'
,
'--quiet'
])
if
code
==
0
and
data
:
...
...
@@ -258,11 +258,11 @@ class SvnInfo(object):
normdir = os.path.normpath(dirname)
# Temp config directory should be enough to check for repository
# This is needed because .svn always creates .subversion and
# This is needed because .svn always creates .subversion and
# some operating systems do not handle dot directory correctly.
# Real queries in real svn repos with be concerned with it creation
with TemporaryDirectory() as tempdir:
code, data = _run_command(['
svn
',
code, data = _run_command(['
svn
',
'
--
config
-
dir
', tempdir,
'
info
', normdir])
...
...
setuptools/tests/test_resources.py
View file @
8567ca65
...
...
@@ -15,7 +15,7 @@ from pkg_resources import (parse_requirements, VersionConflict, parse_version,
from
setuptools.command.easy_install
import
(
get_script_header
,
is_sh
,
nt_quote_arg
)
from
setuptools.compat
import
StringIO
,
iteritems
from
setuptools.compat
import
StringIO
,
iteritems
,
PY3
try
:
frozenset
...
...
@@ -522,8 +522,7 @@ class ScriptHeaderTests(TestCase):
def
test_get_script_header_jython_workaround
(
self
):
# This test doesn't work with Python 3 in some locales
if
(
sys
.
version_info
>=
(
3
,)
and
os
.
environ
.
get
(
"LC_CTYPE"
)
in
(
None
,
"C"
,
"POSIX"
)):
if
PY3
and
os
.
environ
.
get
(
"LC_CTYPE"
)
in
(
None
,
"C"
,
"POSIX"
):
return
class
java
:
...
...
setuptools/tests/test_sdist.py
View file @
8567ca65
...
...
@@ -12,7 +12,7 @@ import re
from
setuptools.tests
import
environment
,
test_svn
from
setuptools.tests.py26compat
import
skipIf
from
setuptools.compat
import
StringIO
,
unicode
from
setuptools.compat
import
StringIO
,
unicode
,
PY3
,
PY2
from
setuptools.tests.py26compat
import
skipIf
from
setuptools.command.sdist
import
sdist
,
walk_revctrl
from
setuptools.command.egg_info
import
manifest_maker
...
...
@@ -34,7 +34,7 @@ setup(**%r)
"""
%
SETUP_ATTRS
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
LATIN1_FILENAME
=
'smörbröd.py'
.
encode
(
'latin-1'
)
else
:
LATIN1_FILENAME
=
'sm
\
xf6
rbr
\
xf6
d.py'
...
...
@@ -52,14 +52,14 @@ def unquiet():
# Fake byte literals for Python <= 2.5
def
b
(
s
,
encoding
=
'utf-8'
):
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
return
s
.
encode
(
encoding
)
return
s
# Convert to POSIX path
def
posix
(
path
):
if
sys
.
version_info
>=
(
3
,)
and
not
isinstance
(
path
,
str
):
if
PY3
and
not
isinstance
(
path
,
str
):
return
path
.
replace
(
os
.
sep
.
encode
(
'ascii'
),
b
(
'/'
))
else
:
return
path
.
replace
(
os
.
sep
,
'/'
)
...
...
@@ -156,14 +156,14 @@ class TestSdistTest(unittest.TestCase):
self
.
fail
(
e
)
# The manifest should contain the UTF-8 filename
if
sys
.
version_info
<
(
3
,)
:
if
PY2
:
fs_enc
=
sys
.
getfilesystemencoding
()
filename
=
filename
.
decode
(
fs_enc
)
self
.
assertTrue
(
posix
(
filename
)
in
u_contents
)
# Python 3 only
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
def
test_write_manifest_allows_utf8_filenames
(
self
):
# Test for #303.
...
...
@@ -281,12 +281,12 @@ class TestSdistTest(unittest.TestCase):
unquiet
()
# The filelist should contain the UTF-8 filename
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
filename
=
filename
.
decode
(
'utf-8'
)
self
.
assertTrue
(
filename
in
cmd
.
filelist
.
files
)
# Python 3 only
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
def
test_read_manifest_skips_non_utf8_filenames
(
self
):
# Test for #303.
...
...
@@ -328,7 +328,7 @@ class TestSdistTest(unittest.TestCase):
filename
=
filename
.
decode
(
'latin-1'
)
self
.
assertFalse
(
filename
in
cmd
.
filelist
.
files
)
@
skipIf
(
sys
.
version_info
>=
(
3
,)
and
locale
.
getpreferredencoding
()
!=
'UTF-8'
,
@
skipIf
(
PY3
and
locale
.
getpreferredencoding
()
!=
'UTF-8'
,
'Unittest fails if locale is not utf-8 but the manifests is recorded correctly'
)
def
test_sdist_with_utf8_encoded_filename
(
self
):
# Test for #303.
...
...
@@ -350,7 +350,7 @@ class TestSdistTest(unittest.TestCase):
if
sys
.
platform
==
'darwin'
:
filename
=
decompose
(
filename
)
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
fs_enc
=
sys
.
getfilesystemencoding
()
if
sys
.
platform
==
'win32'
:
...
...
@@ -385,7 +385,7 @@ class TestSdistTest(unittest.TestCase):
finally
:
unquiet
()
if
sys
.
version_info
>=
(
3
,)
:
if
PY3
:
#not all windows systems have a default FS encoding of cp1252
if
sys
.
platform
==
'win32'
:
# Latin-1 is similar to Windows-1252 however
...
...
@@ -408,7 +408,7 @@ class TestSdistTest(unittest.TestCase):
try
:
# fs_enc should match how one is expect the decoding to
# be proformed for the manifest output.
fs_enc
=
sys
.
getfilesystemencoding
()
fs_enc
=
sys
.
getfilesystemencoding
()
filename
.
decode
(
fs_enc
)
self
.
assertTrue
(
filename
in
cmd
.
filelist
.
files
)
except
UnicodeDecodeError
:
...
...
setuptools/tests/test_test.py
View file @
8567ca65
...
...
@@ -10,7 +10,7 @@ import tempfile
import
unittest
from
distutils.errors
import
DistutilsError
from
setuptools.compat
import
StringIO
from
setuptools.compat
import
StringIO
,
PY2
from
setuptools.command.test
import
test
from
setuptools.command
import
easy_install
as
easy_install_pkg
from
setuptools.dist
import
Distribution
...
...
@@ -34,7 +34,7 @@ except ImportError:
__path__ = extend_path(__path__, __name__)
"""
# Make sure this is Latin-1 binary, before writing:
if
sys
.
version_info
<
(
3
,)
:
if
PY2
:
NS_INIT
=
NS_INIT
.
decode
(
'UTF-8'
)
NS_INIT
=
NS_INIT
.
encode
(
'Latin-1'
)
...
...
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