Merge "packaging: Remove support for pyN requirement files"

This commit is contained in:
Zuul 2018-10-06 21:14:59 +00:00 committed by Gerrit Code Review
commit 32bfe7808f
4 changed files with 14 additions and 35 deletions

View File

@ -204,14 +204,16 @@ for your project and will then parse these files, split them up appropriately,
and inject them into the ``install_requires``, ``tests_require`` and/or
``dependency_links`` 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 then just drop a
``requirements-py3.txt`` and it will be used instead.
Finally, it is possible to specify groups of optional dependencies, or
:ref:`"extra" requirements <extra-requirements>`, in your ``setup.cfg`` rather
than ``setup.py``.
.. versionchanged:: 5.0
Previously you could specify requirements for a given major version of
Python using requirments files with a ``-pyN`` suffix. This was deprecated
in 4.0 and removed in 5.0 in favour of environment markers.
Automatic File Generation
-------------------------

View File

@ -382,20 +382,18 @@ Requirements
Requirements files are used in place of the ``install_requires`` and
``extras_require`` attributes. Requirement files should be given one of the
below names. This order is also the order that the requirements are tried in
(where ``N`` is the Python major version number used to install the package):
below names. This order is also the order that the requirements are tried in:
* ``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.
.. note::
.. versionchanged:: 5.0
The ``requirements-pyN.txt`` file is deprecated - ``requirements.txt``
should be universal. You can use `Environment markers`_ for this purpose.
Previously you could specify requirements for a given major version of
Python using requirements files with a ``-pyN`` suffix. This was deprecated
in 4.0 and removed in 5.0 in favour of environment markers.
.. _extra-requirements:

View File

@ -81,14 +81,16 @@ def _any_existing(file_list):
def get_reqs_from_files(requirements_files):
existing = _any_existing(requirements_files)
# TODO(stephenfin): Remove this in pbr 6.0+
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. '
'removed in pbr 5.0 and these files are now ignored. '
'Use environment markers instead. Conflicting files: '
'%r' % deprecated,
DeprecationWarning)
existing = [f for f in existing if f not in PY_REQUIREMENTS_FILES]
for requirements_file in existing:
with open(requirements_file, 'r') as fil:
return fil.read().split('\n')

View File

@ -43,7 +43,6 @@ import email.errors
import imp
import os
import re
import sys
import sysconfig
import tempfile
import textwrap
@ -549,28 +548,6 @@ class ParseRequirementsTest(base.BaseTestCase):
result = packaging.parse_requirements([requirements])
self.assertEqual(['pbr'], result)
@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)
@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],
"w") as fh:
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):