Commit a6a5040a authored by Sreejith Menon's avatar Sreejith Menon Committed by Paul Ganssle

Deprecate the requires keyword

For runtime dependencies, install_requires should be used. For build
dependencies, a PEP 518-compliant `pyproject.toml` should be used.

Other dependencies can use extra requirements.
parent fb84b3fd
...@@ -2,8 +2,10 @@ from __future__ import absolute_import, unicode_literals ...@@ -2,8 +2,10 @@ from __future__ import absolute_import, unicode_literals
import io import io
import os import os
import sys import sys
import warnings
from collections import defaultdict from collections import defaultdict
from functools import partial from functools import partial
from functools import wraps
from importlib import import_module from importlib import import_module
from distutils.errors import DistutilsOptionError, DistutilsFileError from distutils.errors import DistutilsOptionError, DistutilsFileError
...@@ -399,6 +401,20 @@ class ConfigHandler: ...@@ -399,6 +401,20 @@ class ConfigHandler:
section_parser_method(section_options) section_parser_method(section_options)
def _deprecated_config_handler(self, func, msg, warning_class):
""" this function will wrap around parameters that are deprecated
:param msg: deprecation message
:param warning_class: class of warning exception to be raised
:param func: function to be wrapped around
"""
@wraps(func)
def config_handler(*args, **kwargs):
warnings.warn(msg, warning_class)
return func(*args, **kwargs)
return config_handler
class ConfigMetadataHandler(ConfigHandler): class ConfigMetadataHandler(ConfigHandler):
...@@ -434,7 +450,10 @@ class ConfigMetadataHandler(ConfigHandler): ...@@ -434,7 +450,10 @@ class ConfigMetadataHandler(ConfigHandler):
'platforms': parse_list, 'platforms': parse_list,
'keywords': parse_list, 'keywords': parse_list,
'provides': parse_list, 'provides': parse_list,
'requires': parse_list, 'requires': self._deprecated_config_handler(parse_list,
"The requires parameter is deprecated, please use " +
"install_requires for runtime dependencies.",
DeprecationWarning),
'obsoletes': parse_list, 'obsoletes': parse_list,
'classifiers': self._get_parser_compound(parse_file, parse_list), 'classifiers': self._get_parser_compound(parse_file, parse_list),
'license': parse_file, 'license': parse_file,
......
...@@ -391,6 +391,23 @@ class TestMetadata: ...@@ -391,6 +391,23 @@ class TestMetadata:
with get_dist(tmpdir) as dist: with get_dist(tmpdir) as dist:
assert set(dist.metadata.classifiers) == expected assert set(dist.metadata.classifiers) == expected
def test_deprecated_config_handlers(self, tmpdir):
fake_env(
tmpdir,
'[metadata]\n'
'version = 10.1.1\n'
'description = Some description\n'
'requires = some, requirement\n'
)
with pytest.deprecated_call():
with get_dist(tmpdir) as dist:
metadata = dist.metadata
assert metadata.version == '10.1.1'
assert metadata.description == 'Some description'
assert metadata.requires == ['some', 'requirement']
class TestOptions: class TestOptions:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment