Skip to content

Commit

Permalink
Merge pull request #7 from iwanbolzern/main
Browse files Browse the repository at this point in the history
feat: support UV_DYNAMIC_VERSIONING_BYPASS to bypass version resolution
  • Loading branch information
ninoseki authored Nov 28, 2024
2 parents 82cb0b7 + 819e105 commit 3941908
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ vcs = "git"
style = "semver"
```

## Environment variables
In addition to the project-specific configuration above,
you can apply some global overrides via environment variables.

* `UV_DYNAMIC_VERSIONING_BYPASS`:
Use this to bypass the VCS mechanisms and use a static version instead.
The value of the environment variable will be used as the version
for the active project and any path/SSH dependencies that also use the plugin.
This is mainly for distro package maintainers who need to patch existing releases,
without needing access to the original repository.

## Alternatives

- [hatch-vcs](https://github.com/ofek/hatch-vcs)
Expand Down
5 changes: 5 additions & 0 deletions src/uv_dynamic_versioning/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

import tomlkit
Expand Down Expand Up @@ -25,6 +26,9 @@ def validate(project: tomlkit.TOMLDocument):

@safe
def get_version(config: schemas.UvDynamicVersioning) -> str:
if "UV_DYNAMIC_VERSIONING_BYPASS" in os.environ:
return os.environ["UV_DYNAMIC_VERSIONING_BYPASS"]

version = Version.from_vcs(
config.vcs,
latest_tag=config.latest_tag,
Expand All @@ -36,6 +40,7 @@ def get_version(config: schemas.UvDynamicVersioning) -> str:
pattern=config.pattern,
pattern_prefix=config.pattern_prefix,
)

return version.serialize(
metadata=config.metadata,
style=config.style,
Expand Down
27 changes: 27 additions & 0 deletions tests/test_env_bypass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

import pytest

from uv_dynamic_versioning import schemas
from uv_dynamic_versioning.main import get_version


@pytest.fixture
def version():
return "1.1.1"


@pytest.fixture
def set_uv_dynamic_versioning_bypass(version: str):
os.environ["UV_DYNAMIC_VERSIONING_BYPASS"] = version

try:
yield version
finally:
del os.environ["UV_DYNAMIC_VERSIONING_BYPASS"]


@pytest.mark.usefixtures("set_uv_dynamic_versioning_bypass")
def test_get_version(version: str):
got = get_version(schemas.UvDynamicVersioning()).unwrap()
assert got == version

0 comments on commit 3941908

Please sign in to comment.