summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2017-10-16 11:43:02 +0100
committerStephen Finucane <sfinucan@redhat.com>2018-01-09 14:31:01 +0000
commit9be181e8e60cc41f3ad685e236b0c4cdc29dbd3c (patch)
tree5d9611b4ecee039033120d1271fc9e360d23f813
parentf4a1a7dec0c21a6b817eb1e662a0f0bf10901cf4 (diff)
downloadpbr-9be181e8e60cc41f3ad685e236b0c4cdc29dbd3c.tar.gz
deprecations: Deprecate support for '-py{N}' requirements
This has been marked as deprecated for a long time in the docs but we've done nothing to indicate this from a code perspective. Fix this. Change-Id: I916bf16773a2a2cffa3c352d5dba52e3fbc298c2 Fixes-Bug: #431529
-rw-r--r--pbr/packaging.py20
-rw-r--r--pbr/tests/test_packaging.py10
-rw-r--r--releasenotes/notes/deprecate-pyN-requirements-364655c38fa5b780.yaml5
3 files changed, 29 insertions, 6 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py
index 0177437..38b4982 100644
--- a/pbr/packaging.py
+++ b/pbr/packaging.py
@@ -46,6 +46,8 @@ from pbr import testr_command
from pbr import version
REQUIREMENTS_FILES = ('requirements.txt', 'tools/pip-requires')
+PY_REQUIREMENTS_FILES = [x % sys.version_info[0] for x in (
+ 'requirements-py%d.txt', 'tools/pip-requires-py%d')]
TEST_REQUIREMENTS_FILES = ('test-requirements.txt', 'tools/test-requires')
@@ -57,9 +59,8 @@ def get_requirements_files():
# - 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))
+
+ return PY_REQUIREMENTS_FILES + list(REQUIREMENTS_FILES)
def append_text_list(config, key, text_list):
@@ -78,9 +79,20 @@ def _any_existing(file_list):
# Get requirements from the first file that exists
def get_reqs_from_files(requirements_files):
- for requirements_file in _any_existing(requirements_files):
+ existing = _any_existing(requirements_files)
+
+ deprecated = [f for f in existing if f in PY_REQUIREMENTS_FILES]
+ if deprecated:
+ warnings.warn('Support for \'-pyN\'-suffixed requirements files is '
+ 'deprecated in pbr 4.0 and will be removed in 5.0. '
+ 'Use environment markers instead. Conflicting files: '
+ '%r' % deprecated,
+ DeprecationWarning)
+
+ for requirements_file in existing:
with open(requirements_file, 'r') as fil:
return fil.read().split('\n')
+
return []
diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py
index 526e12d..da221d7 100644
--- a/pbr/tests/test_packaging.py
+++ b/pbr/tests/test_packaging.py
@@ -549,14 +549,17 @@ class ParseRequirementsTest(base.BaseTestCase):
result = packaging.parse_requirements([requirements])
self.assertEqual(['pbr'], result)
- def test_python_version(self):
+ @mock.patch('warnings.warn')
+ def test_python_version(self, mock_warn):
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())
+ mock_warn.assert_called_once_with(mock.ANY, DeprecationWarning)
- def test_python_version_multiple_options(self):
+ @mock.patch('warnings.warn')
+ def test_python_version_multiple_options(self, mock_warn):
with open("requirements-py1.txt", "w") as fh:
fh.write("thisisatrap")
with open("requirements-py%d.txt" % sys.version_info[0],
@@ -564,6 +567,9 @@ class ParseRequirementsTest(base.BaseTestCase):
fh.write("# this is a comment\nfoobar\n# and another one\nfoobaz")
self.assertEqual(['foobar', 'foobaz'],
packaging.parse_requirements())
+ # even though we have multiple offending files, this should only be
+ # called once
+ mock_warn.assert_called_once_with(mock.ANY, DeprecationWarning)
class ParseRequirementsTestScenarios(base.BaseTestCase):
diff --git a/releasenotes/notes/deprecate-pyN-requirements-364655c38fa5b780.yaml b/releasenotes/notes/deprecate-pyN-requirements-364655c38fa5b780.yaml
new file mode 100644
index 0000000..3ed9bc7
--- /dev/null
+++ b/releasenotes/notes/deprecate-pyN-requirements-364655c38fa5b780.yaml
@@ -0,0 +1,5 @@
+---
+deprecations:
+ - |
+ Support for ``pyN``-suffixed requirement files has been deprecated:
+ environment markers should be used instead.