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

Add support to overwrite version using VERSIONINGIT_PRETEND_VERSION #76

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 4 additions & 1 deletion src/versioningit/hatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .core import Report, Versioningit
from .errors import NoTagError, NotSdistError, NotVersioningitError
from .logging import init_logging, log
from .onbuild import HatchFileProvider
from .onbuild import HatchFileProvider, get_pretend_version


class VersioningitSource(VersionSourceInterface):
Expand All @@ -28,6 +28,9 @@ def get_version_data(self) -> dict:
init_logging()
PROJECT_ROOT = Path(self.root)
log.info("Project dir: %s", PROJECT_ROOT)
pretend_version = get_pretend_version()
if pretend_version is not None:
return {"version": pretend_version}
try:
vgit = Versioningit.from_project_dir(PROJECT_ROOT)
report = vgit.run(write=True, fallback=True)
Expand Down
5 changes: 5 additions & 0 deletions src/versioningit/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .core import Report, Versioningit
from .errors import NoTagError, NotSdistError, NotVersioningitError
from .logging import init_logging, log
from .onbuild import get_pretend_version

if TYPE_CHECKING:
from setuptools import Distribution
Expand All @@ -18,6 +19,10 @@ def setuptools_finalizer(dist: Distribution) -> None:
# root of the source tree".
PROJECT_ROOT = Path().resolve()
log.info("Project dir: %s", PROJECT_ROOT)
pretend_version = get_pretend_version()
if pretend_version is not None:
dist.metadata.version = pretend_version
return
try:
vgit = Versioningit.from_project_dir(PROJECT_ROOT)
report = vgit.run(write=True, fallback=True)
Expand Down
4 changes: 4 additions & 0 deletions src/versioningit/onbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,7 @@ def replace_version_onbuild(
return
with file.open("w", encoding=encoding) as fp:
fp.writelines(lines)


def get_pretend_version() -> str:
return os.getenv("VERSIONINGIT_PRETEND_VERSION")