From fdd6abccb4d6764b9bc58936073e18c05e6cedf9 Mon Sep 17 00:00:00 2001 From: Maxim Martynov Date: Mon, 8 Apr 2024 17:59:15 +0300 Subject: [PATCH] Drop deprecated functions & config options --- CHANGELOG.rst | 22 +++ README.rst | 4 +- docs/options/enabled.rst | 12 -- setup.py | 3 +- setuptools_git_versioning.py | 47 +------ tests/lib/util.py | 7 +- .../test_integration/test_branch_formatter.py | 9 +- tests/test_integration/test_config.py | 129 +++--------------- .../test_integration/test_version_callback.py | 4 +- 9 files changed, 55 insertions(+), 182 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index dc3de5c..3b77ccb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,28 @@ Changelog ========== +2.0 +--- + +.. changelog:: + :version: 2.0.0 + + .. change:: + :tags: config, breaking + + Drop ``version_config`` keyword from ``setup.py``, which was deprecated since ``1.8.0``. + + .. change:: + :tags: config, breaking + + Does not allow passing ``setuptools_git_versioning=False`` and ``setuptools_git_versioning=True`` to config. + Always use ``setuptools_git_versioning={"enabled": True}``. + + .. change:: + :tags: core, breaking + + Drop ``get_branch_tags`` function which was deprecated since ``1.8.0``. + 1.13 ---- diff --git a/README.rst b/README.rst index 55864e3..fd2b0ef 100644 --- a/README.rst +++ b/README.rst @@ -81,7 +81,7 @@ add a section ``tool.setuptools-git-versioning`` with config options, and mark t .. code:: toml [build-system] - requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning<2", ] + requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=2.0,<3", ] build-backend = "setuptools.build_meta" [tool.setuptools-git-versioning] @@ -117,7 +117,7 @@ and then add new argument ``setuptools_git_versioning`` with config options: setuptools_git_versioning={ "enabled": True, }, - setup_requires=["setuptools-git-versioning<2"], + setup_requires=["setuptools-git-versioning>=2.0,<3"], ) And check the package version generated (see `command help `__): diff --git a/docs/options/enabled.rst b/docs/options/enabled.rst index f635300..a26ae12 100644 --- a/docs/options/enabled.rst +++ b/docs/options/enabled.rst @@ -20,15 +20,3 @@ is the same as ``"enabled": False``. **This is because we don't want to mess up existing projects which are not using this tool** If any other config value is set, default value is ``True``. - -.. warning:: - - Previously it was allowed to pass boolean value to the entire config, like: - - .. code:: python - - setuptools.setup(setuptools_git_versioning=False, ...) - - This has the same meaning as ``"enabled"`` option of config, but it is deprecated since v1.8.0. - - Please replace this value with new syntax. The old syntax support will be removed in v2.0.0 diff --git a/setup.py b/setup.py index 982220e..d3aadfc 100644 --- a/setup.py +++ b/setup.py @@ -56,8 +56,7 @@ def parse_requirements(file: Path) -> list[str]: setup_requires=requirements, entry_points={ "distutils.setup_keywords": [ - "version_config = setuptools_git_versioning:_parse_config", - "setuptools_git_versioning = setuptools_git_versioning:_parse_config", + "setuptools_git_versioning = setuptools_git_versioning:parse_config", ], "setuptools.finalize_distribution_options": [ "setuptools_git_versioning = setuptools_git_versioning:infer_version", diff --git a/setuptools_git_versioning.py b/setuptools_git_versioning.py index 68e2187..fe21a68 100644 --- a/setuptools_git_versioning.py +++ b/setuptools_git_versioning.py @@ -9,7 +9,6 @@ import subprocess # nosec import sys import textwrap -import warnings from datetime import datetime from pathlib import Path from pprint import pformat @@ -104,18 +103,6 @@ def get_all_tags(sort_by: str = DEFAULT_SORT_BY, root: str | os.PathLike | None return [] -def get_branch_tags(*args, **kwargs) -> list[str]: - warnings.warn( - "`get_branch_tags` function is deprecated " - "since setuptools-git-versioning v1.8.0 " - "and will be dropped in v2.0.0\n" - "Please use `get_tags` instead", - category=UserWarning, - ) - - return get_tags(*args, **kwargs) - - def get_tags( sort_by: str = DEFAULT_SORT_BY, filter_callback: Callable[[str], str | None] | None = None, @@ -232,24 +219,9 @@ def _infer_setup_py(name_or_path: str = "setup.py", root: str | os.PathLike | No os.chdir(original_cwd) -# TODO: remove along with version_config -def _parse_config(dist: Distribution, attr: Any, value: Any) -> None: - from distutils.errors import DistutilsOptionError - - if attr == "version_config" and value is not None: - warnings.warn( - "'version_config' option is deprecated " - "since setuptools-git-versioning v1.8.0 " - "and will be dropped in v2.0.0\n" - "Please rename it to 'setuptools_git_versioning'", - category=UserWarning, - ) - - if getattr(dist, "setuptools_git_versioning", None) is not None: - raise DistutilsOptionError( - "You can set either 'version_config' or 'setuptools_git_versioning' " - "but not both of them at the same time" - ) +def parse_config(dist: Distribution, attr: Any, value: Any) -> None: + "Dummy function used only to register in distutils" + return None def infer_version(dist: Distribution, root: str | os.PathLike | None = None) -> str | None: @@ -257,18 +229,7 @@ def infer_version(dist: Distribution, root: str | os.PathLike | None = None) -> from distutils.errors import DistutilsOptionError, DistutilsSetupError - config = getattr(dist, "setuptools_git_versioning", None) or getattr(dist, "version_config", None) - - if isinstance(config, bool): - warnings.warn( - "Passing boolean value to 'version_config'/'setuptools_git_versioning' option is deprecated " - "since setuptools-git-versioning 1.8.0 " - "and will be dropped in v2.0.0\n" - "Please change value to '{'enabled': False/True}'", - category=UserWarning, - ) - config = {"enabled": config} - + config = getattr(dist, "setuptools_git_versioning", None) toml_config = _read_toml(root=root) if config is None: diff --git a/tests/lib/util.py b/tests/lib/util.py index ab218cf..30a6b57 100644 --- a/tests/lib/util.py +++ b/tests/lib/util.py @@ -223,7 +223,6 @@ def create_pyproject_toml( def create_setup_py( cwd: str | os.PathLike, config: dict | None = None, - option: str = "setuptools_git_versioning", **kwargs, ) -> str | None: if config is None: @@ -232,13 +231,13 @@ def create_setup_py( if config == NotImplemented: cfg = "" else: - cfg = f"{option}={config}," + cfg = f"setuptools_git_versioning={config}," return create_file( cwd, "setup.py", textwrap.dedent( - """ + f""" from coverage.control import Coverage coverage = Coverage() @@ -261,7 +260,7 @@ def create_setup_py( coverage.stop() coverage.save() """ - ).format(cfg=cfg), + ), **kwargs, ) diff --git a/tests/test_integration/test_branch_formatter.py b/tests/test_integration/test_branch_formatter.py index f2f53dc..c6547f2 100644 --- a/tests/test_integration/test_branch_formatter.py +++ b/tests/test_integration/test_branch_formatter.py @@ -1,5 +1,4 @@ import os -import pickle import subprocess import textwrap @@ -118,13 +117,11 @@ def test_branch_formatter_external_setup_py_direct_import(repo, template_config) checkout_branch(repo, branch) def config_creator(root, cfg): - conf = pickle.dumps(cfg) - return create_file( root, "setup.py", textwrap.dedent( - """ + f""" from coverage.control import Coverage coverage = Coverage() @@ -138,7 +135,7 @@ def config_creator(root, cfg): def branch_formatter(branch): return re.sub("[^\\d]+", "", branch) - version_config = pickle.loads({conf}) + version_config = {cfg} version_config["branch_formatter"] = branch_formatter setuptools.setup( @@ -154,7 +151,7 @@ def branch_formatter(branch): coverage.stop() coverage.save() """ - ).format(conf=conf), + ), ) template_config(repo, config_creator, template="{tag}.{branch}{ccount}") diff --git a/tests/test_integration/test_config.py b/tests/test_integration/test_config.py index c41b353..5e40988 100644 --- a/tests/test_integration/test_config.py +++ b/tests/test_integration/test_config.py @@ -1,4 +1,3 @@ -import itertools import os import subprocess import textwrap @@ -84,49 +83,8 @@ def test_config_not_used(repo): get_version_script(repo) -@pytest.mark.parametrize( - "value", - [True, False], -) -def test_config_bool_pyproject_toml(repo, value): - create_pyproject_toml(repo, value) - - with pytest.raises(subprocess.CalledProcessError): - get_version(repo) - - with pytest.raises(subprocess.CalledProcessError): - get_version_module(repo) - - with pytest.raises(subprocess.CalledProcessError): - get_version_script(repo) - - -@pytest.mark.parametrize( - "option", - ["version_config", "setuptools_git_versioning"], -) -def test_config_false_setup_py(repo, option): - create_setup_py(repo, False, option=option) - - assert get_version_setup_py(repo) == "0.0.0" - - -@pytest.mark.parametrize( - "option", - ["version_config", "setuptools_git_versioning"], -) -def test_config_true_setup_py(repo, option): - create_setup_py(repo, True, option=option) - - assert get_version_setup_py(repo) == "0.0.1" - - -@pytest.mark.parametrize( - "option", - ["version_config", "setuptools_git_versioning"], -) -def test_config_enabled_true(repo, create_config, option): - create_config(repo, {"enabled": True}, option=option) +def test_config_enabled_true(repo, create_config): + create_config(repo, {"enabled": True}) assert get_version(repo) == "0.0.1" assert get_version_script(repo) == "0.0.1" @@ -138,23 +96,29 @@ def test_config_enabled_true(repo, create_config, option): @pytest.mark.parametrize( - "option", - ["version_config", "setuptools_git_versioning"], + "value", + [ + True, + False, + [("A", "B")], + ], ) -def test_config_wrong_format(repo, create_config, option): - create_config(repo, [("A", "B")], option=option) +def test_config_wrong_format(repo, create_config, value): + create_config(repo, value) with pytest.raises(subprocess.CalledProcessError): get_version(repo) + with pytest.raises(subprocess.CalledProcessError): + get_version_module(repo) -@pytest.mark.parametrize( - "option", - ["version_config", "setuptools_git_versioning"], -) -def test_config_pyproject_toml_is_used_then_setup_py_is_empty(repo, option): + with pytest.raises(subprocess.CalledProcessError): + get_version_script(repo) + + +def test_config_pyproject_toml_is_used_then_setup_py_is_empty(repo): create_pyproject_toml(repo, {"starting_version": "2.3.4"}, add=False, commit=False) - create_setup_py(repo, NotImplemented, option=option, add=False, commit=False) + create_setup_py(repo, NotImplemented, add=False, commit=False) assert get_version(repo) == "2.3.4" assert get_version_script(repo) == "2.3.4" @@ -239,60 +203,3 @@ def test_config_pyproject_toml_is_folder(repo): with pytest.raises(subprocess.CalledProcessError): get_version_script(repo) - - -@pytest.mark.parametrize( - "version_config, setuptools_git_versioning", - itertools.combinations( - [ - False, - True, - {"enabled": True}, - {"enabled": False}, - {"any": "abc"}, - ], - 2, - ), -) -def test_config_both_old_and_new_config_are_set(repo, version_config, setuptools_git_versioning): - create_file( - repo, - "setup.py", - textwrap.dedent( - """ - from coverage.control import Coverage - - coverage = Coverage() - coverage.start() - - try: - import setuptools - - setuptools.setup( - name="mypkg", - setuptools_git_versioning={setuptools_git_versioning}, - version_config={version_config}, - setup_requires=[ - "setuptools>=41", - "wheel", - "setuptools-git-versioning", - ] - ) - finally: - coverage.stop() - coverage.save() - """ - ).format(version_config=version_config, setuptools_git_versioning=setuptools_git_versioning), - ) - - with pytest.raises(subprocess.CalledProcessError): - get_version(repo) - - with pytest.raises(subprocess.CalledProcessError): - get_version_setup_py(repo) - - with pytest.raises(subprocess.CalledProcessError): - get_version_module(repo) - - with pytest.raises(subprocess.CalledProcessError): - get_version_script(repo) diff --git a/tests/test_integration/test_version_callback.py b/tests/test_integration/test_version_callback.py index 8996ed5..e73d8a0 100644 --- a/tests/test_integration/test_version_callback.py +++ b/tests/test_integration/test_version_callback.py @@ -32,7 +32,7 @@ from version import get_version setuptools.setup( - version_config={ + setuptools_git_versioning={ "version_callback": get_version }, setup_requires=[ @@ -58,7 +58,7 @@ from version import __version__ setuptools.setup( - version_config={ + setuptools_git_versioning={ "version_callback": __version__ }, setup_requires=[