Skip to content

Commit

Permalink
Add a "only-version" version scheme (#1005)
Browse files Browse the repository at this point in the history
* Add "just-tag"

* docs too

* rename

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Dont autoformat this

* docs warning

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
thejcannon and pre-commit-ci[bot] authored Jan 19, 2024
1 parent ac3b6e1 commit a23d5fe
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/extending.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ representing the version.
`no-guess-dev`
: Does no next version guessing, just adds `.post1.devN`

`only-version`
: Only use the version from the tag, as given.

!!! warning "This means version is no longer pseudo unique per commit"


### `setuptools_scm.local_scheme`
Configures how the local part of a version is rendered given a
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ PKG-INFO = "setuptools_scm.fallbacks:parse_pkginfo"
"calver-by-date" = "setuptools_scm.version:calver_by_date"
"guess-next-dev" = "setuptools_scm.version:guess_next_dev_version"
"no-guess-dev" = "setuptools_scm.version:no_guess_dev_version"
"only-version" = "setuptools_scm.version:only_version"
"post-release" = "setuptools_scm.version:postrelease_version"
"python-simplified-semver" = "setuptools_scm.version:simplified_semver_version"
"release-branch-semver" = "setuptools_scm.version:release_branch_semver_version"
Expand Down
4 changes: 4 additions & 0 deletions src/setuptools_scm/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ def release_branch_semver(version: ScmVersion) -> str:
return release_branch_semver_version(version)


def only_version(version: ScmVersion) -> str:
return version.format_with("{tag}")


def no_guess_dev_version(version: ScmVersion) -> str:
if version.exact:
return version.format_with("{tag}")
Expand Down
28 changes: 28 additions & 0 deletions testing/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from setuptools_scm.version import guess_next_version
from setuptools_scm.version import meta
from setuptools_scm.version import no_guess_dev_version
from setuptools_scm.version import only_version
from setuptools_scm.version import release_branch_semver_version
from setuptools_scm.version import ScmVersion
from setuptools_scm.version import simplified_semver_version
Expand Down Expand Up @@ -170,6 +171,33 @@ def test_bump_dev_version_nonzero_raises() -> None:
guess_next_version(m("1.0.dev1"))


@pytest.mark.parametrize(
"version",
[
"1.dev0",
"1.0.dev456",
"1.0a1",
"1.0a2.dev456",
"1.0a12.dev456",
"1.0a12",
"1.0b1.dev456",
"1.0b2",
"1.0b2.post345.dev456",
"1.0b2.post345",
"1.0rc1.dev456",
"1.0rc1",
"1.0",
"1.0.post456.dev34",
"1.0.post456",
"1.0.15",
"1.1.dev1",
],
)
def test_only_version(version: str) -> None:
assert version == only_version(meta(version, config=c))
assert version == only_version(meta(version, distance=2, config=c))


@pytest.mark.parametrize(
("tag", "expected"),
[
Expand Down

0 comments on commit a23d5fe

Please sign in to comment.