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
558ed858
Commit
558ed858
authored
Aug 02, 2017
by
Benoit Pierre
Committed by
GitHub
Aug 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1108 from benoit-pierre/fix_requires_handling,_again
fix requires handling when using setup.cfg
parents
28e2625c
096f3287
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
201 additions
and
149 deletions
+201
-149
setuptools/dist.py
setuptools/dist.py
+5
-5
setuptools/tests/test_config.py
setuptools/tests/test_config.py
+3
-3
setuptools/tests/test_egg_info.py
setuptools/tests/test_egg_info.py
+193
-141
No files found.
setuptools/dist.py
View file @
558ed858
...
...
@@ -349,14 +349,15 @@ class Distribution(Distribution_parse_config_files, _Distribution):
"setuptools, pip, and PyPI. Please see PEP 440 for more "
"details." % self.metadata.version
)
if getattr(self, '
python_requires
', None):
self.metadata.python_requires = self.python_requires
self._finalize_requires()
def _finalize_requires(self):
"""
Fix environment markers in `install_requires` and `extras_require`.
Set `metadata.python_requires` and fix environment markers
in `install_requires` and `extras_require`.
"""
if getattr(self, '
python_requires
', None):
self.metadata.python_requires = self.python_requires
self._convert_extras_requirements()
self._move_install_requirements_markers()
...
...
@@ -424,8 +425,7 @@ class Distribution(Distribution_parse_config_files, _Distribution):
_Distribution.parse_config_files(self, filenames=filenames)
parse_configuration(self, self.command_options)
if getattr(self, '
python_requires
', None):
self.metadata.python_requires = self.python_requires
self._finalize_requires()
def parse_command_line(self):
"""Process features after parsing command line options"""
...
...
setuptools/tests/test_config.py
View file @
558ed858
...
...
@@ -333,7 +333,7 @@ class TestOptions:
])
assert
dist
.
install_requires
==
([
'docutils>=0.3'
,
'pack
==1.1,
==1.3'
,
'pack
==1.1,
==1.3'
,
'hey'
])
assert
dist
.
setup_requires
==
([
...
...
@@ -403,7 +403,7 @@ class TestOptions:
])
assert
dist
.
install_requires
==
([
'docutils>=0.3'
,
'pack
==1.1,
==1.3'
,
'pack
==1.1,
==1.3'
,
'hey'
])
assert
dist
.
setup_requires
==
([
...
...
@@ -508,7 +508,7 @@ class TestOptions:
with
get_dist
(
tmpdir
)
as
dist
:
assert
dist
.
extras_require
==
{
'pdf'
:
[
'ReportLab>=1.2'
,
'RXP'
],
'rest'
:
[
'docutils>=0.3'
,
'pack
==1.1,
==1.3'
]
'rest'
:
[
'docutils>=0.3'
,
'pack
==1.1,
==1.3'
]
}
def
test_entry_points
(
self
,
tmpdir
):
...
...
setuptools/tests/test_egg_info.py
View file @
558ed858
import
ast
import
os
import
glob
import
re
...
...
@@ -165,19 +166,17 @@ class TestEggInfo(object):
sources_txt
=
os
.
path
.
join
(
egg_info_dir
,
'SOURCES.txt'
)
assert
'docs/usage.rst'
in
open
(
sources_txt
).
read
().
split
(
'
\
n
'
)
def
_setup_script_with_requires
(
self
,
requires_line
):
setup_script
=
DALS
(
"""
def
_setup_script_with_requires
(
self
,
requires
,
use_setup_cfg
=
False
):
setup_script
=
DALS
(
'''
from setuptools import setup
setup(
name='foo',
%s
zip_safe=False,
)
"""
%
requires_line
)
build_files
({
'setup.py'
:
setup_script
,
})
setup(name='foo', zip_safe=False, %s)
'''
)
%
(
''
if
use_setup_cfg
else
requires
)
setup_config
=
requires
if
use_setup_cfg
else
''
build_files
({
'setup.py'
:
setup_script
,
'setup.cfg'
:
setup_config
})
mismatch_marker
=
"python_version<'{this_ver}'"
.
format
(
this_ver
=
sys
.
version_info
[
0
],
...
...
@@ -188,131 +187,198 @@ class TestEggInfo(object):
)
invalid_marker
=
"<=>++"
def
test_install_requires_with_marker
(
self
,
tmpdir_cwd
,
env
):
tmpl
=
'install_requires=["barbazquux;{marker}"],'
req
=
tmpl
.
format
(
marker
=
self
.
mismatch_marker
)
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
egg_info_dir
=
self
.
_find_egg_info_files
(
env
.
paths
[
'lib'
]).
base
requires_txt
=
os
.
path
.
join
(
egg_info_dir
,
'requires.txt'
)
with
open
(
requires_txt
)
as
fp
:
install_requires
=
fp
.
read
()
expected_requires
=
DALS
(
'''
[:{marker}]
class
RequiresTestHelper
(
object
):
@
staticmethod
def
parametrize
(
*
test_list
,
**
format_dict
):
idlist
=
[]
argvalues
=
[]
for
test
in
test_list
:
test_params
=
test
.
lstrip
().
split
(
'
\
n
\
n
'
,
3
)
name_kwargs
=
test_params
.
pop
(
0
).
split
(
'
\
n
'
)
if
len
(
name_kwargs
)
>
1
:
install_cmd_kwargs
=
ast
.
literal_eval
(
name_kwargs
[
1
].
strip
())
else
:
install_cmd_kwargs
=
{}
name
=
name_kwargs
[
0
].
strip
()
setup_py_requires
,
setup_cfg_requires
,
expected_requires
=
(
DALS
(
a
).
format
(
**
format_dict
)
for
a
in
test_params
)
for
id_
,
requires
,
use_cfg
in
(
(
name
,
setup_py_requires
,
False
),
(
name
+
'_in_setup_cfg'
,
setup_cfg_requires
,
True
),
):
idlist
.
append
(
id_
)
marks
=
()
if
requires
.
startswith
(
'@xfail
\
n
'
):
requires
=
requires
[
7
:]
marks
=
pytest
.
mark
.
xfail
argvalues
.
append
(
pytest
.
param
(
requires
,
use_cfg
,
expected_requires
,
install_cmd_kwargs
,
marks
=
marks
))
return
pytest
.
mark
.
parametrize
(
'requires,use_setup_cfg,'
'expected_requires,install_cmd_kwargs'
,
argvalues
,
ids
=
idlist
)
@
RequiresTestHelper
.
parametrize
(
# Format of a test:
#
# id
# install_cmd_kwargs [optional]
#
# requires block (when used in setup.py)
#
# requires block (when used in setup.cfg)
#
# expected contents of requires.txt
'''
install_requires_with_marker
install_requires=["barbazquux;{mismatch_marker}"],
[options]
install_requires =
barbazquux; {mismatch_marker}
[:{mismatch_marker_alternate}]
barbazquux
'''
).
format
(
marker
=
self
.
mismatch_marker_alternate
)
assert
install_requires
.
lstrip
()
==
expected_requires
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
'''
,
'''
install_requires_with_extra
{'cmd': ['egg_info']}
install_requires=["barbazquux [test]"],
[options]
install_requires =
barbazquux [test]
def
test_install_requires_with_extra
(
self
,
tmpdir_cwd
,
env
):
req
=
'install_requires=["barbazquux [test]"],'
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
,
cmd
=
[
'egg_info'
])
egg_info_dir
=
os
.
path
.
join
(
'.'
,
'foo.egg-info'
)
requires_txt
=
os
.
path
.
join
(
egg_info_dir
,
'requires.txt'
)
with
open
(
requires_txt
)
as
fp
:
install_requires
=
fp
.
read
()
expected_requires
=
DALS
(
'''
barbazquux[test]
'''
)
assert
install_requires
.
lstrip
()
==
expected_requires
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
'''
,
def
test_install_requires_with_extra_and_marker
(
self
,
tmpdir_cwd
,
env
):
tmpl
=
'install_requires=["barbazquux [test]; {marker}"],'
req
=
tmpl
.
format
(
marker
=
self
.
mismatch_marker
)
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
egg_info_dir
=
self
.
_find_egg_info_files
(
env
.
paths
[
'lib'
]).
base
requires_txt
=
os
.
path
.
join
(
egg_info_dir
,
'requires.txt'
)
with
open
(
requires_txt
)
as
fp
:
install_requires
=
fp
.
read
()
expected_requires
=
DALS
(
'''
[:{marker}]
'''
install_requires_with_extra_and_marker
install_requires=["barbazquux [test]; {mismatch_marker}"],
[options]
install_requires =
barbazquux [test]; {mismatch_marker}
[:{mismatch_marker_alternate}]
barbazquux[test]
'''
).
format
(
marker
=
self
.
mismatch_marker_alternate
)
assert
install_requires
.
lstrip
()
==
expected_requires
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
'''
,
def
test_setup_requires_with_markers
(
self
,
tmpdir_cwd
,
env
):
tmpl
=
'setup_requires=["barbazquux;{marker}"],'
req
=
tmpl
.
format
(
marker
=
self
.
mismatch_marker
)
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
'''
setup_requires_with_markers
def
test_tests_require_with_markers
(
self
,
tmpdir_cwd
,
env
):
tmpl
=
'tests_require=["barbazquux;{marker}"],'
req
=
tmpl
.
format
(
marker
=
self
.
mismatch_marker
)
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
,
cmd
=
[
'test'
],
output
=
"Ran 0 tests in"
)
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
setup_requires=["barbazquux;{mismatch_marker}"],
[options]
setup_requires =
barbazquux; {mismatch_marker}
'''
,
'''
tests_require_with_markers
{'cmd': ['test'], 'output': "Ran 0 tests in"}
tests_require=["barbazquux;{mismatch_marker}"],
[options]
tests_require =
barbazquux; {mismatch_marker}
'''
,
'''
extras_require_with_extra
{'cmd': ['egg_info']}
extras_require={{"extra": ["barbazquux [test]"]}},
[options.extras_require]
extra = barbazquux [test]
def
test_extras_require_with_extra
(
self
,
tmpdir_cwd
,
env
):
req
=
'extras_require={"extra": ["barbazquux [test]"]},'
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
,
cmd
=
[
'egg_info'
])
egg_info_dir
=
os
.
path
.
join
(
'.'
,
'foo.egg-info'
)
requires_txt
=
os
.
path
.
join
(
egg_info_dir
,
'requires.txt'
)
with
open
(
requires_txt
)
as
fp
:
install_requires
=
fp
.
read
()
expected_requires
=
DALS
(
'''
[extra]
barbazquux[test]
'''
)
assert
install_requires
.
lstrip
()
==
expected_requires
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
'''
,
'''
extras_require_with_extra_and_marker_in_req
extras_require={{"extra": ["barbazquux [test]; {mismatch_marker}"]}},
[options.extras_require]
extra =
barbazquux [test]; {mismatch_marker}
def
test_extras_require_with_extra_and_marker_in_req
(
self
,
tmpdir_cwd
,
env
):
tmpl
=
'extras_require={{"extra": ["barbazquux [test]; {marker}"]}},'
req
=
tmpl
.
format
(
marker
=
self
.
mismatch_marker
)
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
egg_info_dir
=
self
.
_find_egg_info_files
(
env
.
paths
[
'lib'
]).
base
requires_txt
=
os
.
path
.
join
(
egg_info_dir
,
'requires.txt'
)
with
open
(
requires_txt
)
as
fp
:
install_requires
=
fp
.
read
()
expected_requires
=
DALS
(
'''
[extra]
[extra:{marker
}]
[extra:{mismatch_marker_alternate
}]
barbazquux[test]
'''
).
format
(
marker
=
self
.
mismatch_marker_alternate
)
assert
install_requires
.
lstrip
()
==
expected_requires
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
'''
,
def
test_extras_require_with_marker
(
self
,
tmpdir_cwd
,
env
):
tmpl
=
'extras_require={{":{marker}": ["barbazquux"]}},
'
req
=
tmpl
.
format
(
marker
=
self
.
mismatch_marker
)
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
egg_info_dir
=
self
.
_find_egg_info_files
(
env
.
paths
[
'lib'
]).
base
requires_txt
=
os
.
path
.
join
(
egg_info_dir
,
'requires.txt'
)
with
open
(
requires_txt
)
as
fp
:
install_requires
=
fp
.
read
()
expected_requires
=
DALS
(
'''
[:{
marker}]
# FIXME: ConfigParser does not allow : in key names!
''
'
extras_require_with_marker
extras_require={{":{mismatch_marker}": ["barbazquux"]}},
@xfail
[options.extras_require]
:{mismatch_marker} = barbazquux
[:{mismatch_
marker}]
barbazquux
'''
).
format
(
marker
=
self
.
mismatch_marker
)
assert
install_requires
.
lstrip
()
==
expected_requires
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
'''
,
'''
extras_require_with_marker_in_req
extras_require={{"extra": ["barbazquux; {mismatch_marker}"]}},
[options.extras_require]
extra =
barbazquux; {mismatch_marker}
def
test_extras_require_with_marker_in_req
(
self
,
tmpdir_cwd
,
env
):
tmpl
=
'extras_require={{"extra": ["barbazquux; {marker}"]}},'
req
=
tmpl
.
format
(
marker
=
self
.
mismatch_marker
)
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
egg_info_dir
=
self
.
_find_egg_info_files
(
env
.
paths
[
'lib'
]).
base
requires_txt
=
os
.
path
.
join
(
egg_info_dir
,
'requires.txt'
)
with
open
(
requires_txt
)
as
fp
:
install_requires
=
fp
.
read
()
expected_requires
=
DALS
(
'''
[extra]
[extra:{marker
}]
[extra:{mismatch_marker_alternate
}]
barbazquux
'''
).
format
(
marker
=
self
.
mismatch_marker_alternate
)
'''
,
'''
extras_require_with_empty_section
extras_require={{"empty": []}},
[options.extras_require]
empty =
[empty]
'''
,
# Format arguments.
invalid_marker
=
invalid_marker
,
mismatch_marker
=
mismatch_marker
,
mismatch_marker_alternate
=
mismatch_marker_alternate
,
)
def
test_requires
(
self
,
tmpdir_cwd
,
env
,
requires
,
use_setup_cfg
,
expected_requires
,
install_cmd_kwargs
):
self
.
_setup_script_with_requires
(
requires
,
use_setup_cfg
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
,
**
install_cmd_kwargs
)
egg_info_dir
=
os
.
path
.
join
(
'.'
,
'foo.egg-info'
)
requires_txt
=
os
.
path
.
join
(
egg_info_dir
,
'requires.txt'
)
if
os
.
path
.
exists
(
requires_txt
):
with
open
(
requires_txt
)
as
fp
:
install_requires
=
fp
.
read
()
else
:
install_requires
=
''
assert
install_requires
.
lstrip
()
==
expected_requires
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
...
...
@@ -332,20 +398,6 @@ class TestEggInfo(object):
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
def
test_extras_require_with_empty_section
(
self
,
tmpdir_cwd
,
env
):
tmpl
=
'extras_require={{"empty": []}},'
req
=
tmpl
.
format
(
marker
=
self
.
invalid_marker
)
self
.
_setup_script_with_requires
(
req
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
egg_info_dir
=
self
.
_find_egg_info_files
(
env
.
paths
[
'lib'
]).
base
requires_txt
=
os
.
path
.
join
(
egg_info_dir
,
'requires.txt'
)
with
open
(
requires_txt
)
as
fp
:
install_requires
=
fp
.
read
()
expected_requires
=
DALS
(
'''
[empty]
'''
).
format
(
marker
=
self
.
mismatch_marker_alternate
)
assert
install_requires
.
lstrip
()
==
expected_requires
def
test_python_requires_egg_info
(
self
,
tmpdir_cwd
,
env
):
self
.
_setup_script_with_requires
(
"""python_requires='>=2.7.12',"""
)
...
...
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