-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,4 +80,4 @@ venv/ | |
.DS_Store | ||
|
||
# build metadata written by hatch | ||
src/mitoanalyzer/_version.p | ||
src/mitosisanalyzer/_version.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import _version | ||
|
||
__version__ = _version.__version__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
import textwrap | ||
from datetime import datetime, timezone | ||
from pathlib import Path | ||
from subprocess import CalledProcessError, check_output | ||
from typing import Any | ||
|
||
|
||
def write_version_info( | ||
project_dir: str | Path, template_fields: dict[str, Any], params: dict[str, Any] | ||
) -> None: | ||
""" | ||
Write the build info to the project directory. | ||
""" | ||
path = Path(project_dir) / params.get("path", "src/mitosisanalyzer/_version.py") | ||
|
||
try: | ||
git_hash = check_output(["git", "rev-parse", "HEAD"]).decode().strip() | ||
except CalledProcessError: | ||
git_hash = "unknown" | ||
|
||
build_dt_str = template_fields.get( | ||
"build_date", datetime.now(timezone.utc).isoformat() | ||
) | ||
version = template_fields.get("version", "unknown") | ||
dirty = "dirty" in version | ||
|
||
build_info = textwrap.dedent( | ||
f"""\ | ||
# Generated by versioningit | ||
__version__ = "{version}" | ||
__build_date__ = "{build_dt_str}" | ||
__git_commit__ = "{git_hash}" | ||
__dirty__ = {dirty} | ||
""" | ||
) | ||
|
||
with open(path, "w") as f: | ||
f.write(build_info) |