summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-05-16 18:36:00 +0100
committerGitHub <noreply@github.com>2022-05-16 18:36:00 +0100
commit73bc126cd05b25a24e2a3e7ad347a245e980b673 (patch)
tree7a3d1a72f4e58565d0c8f6eecc509f6e7c36fa31 /setuptools
parent42d940f04e6d39e999ad184d4a6b5062957f4ae6 (diff)
parent269f3acbf4e3a2f717fb37dc23ff48bf36b8bc2a (diff)
downloadpython-setuptools-git-73bc126cd05b25a24e2a3e7ad347a245e980b673.tar.gz
Add deprecation messages for `namespace_packages` (#3262)
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/config/_apply_pyprojecttoml.py11
-rw-r--r--setuptools/config/setupcfg.py12
-rw-r--r--setuptools/dist.py5
-rw-r--r--setuptools/tests/config/test_apply_pyprojecttoml.py17
-rw-r--r--setuptools/tests/config/test_setupcfg.py9
5 files changed, 48 insertions, 6 deletions
diff --git a/setuptools/config/_apply_pyprojecttoml.py b/setuptools/config/_apply_pyprojecttoml.py
index 002cc4b8..4b4ed9df 100644
--- a/setuptools/config/_apply_pyprojecttoml.py
+++ b/setuptools/config/_apply_pyprojecttoml.py
@@ -16,6 +16,8 @@ from types import MappingProxyType
from typing import (TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Tuple,
Type, Union)
+from setuptools._deprecation_warning import SetuptoolsDeprecationWarning
+
if TYPE_CHECKING:
from setuptools._importlib import metadata # noqa
from setuptools.dist import Distribution # noqa
@@ -75,6 +77,12 @@ def _apply_tool_table(dist: "Distribution", config: dict, filename: _Path):
for field, value in tool_table.items():
norm_key = json_compatible_key(field)
+
+ if norm_key in TOOL_TABLE_DEPRECATIONS:
+ suggestion = TOOL_TABLE_DEPRECATIONS[norm_key]
+ msg = f"The parameter `{norm_key}` is deprecated, {suggestion}"
+ warnings.warn(msg, SetuptoolsDeprecationWarning)
+
norm_key = TOOL_TABLE_RENAMES.get(norm_key, norm_key)
_set_config(dist, norm_key, value)
@@ -307,6 +315,9 @@ PYPROJECT_CORRESPONDENCE: Dict[str, _Correspondence] = {
}
TOOL_TABLE_RENAMES = {"script_files": "scripts"}
+TOOL_TABLE_DEPRECATIONS = {
+ "namespace_packages": "consider using implicit namespaces instead (PEP 420)."
+}
SETUPTOOLS_PATCHES = {"long_description_content_type", "project_urls",
"provides_extras", "license_file", "license_files"}
diff --git a/setuptools/config/setupcfg.py b/setuptools/config/setupcfg.py
index d485a8bb..b2d5c346 100644
--- a/setuptools/config/setupcfg.py
+++ b/setuptools/config/setupcfg.py
@@ -12,6 +12,7 @@ from typing import (TYPE_CHECKING, Callable, Any, Dict, Generic, Iterable, List,
from distutils.errors import DistutilsOptionError, DistutilsFileError
from setuptools.extern.packaging.version import Version, InvalidVersion
from setuptools.extern.packaging.specifiers import SpecifierSet
+from setuptools._deprecation_warning import SetuptoolsDeprecationWarning
from . import expand
@@ -507,7 +508,7 @@ class ConfigMetadataHandler(ConfigHandler["DistributionMetadata"]):
parse_list,
"The requires parameter is deprecated, please use "
"install_requires for runtime dependencies.",
- DeprecationWarning,
+ SetuptoolsDeprecationWarning,
),
'obsoletes': parse_list,
'classifiers': self._get_parser_compound(parse_file, parse_list),
@@ -516,7 +517,7 @@ class ConfigMetadataHandler(ConfigHandler["DistributionMetadata"]):
exclude_files_parser('license_file'),
"The license_file parameter is deprecated, "
"use license_files instead.",
- DeprecationWarning,
+ SetuptoolsDeprecationWarning,
),
'license_files': parse_list,
'description': parse_file,
@@ -584,7 +585,12 @@ class ConfigOptionsHandler(ConfigHandler["Distribution"]):
'scripts': parse_list,
'eager_resources': parse_list,
'dependency_links': parse_list,
- 'namespace_packages': parse_list,
+ 'namespace_packages': self._deprecated_config_handler(
+ parse_list,
+ "The namespace_packages parameter is deprecated, "
+ "consider using implicit namespaces instead (PEP 420).",
+ SetuptoolsDeprecationWarning,
+ ),
'install_requires': parse_list_semicolon,
'setup_requires': parse_list_semicolon,
'tests_require': parse_list_semicolon,
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 5507167d..37021ac7 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -280,6 +280,11 @@ def check_nsp(dist, attr, value):
nsp,
parent,
)
+ msg = (
+ "The namespace_packages parameter is deprecated, "
+ "consider using implicit namespaces instead (PEP 420).",
+ )
+ warnings.warn(msg, SetuptoolsDeprecationWarning)
def check_extras(dist, attr, value):
diff --git a/setuptools/tests/config/test_apply_pyprojecttoml.py b/setuptools/tests/config/test_apply_pyprojecttoml.py
index 28643f0c..2194197f 100644
--- a/setuptools/tests/config/test_apply_pyprojecttoml.py
+++ b/setuptools/tests/config/test_apply_pyprojecttoml.py
@@ -6,6 +6,7 @@ To run these tests offline, please have a look on ``./downloads/preload.py``
import io
import re
import tarfile
+from inspect import cleandoc
from pathlib import Path
from unittest.mock import Mock
from zipfile import ZipFile
@@ -14,6 +15,7 @@ import pytest
from ini2toml.api import Translator
import setuptools # noqa ensure monkey patch to metadata
+from setuptools._deprecation_warning import SetuptoolsDeprecationWarning
from setuptools.dist import Distribution
from setuptools.config import setupcfg, pyprojecttoml
from setuptools.config import expand
@@ -211,6 +213,21 @@ def test_license_and_license_files(tmp_path):
assert dist.metadata.license == "LicenseRef-Proprietary\n"
+class TestDeprecatedFields:
+ def test_namespace_packages(self, tmp_path):
+ pyproject = tmp_path / "pyproject.toml"
+ config = """
+ [project]
+ name = "myproj"
+ version = "42"
+ [tool.setuptools]
+ namespace-packages = ["myproj.pkg"]
+ """
+ pyproject.write_text(cleandoc(config), encoding="utf-8")
+ with pytest.warns(SetuptoolsDeprecationWarning, match="namespace_packages"):
+ pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
+
+
class TestPresetField:
def pyproject(self, tmp_path, dynamic, extra_content=""):
content = f"[project]\nname = 'proj'\ndynamic = {dynamic!r}\n"
diff --git a/setuptools/tests/config/test_setupcfg.py b/setuptools/tests/config/test_setupcfg.py
index 1f35f836..904b1ef8 100644
--- a/setuptools/tests/config/test_setupcfg.py
+++ b/setuptools/tests/config/test_setupcfg.py
@@ -7,6 +7,7 @@ from unittest.mock import Mock, patch
import pytest
from distutils.errors import DistutilsOptionError, DistutilsFileError
+from setuptools._deprecation_warning import SetuptoolsDeprecationWarning
from setuptools.dist import Distribution, _Distribution
from setuptools.config.setupcfg import ConfigHandler, read_configuration
from ..textwrap import DALS
@@ -409,7 +410,7 @@ class TestMetadata:
'requires = some, requirement\n',
)
- with pytest.deprecated_call():
+ with pytest.warns(SetuptoolsDeprecationWarning, match="requires"):
with get_dist(tmpdir) as dist:
metadata = dist.metadata
@@ -518,7 +519,8 @@ class TestOptions:
'python_requires = >=1.0, !=2.8\n'
'py_modules = module1, module2\n',
)
- with get_dist(tmpdir) as dist:
+ deprec = pytest.warns(SetuptoolsDeprecationWarning, match="namespace_packages")
+ with deprec, get_dist(tmpdir) as dist:
assert dist.zip_safe
assert dist.include_package_data
assert dist.package_dir == {'': 'src', 'b': 'c'}
@@ -572,7 +574,8 @@ class TestOptions:
' http://some.com/here/1\n'
' http://some.com/there/2\n',
)
- with get_dist(tmpdir) as dist:
+ deprec = pytest.warns(SetuptoolsDeprecationWarning, match="namespace_packages")
+ with deprec, get_dist(tmpdir) as dist:
assert dist.package_dir == {'': 'src', 'b': 'c'}
assert dist.packages == ['pack_a', 'pack_b.subpack']
assert dist.namespace_packages == ['pack1', 'pack2']