package: read a specific Python version requirement file
This change makes pbr reads a specific requirement file tight to the major Python version that is used. So you can add a file such as requirements-py3.txt to have a specific requirement file for Python 3, or requirements-py2.txt to have a specific requirement file for Python 2. Change-Id: I4b548e9830586f11b82539d334dd5cf4b0445a36
This commit is contained in:
@@ -67,6 +67,21 @@ your project, will parse them and split them up approprirately, and inject
|
|||||||
them into the install_requires and/or tests_require and/or dependency_links
|
them into the install_requires and/or tests_require and/or dependency_links
|
||||||
arguments to setup. Voila!
|
arguments to setup. Voila!
|
||||||
|
|
||||||
|
You can also have a requirement file for each specific major version of
|
||||||
|
Python. If you want to have a different package list for Python 3, just drop
|
||||||
|
a requirements-py3.txt, and it will be used instead.
|
||||||
|
|
||||||
|
The requirement files are tried in that order (N being the Python major
|
||||||
|
version number used to install the package):
|
||||||
|
|
||||||
|
* requirements-pyN.txt
|
||||||
|
* tools/pip-requires-py3
|
||||||
|
* requirements.txt
|
||||||
|
* tools/pip-requires
|
||||||
|
|
||||||
|
Only the first file found is used to install the list of packages it
|
||||||
|
contains.
|
||||||
|
|
||||||
long_description
|
long_description
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,13 @@ def get_requirements_files():
|
|||||||
files = os.environ.get("PBR_REQUIREMENTS_FILES")
|
files = os.environ.get("PBR_REQUIREMENTS_FILES")
|
||||||
if files:
|
if files:
|
||||||
return tuple(f.strip() for f in files.split(','))
|
return tuple(f.strip() for f in files.split(','))
|
||||||
return REQUIREMENTS_FILES
|
# Returns a list composed of:
|
||||||
|
# - REQUIREMENTS_FILES with -py2 or -py3 in the name
|
||||||
|
# (e.g. requirements-py3.txt)
|
||||||
|
# - REQUIREMENTS_FILES
|
||||||
|
return (list(map(('-py' + str(sys.version_info[0])).join,
|
||||||
|
map(os.path.splitext, REQUIREMENTS_FILES)))
|
||||||
|
+ list(REQUIREMENTS_FILES))
|
||||||
|
|
||||||
|
|
||||||
def append_text_list(config, key, text_list):
|
def append_text_list(config, key, text_list):
|
||||||
|
|||||||
@@ -352,6 +352,22 @@ class ParseRequirementsTest(base.BaseTestCase):
|
|||||||
self.assertEqual(['foobar', 'foobaz'],
|
self.assertEqual(['foobar', 'foobaz'],
|
||||||
packaging.parse_requirements([self.tmp_file]))
|
packaging.parse_requirements([self.tmp_file]))
|
||||||
|
|
||||||
|
def test_parse_requirements_python_version(self):
|
||||||
|
with open("requirements-py%d.txt" % sys.version_info[0],
|
||||||
|
"w") as fh:
|
||||||
|
fh.write("# this is a comment\nfoobar\n# and another one\nfoobaz")
|
||||||
|
self.assertEqual(['foobar', 'foobaz'],
|
||||||
|
packaging.parse_requirements())
|
||||||
|
|
||||||
|
def test_parse_requirements_right_python_version(self):
|
||||||
|
with open("requirements-py1.txt", "w") as fh:
|
||||||
|
fh.write("thisisatrap")
|
||||||
|
with open("requirements-py%d.txt" % sys.version_info[0],
|
||||||
|
"w") as fh:
|
||||||
|
fh.write("# this is a comment\nfoobar\n# and another one\nfoobaz")
|
||||||
|
self.assertEqual(['foobar', 'foobaz'],
|
||||||
|
packaging.parse_requirements())
|
||||||
|
|
||||||
|
|
||||||
class ParseDependencyLinksTest(base.BaseTestCase):
|
class ParseDependencyLinksTest(base.BaseTestCase):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user