Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support UV_DYNAMIC_VERSIONING_BYPASS to bypass version resolution #7

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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