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
133272d7
Commit
133272d7
authored
Dec 30, 2014
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Plain Diff
Merge with master
parents
457b0161
3967fa33
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
90 deletions
+91
-90
setuptools/command/easy_install.py
setuptools/command/easy_install.py
+8
-4
setuptools/tests/py26compat.py
setuptools/tests/py26compat.py
+13
-0
setuptools/tests/test_easy_install.py
setuptools/tests/test_easy_install.py
+70
-86
No files found.
setuptools/command/easy_install.py
View file @
133272d7
...
@@ -1549,10 +1549,14 @@ class PthDistributions(Environment):
...
@@ -1549,10 +1549,14 @@ class PthDistributions(Environment):
def
add
(
self
,
dist
):
def
add
(
self
,
dist
):
"""Add `dist` to the distribution map"""
"""Add `dist` to the distribution map"""
if
(
dist
.
location
not
in
self
.
paths
and
(
new_path
=
(
dist
.
location
not
in
self
.
paths
and
(
dist
.
location
not
in
self
.
sitedirs
or
dist
.
location
not
in
self
.
sitedirs
or
dist
.
location
==
os
.
getcwd
()
# account for '.' being in PYTHONPATH
# account for '.' being in PYTHONPATH
)):
dist
.
location
==
os
.
getcwd
()
)
)
if
new_path
:
self
.
paths
.
append
(
dist
.
location
)
self
.
paths
.
append
(
dist
.
location
)
self
.
dirty
=
True
self
.
dirty
=
True
Environment
.
add
(
self
,
dist
)
Environment
.
add
(
self
,
dist
)
...
...
setuptools/tests/py26compat.py
View file @
133272d7
import
sys
import
unittest
import
unittest
import
tarfile
try
:
try
:
# provide skipIf for Python 2.4-2.6
# provide skipIf for Python 2.4-2.6
...
@@ -12,3 +14,14 @@ except AttributeError:
...
@@ -12,3 +14,14 @@ except AttributeError:
return
skip
return
skip
return
func
return
func
return
skipper
return
skipper
def
_tarfile_open_ex
(
*
args
,
**
kwargs
):
"""
Extend result as a context manager.
"""
res
=
tarfile
.
open
(
*
args
,
**
kwargs
)
res
.
__exit__
=
lambda
exc_type
,
exc_value
,
traceback
:
res
.
close
()
res
.
__enter__
=
lambda
:
res
return
res
tarfile_open
=
_tarfile_open_ex
if
sys
.
version_info
<
(
2
,
7
)
else
tarfile
.
open
setuptools/tests/test_easy_install.py
View file @
133272d7
...
@@ -10,7 +10,7 @@ import contextlib
...
@@ -10,7 +10,7 @@ import contextlib
import
textwrap
import
textwrap
import
tarfile
import
tarfile
import
logging
import
logging
import
distutils.core
import
itertools
import
pytest
import
pytest
import
mock
import
mock
...
@@ -28,6 +28,16 @@ from pkg_resources import Distribution as PRDistribution
...
@@ -28,6 +28,16 @@ from pkg_resources import Distribution as PRDistribution
import
setuptools.tests.server
import
setuptools.tests.server
import
pkg_resources
import
pkg_resources
from
.py26compat
import
tarfile_open
def
DALS
(
input
):
"""
Dedent and left-strip
"""
return
textwrap
.
dedent
(
input
).
lstrip
()
class
FakeDist
(
object
):
class
FakeDist
(
object
):
def
get_entry_map
(
self
,
group
):
def
get_entry_map
(
self
,
group
):
if
group
!=
'console_scripts'
:
if
group
!=
'console_scripts'
:
...
@@ -37,24 +47,24 @@ class FakeDist(object):
...
@@ -37,24 +47,24 @@ class FakeDist(object):
def
as_requirement
(
self
):
def
as_requirement
(
self
):
return
'spec'
return
'spec'
WANTED
=
"""
\
WANTED
=
DALS
(
"""
#!%s
#!%s
# EASY-INSTALL-ENTRY-SCRIPT: 'spec','console_scripts','name'
# EASY-INSTALL-ENTRY-SCRIPT: 'spec','console_scripts','name'
__requires__ = 'spec'
__requires__ = 'spec'
import sys
import sys
from pkg_resources import load_entry_point
from pkg_resources import load_entry_point
if __name__ == '__main__':
if __name__ == '__main__':
sys.exit(
sys.exit(
load_entry_point('spec', 'console_scripts', 'name')()
load_entry_point('spec', 'console_scripts', 'name')()
)
)
"""
%
nt_quote_arg
(
fix_jython_executable
(
sys
.
executable
,
""
))
"""
)
%
nt_quote_arg
(
fix_jython_executable
(
sys
.
executable
,
""
))
SETUP_PY
=
"""
\
SETUP_PY
=
DALS
(
"""
from setuptools import setup
from setuptools import setup
setup(name='foo')
setup(name='foo')
"""
"""
)
class
TestEasyInstallTest
(
unittest
.
TestCase
):
class
TestEasyInstallTest
(
unittest
.
TestCase
):
...
@@ -73,11 +83,8 @@ class TestEasyInstallTest(unittest.TestCase):
...
@@ -73,11 +83,8 @@ class TestEasyInstallTest(unittest.TestCase):
def
test_get_script_args
(
self
):
def
test_get_script_args
(
self
):
dist
=
FakeDist
()
dist
=
FakeDist
()
old_platform
=
sys
.
platform
args
=
next
(
get_script_args
(
dist
))
try
:
name
,
script
=
itertools
.
islice
(
args
,
2
)
name
,
script
=
[
i
for
i
in
next
(
get_script_args
(
dist
))][
0
:
2
]
finally
:
sys
.
platform
=
old_platform
self
.
assertEqual
(
script
,
WANTED
)
self
.
assertEqual
(
script
,
WANTED
)
...
@@ -116,10 +123,9 @@ class TestPTHFileWriter(unittest.TestCase):
...
@@ -116,10 +123,9 @@ class TestPTHFileWriter(unittest.TestCase):
self
.
assertTrue
(
pth
.
dirty
)
self
.
assertTrue
(
pth
.
dirty
)
def
test_add_from_site_is_ignored
(
self
):
def
test_add_from_site_is_ignored
(
self
):
if
os
.
name
!=
'nt'
:
location
=
'/test/location/does-not-have-to-exist'
location
=
'/test/location/does-not-have-to-exist'
else
:
# PthDistributions expects all locations to be normalized
location
=
'c:
\
\
does_not_exist'
location
=
pkg_resources
.
normalize_path
(
location
)
pth
=
PthDistributions
(
'does-not_exist'
,
[
location
,
])
pth
=
PthDistributions
(
'does-not_exist'
,
[
location
,
])
self
.
assertTrue
(
not
pth
.
dirty
)
self
.
assertTrue
(
not
pth
.
dirty
)
pth
.
add
(
PRDistribution
(
location
))
pth
.
add
(
PRDistribution
(
location
))
...
@@ -131,9 +137,8 @@ class TestUserInstallTest(unittest.TestCase):
...
@@ -131,9 +137,8 @@ class TestUserInstallTest(unittest.TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
dir
=
tempfile
.
mkdtemp
()
self
.
dir
=
tempfile
.
mkdtemp
()
setup
=
os
.
path
.
join
(
self
.
dir
,
'setup.py'
)
setup
=
os
.
path
.
join
(
self
.
dir
,
'setup.py'
)
f
=
open
(
setup
,
'w'
)
with
open
(
setup
,
'w'
)
as
f
:
f
.
write
(
SETUP_PY
)
f
.
write
(
SETUP_PY
)
f
.
close
()
self
.
old_cwd
=
os
.
getcwd
()
self
.
old_cwd
=
os
.
getcwd
()
os
.
chdir
(
self
.
dir
)
os
.
chdir
(
self
.
dir
)
...
@@ -194,11 +199,8 @@ class TestUserInstallTest(unittest.TestCase):
...
@@ -194,11 +199,8 @@ class TestUserInstallTest(unittest.TestCase):
new_location
=
tempfile
.
mkdtemp
()
new_location
=
tempfile
.
mkdtemp
()
target
=
tempfile
.
mkdtemp
()
target
=
tempfile
.
mkdtemp
()
egg_file
=
os
.
path
.
join
(
new_location
,
'foo-1.0.egg-info'
)
egg_file
=
os
.
path
.
join
(
new_location
,
'foo-1.0.egg-info'
)
f
=
open
(
egg_file
,
'w'
)
with
open
(
egg_file
,
'w'
)
as
f
:
try
:
f
.
write
(
'Name: foo
\
n
'
)
f
.
write
(
'Name: foo
\
n
'
)
finally
:
f
.
close
()
sys
.
path
.
append
(
target
)
sys
.
path
.
append
(
target
)
old_ppath
=
os
.
environ
.
get
(
'PYTHONPATH'
)
old_ppath
=
os
.
environ
.
get
(
'PYTHONPATH'
)
...
@@ -263,7 +265,6 @@ class TestUserInstallTest(unittest.TestCase):
...
@@ -263,7 +265,6 @@ class TestUserInstallTest(unittest.TestCase):
try
:
try
:
with
quiet_context
():
with
quiet_context
():
with
reset_setup_stop_context
():
with
self
.
patched_setup_context
():
with
self
.
patched_setup_context
():
run_setup
(
test_setup_py
,
[
'install'
])
run_setup
(
test_setup_py
,
[
'install'
])
except
SandboxViolation
:
except
SandboxViolation
:
...
@@ -296,11 +297,13 @@ class TestSetupRequires(unittest.TestCase):
...
@@ -296,11 +297,13 @@ class TestSetupRequires(unittest.TestCase):
with
TestSetupRequires
.
create_sdist
()
as
dist_file
:
with
TestSetupRequires
.
create_sdist
()
as
dist_file
:
with
tempdir_context
()
as
temp_install_dir
:
with
tempdir_context
()
as
temp_install_dir
:
with
environment_context
(
PYTHONPATH
=
temp_install_dir
):
with
environment_context
(
PYTHONPATH
=
temp_install_dir
):
ei_params
=
[
'--index-url'
,
p_index
.
url
,
ei_params
=
[
'--index-url'
,
p_index
.
url
,
'--allow-hosts'
,
p_index_loc
,
'--allow-hosts'
,
p_index_loc
,
'--exclude-scripts'
,
'--install-dir'
,
temp_install_dir
,
'--exclude-scripts'
,
dist_file
]
'--install-dir'
,
temp_install_dir
,
with
reset_setup_stop_context
():
dist_file
,
]
with
argv_context
([
'easy_install'
]):
with
argv_context
([
'easy_install'
]):
# attempt to install the dist. It should fail because
# attempt to install the dist. It should fail because
# it doesn't exist.
# it doesn't exist.
...
@@ -320,16 +323,15 @@ class TestSetupRequires(unittest.TestCase):
...
@@ -320,16 +323,15 @@ class TestSetupRequires(unittest.TestCase):
"""
"""
with
tempdir_context
()
as
dir
:
with
tempdir_context
()
as
dir
:
dist_path
=
os
.
path
.
join
(
dir
,
'setuptools-test-fetcher-1.0.tar.gz'
)
dist_path
=
os
.
path
.
join
(
dir
,
'setuptools-test-fetcher-1.0.tar.gz'
)
make_trivial_sdist
(
script
=
DALS
(
"""
dist_path
,
textwrap
.
dedent
(
"""
import setuptools
import setuptools
setuptools.setup(
setuptools.setup(
name="setuptools-test-fetcher",
name="setuptools-test-fetcher",
version="1.0",
version="1.0",
setup_requires = ['does-not-exist'],
setup_requires = ['does-not-exist'],
)
)
"""
).
lstrip
())
"""
)
make_trivial_sdist
(
dist_path
,
script
)
yield
dist_path
yield
dist_path
def
test_setup_requires_overrides_version_conflict
(
self
):
def
test_setup_requires_overrides_version_conflict
(
self
):
...
@@ -351,7 +353,6 @@ class TestSetupRequires(unittest.TestCase):
...
@@ -351,7 +353,6 @@ class TestSetupRequires(unittest.TestCase):
test_pkg
=
create_setup_requires_package
(
temp_dir
)
test_pkg
=
create_setup_requires_package
(
temp_dir
)
test_setup_py
=
os
.
path
.
join
(
test_pkg
,
'setup.py'
)
test_setup_py
=
os
.
path
.
join
(
test_pkg
,
'setup.py'
)
with
quiet_context
()
as
(
stdout
,
stderr
):
with
quiet_context
()
as
(
stdout
,
stderr
):
with
reset_setup_stop_context
():
try
:
try
:
# Don't even need to install the package, just
# Don't even need to install the package, just
# running the setup.py at all is sufficient
# running the setup.py at all is sufficient
...
@@ -383,17 +384,16 @@ def create_setup_requires_package(path):
...
@@ -383,17 +384,16 @@ def create_setup_requires_package(path):
test_setup_py
=
os
.
path
.
join
(
test_pkg
,
'setup.py'
)
test_setup_py
=
os
.
path
.
join
(
test_pkg
,
'setup.py'
)
os
.
mkdir
(
test_pkg
)
os
.
mkdir
(
test_pkg
)
f
=
open
(
test_setup_py
,
'w'
)
with
open
(
test_setup_py
,
'w'
)
as
f
:
f
.
write
(
textwrap
.
dedent
(
"""
\
f
.
write
(
DALS
(
"""
import setuptools
import setuptools
setuptools.setup(**%r)
setuptools.setup(**%r)
"""
%
test_setup_attrs
))
"""
%
test_setup_attrs
))
f
.
close
()
foobar_path
=
os
.
path
.
join
(
path
,
'foobar-0.1.tar.gz'
)
foobar_path
=
os
.
path
.
join
(
path
,
'foobar-0.1.tar.gz'
)
make_trivial_sdist
(
make_trivial_sdist
(
foobar_path
,
foobar_path
,
textwrap
.
dedent
(
"""
\
DALS
(
"""
import setuptools
import setuptools
setuptools.setup(
setuptools.setup(
name='foobar',
name='foobar',
...
@@ -417,11 +417,8 @@ def make_trivial_sdist(dist_path, setup_py):
...
@@ -417,11 +417,8 @@ def make_trivial_sdist(dist_path, setup_py):
MemFile
=
StringIO
MemFile
=
StringIO
setup_py_bytes
=
MemFile
(
setup_py
.
encode
(
'utf-8'
))
setup_py_bytes
=
MemFile
(
setup_py
.
encode
(
'utf-8'
))
setup_py_file
.
size
=
len
(
setup_py_bytes
.
getvalue
())
setup_py_file
.
size
=
len
(
setup_py_bytes
.
getvalue
())
dist
=
tarfile
.
open
(
dist_path
,
'w:gz'
)
with
tarfile_open
(
dist_path
,
'w:gz'
)
as
dist
:
try
:
dist
.
addfile
(
setup_py_file
,
fileobj
=
setup_py_bytes
)
dist
.
addfile
(
setup_py_file
,
fileobj
=
setup_py_bytes
)
finally
:
dist
.
close
()
@
contextlib
.
contextmanager
@
contextlib
.
contextmanager
...
@@ -453,19 +450,6 @@ def argv_context(repl):
...
@@ -453,19 +450,6 @@ def argv_context(repl):
yield
yield
sys
.
argv
[:]
=
old_argv
sys
.
argv
[:]
=
old_argv
@
contextlib
.
contextmanager
def
reset_setup_stop_context
():
"""
When the setuptools tests are run using setup.py test, and then
one wants to invoke another setup() command (such as easy_install)
within those tests, it's necessary to reset the global variable
in distutils.core so that the setup() command will run naturally.
"""
saved
=
distutils
.
core
.
_setup_stop_after
distutils
.
core
.
_setup_stop_after
=
None
yield
distutils
.
core
.
_setup_stop_after
=
saved
@
contextlib
.
contextmanager
@
contextlib
.
contextmanager
def
quiet_context
():
def
quiet_context
():
...
...
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