-
Notifications
You must be signed in to change notification settings - Fork 21
unique version for each commit #409
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,84 +1,98 @@ | ||||||
| import re | ||||||
| import subprocess | ||||||
| from pathlib import Path | ||||||
|
|
||||||
| from setuptools_scm import ScmVersion, get_version | ||||||
| from setuptools_scm._integration.dump_version import write_version_to_path | ||||||
|
|
||||||
| BASE_DIR = Path(__file__).parent | ||||||
| REPO_DIR = BASE_DIR / ".." | ||||||
| PYRX_INIT_PY_TPL = BASE_DIR / "__init__.tpl" | ||||||
| PYRX_INIT_PY = BASE_DIR / "../pyrx/__init__.py" | ||||||
| BASE_VERSION_FILE = BASE_DIR / "version.txt" | ||||||
| PYRX_VERSION_PY = BASE_DIR / "../pyrx/_version.py" | ||||||
| PYRX_VERSION_H_TPL = BASE_DIR / "pyrx_version.tpl" | ||||||
| PYRX_VERSION_H = BASE_DIR / "../pyrx_version.h" | ||||||
| PYRX_PACKAGE_CONTENTS_TPL = BASE_DIR / "PackageContents.tpl" | ||||||
| PYRX_PACKAGE_CONTENTS = BASE_DIR / "../PyRxAcSetup/Include/PackageContents.xml" | ||||||
|
|
||||||
| MAJOR = 2 | ||||||
| MINOR = 2 | ||||||
| REVISION= 23 | ||||||
| BASE_VERSION_PATTERN = re.compile(r"^(\d+)\.(\d+)\.(\d+)$") | ||||||
|
|
||||||
| def custom_version_scheme(version: ScmVersion) -> str: | ||||||
| base_version = version.format_with("{tag}") | ||||||
|
|
||||||
| def get_base_version() -> str: | ||||||
| version = BASE_VERSION_FILE.read_text("utf-8").strip() | ||||||
| if not BASE_VERSION_PATTERN.fullmatch(version): | ||||||
| raise ValueError(f"Invalid version format: {version}") | ||||||
| return version | ||||||
|
|
||||||
|
|
||||||
| def get_revision_number() -> str: | ||||||
| number = subprocess.check_output( | ||||||
| ["git", "rev-list", "--count", "--first-parent", "main"], text=True | ||||||
| ).strip() | ||||||
| if not number.isdigit(): | ||||||
| raise ValueError(f"Revision number is not a digit: {number}") | ||||||
| return number | ||||||
|
|
||||||
|
|
||||||
| def get_project_version() -> tuple[str, tuple[str, str, str, str]]: | ||||||
| base_version = get_base_version() | ||||||
| try: | ||||||
| count = subprocess.check_output( | ||||||
| ["git", "rev-list", "--count", "--first-parent", "main"], text=True, cwd=REPO_DIR | ||||||
| ).strip() | ||||||
| revision = get_revision_number() | ||||||
| except Exception as err: | ||||||
| err.add_note("Failed to get commit count from git.") | ||||||
| raise err | ||||||
| version_tuple = parse_version(base_version) | ||||||
|
|
||||||
| return f"{base_version}.{count}" | ||||||
| return f"{base_version}.{revision}", (*version_tuple, revision) | ||||||
|
|
||||||
|
|
||||||
| def get_project_version(): | ||||||
| return get_version( | ||||||
| root=REPO_DIR, | ||||||
| version_scheme=custom_version_scheme, | ||||||
| local_scheme="no-local-version", | ||||||
| ) | ||||||
| def parse_version(version: str) -> tuple: | ||||||
|
||||||
| def parse_version(version: str) -> tuple: | |
| def parse_version(version: str) -> tuple[str, str, str]: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 2.2.23 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,8 +1,44 @@ | ||||||
| import re | ||||||
| import subprocess | ||||||
| from pathlib import Path | ||||||
|
|
||||||
| from setuptools import setup | ||||||
| from setuptools_scm import ScmVersion | ||||||
|
|
||||||
| BASE_DIR = Path(__file__).parent | ||||||
| BASE_VERSION_FILE = BASE_DIR / "Version/version.txt" | ||||||
| BASE_VERSION_PATTERN = re.compile(r"^(\d+)\.(\d+)\.(\d+)$") | ||||||
|
|
||||||
|
|
||||||
| def get_base_version() -> str: | ||||||
| version = BASE_VERSION_FILE.read_text("utf-8").strip() | ||||||
| if not BASE_VERSION_PATTERN.fullmatch(version): | ||||||
| raise ValueError(f"Invalid version format: {version}") | ||||||
| return version | ||||||
|
|
||||||
|
|
||||||
| def get_revision_number() -> str: | ||||||
| number = subprocess.check_output( | ||||||
| ["git", "rev-list", "--count", "--first-parent", "main"], text=True | ||||||
|
||||||
| ["git", "rev-list", "--count", "--first-parent", "main"], text=True | |
| ["git", "rev-list", "--count", "--first-parent", "main"], text=True, cwd=BASE_DIR |
Copilot
AI
Aug 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching all exceptions with except Exception: is too broad. Consider catching specific exceptions like subprocess.CalledProcessError or FileNotFoundError to handle known failure cases appropriately.
| except Exception: | |
| except (subprocess.CalledProcessError, FileNotFoundError, OSError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The subprocess call does not specify a working directory. This could lead to unexpected behavior if the script is run from a different directory. Consider adding
cwd=REPO_DIRparameter to ensure consistency.