-
Notifications
You must be signed in to change notification settings - Fork 2
get version from latest git tag #217
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||
| from glob import glob | ||||||||||||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||
| GDAL_LIBRARY_PATH = glob("/usr/lib/libgdal.so.*")[0] | ||||||||||||||||||||||||||||||||
|
|
@@ -230,9 +231,13 @@ | |||||||||||||||||||||||||||||||
| TINYMCE_FILEBROWSER = False | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Add Version to the admin site header | ||||||||||||||||||||||||||||||||
| VERSION = "2.2.2" | ||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||
| VERSION = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]).decode("utf-8").strip() | ||||||||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||||||||
| VERSION = "unknown" | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| VERSION = "unknown" | |
| VERSION = os.environ.get("APP_VERSION", "unknown") |
Copilot
AI
Nov 14, 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.
[nitpick] The subprocess call executes every time the settings module is imported, which can happen multiple times during the application lifecycle (e.g., management commands, worker processes, tests). Consider caching the result or using lazy evaluation to avoid repeated git command executions.
Example with lazy evaluation:
_VERSION = None
def get_version():
global _VERSION
if _VERSION is None:
try:
_VERSION = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]).decode("utf-8").strip()
except (subprocess.CalledProcessError, FileNotFoundError, OSError):
_VERSION = os.environ.get("APP_VERSION", "unknown")
return _VERSION
VERSION = get_version()Alternatively, consider setting the version once during deployment (e.g., in an environment variable or a version file) rather than executing git at runtime.
| try: | |
| VERSION = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]).decode("utf-8").strip() | |
| except Exception: | |
| VERSION = "unknown" | |
| _VERSION = None | |
| def get_version(): | |
| global _VERSION | |
| if _VERSION is None: | |
| try: | |
| _VERSION = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]).decode("utf-8").strip() | |
| except (subprocess.CalledProcessError, FileNotFoundError, OSError, Exception): | |
| _VERSION = "unknown" | |
| return _VERSION | |
| VERSION = get_version() |
Copilot
AI
Nov 14, 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.
[nitpick] The "v" prefix was removed from the admin header format string, likely assuming git tags include the "v" prefix (e.g., "v2.2.2"). However, this creates an inconsistency:
- If tags have "v" prefix: displays "ITK DB Admin v2.2.2" ✓
- If tags don't have "v": displays "ITK DB Admin 2.2.2" (different from old format)
- If git fails: displays "ITK DB Admin unknown" (no "v")
Consider either:
- Stripping the "v" prefix from git output to maintain consistent formatting with "v{}"
- Documenting the expected tag format (e.g., tags should use "v" prefix)
Example for option 1:
VERSION = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]).decode("utf-8").strip()
VERSION = VERSION.lstrip('v') # Remove 'v' prefix if present
# Then use format string: "ITK DB Admin v{}".format(VERSION)
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.
Using a bare
except Exceptionis too broad and will catch all exceptions, including system-level exceptions likeKeyboardInterruptandSystemExit. Consider catching more specific exceptions likesubprocess.CalledProcessError,FileNotFoundError, orOSErrorinstead.Example: