Skip to content

Commit

Permalink
Drop deprecated functions & config options
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Apr 8, 2024
1 parent 4268ef4 commit fdd6abc
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 182 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
----

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 <https://setuptools-git-versioning.readthedocs.io/en/stable/command.html>`__):
Expand Down
12 changes: 0 additions & 12 deletions docs/options/enabled.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 4 additions & 43 deletions setuptools_git_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -232,43 +219,17 @@ 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:
log.log(INFO, "Trying 'setup.py' ...")

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:
Expand Down
7 changes: 3 additions & 4 deletions tests/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand All @@ -261,7 +260,7 @@ def create_setup_py(
coverage.stop()
coverage.save()
"""
).format(cfg=cfg),
),
**kwargs,
)

Expand Down
9 changes: 3 additions & 6 deletions tests/test_integration/test_branch_formatter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import pickle
import subprocess
import textwrap

Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand All @@ -154,7 +151,7 @@ def branch_formatter(branch):
coverage.stop()
coverage.save()
"""
).format(conf=conf),
),
)

template_config(repo, config_creator, template="{tag}.{branch}{ccount}")
Expand Down
129 changes: 18 additions & 111 deletions tests/test_integration/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import itertools
import os
import subprocess
import textwrap
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions tests/test_integration/test_version_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from version import get_version
setuptools.setup(
version_config={
setuptools_git_versioning={
"version_callback": get_version
},
setup_requires=[
Expand All @@ -58,7 +58,7 @@
from version import __version__
setuptools.setup(
version_config={
setuptools_git_versioning={
"version_callback": __version__
},
setup_requires=[
Expand Down

0 comments on commit fdd6abc

Please sign in to comment.