Skip to content

Commit

Permalink
Add deprecation messages for namespace_packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Apr 11, 2022
1 parent 5bd3e98 commit 968e5fd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
11 changes: 11 additions & 0 deletions setuptools/config/_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -319,6 +327,9 @@ def _acessor(obj):
}

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"}
Expand Down
12 changes: 9 additions & 3 deletions setuptools/config/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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

Expand Down Expand Up @@ -507,7 +508,7 @@ def parsers(self):
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),
Expand All @@ -516,7 +517,7 @@ def parsers(self):
exclude_files_parser('license_file'),
"The license_file parameter is deprecated, "
"use license_files instead.",
DeprecationWarning,
SetuptoolsDeprecationWarning,
),
'license_files': parse_list,
'description': parse_file,
Expand Down Expand Up @@ -584,7 +585,12 @@ def parsers(self):
'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,
Expand Down
5 changes: 5 additions & 0 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,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):
Expand Down
17 changes: 17 additions & 0 deletions setuptools/tests/config/test_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io
import re
import tarfile
from inspect import cleandoc
from pathlib import Path
from unittest.mock import Mock
from zipfile import ZipFile
Expand All @@ -14,6 +15,7 @@
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
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions setuptools/tests/config/test_setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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
Expand Down Expand Up @@ -409,7 +410,7 @@ def test_deprecated_config_handlers(self, tmpdir):
'requires = some, requirement\n',
)

with pytest.deprecated_call():
with pytest.warns(SetuptoolsDeprecationWarning, match="requires"):
with get_dist(tmpdir) as dist:
metadata = dist.metadata

Expand Down Expand Up @@ -518,7 +519,8 @@ def test_basic(self, tmpdir):
'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'}
Expand Down Expand Up @@ -572,7 +574,8 @@ def test_multiline(self, tmpdir):
' 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']
Expand Down

0 comments on commit 968e5fd

Please sign in to comment.