Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements a new version-detection mechanism based on Git tags and adds tests for the newly introduced --version command.
- Introduces code in init.py to update version from a Git tag if the tag matches the expected format.
- Adds a workflow job in .github/workflows/test.yaml to verify the version output for both the piglot and piglot-plot commands.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| piglot/init.py | Adds Git-based version update logic to dynamically set version. |
| .github/workflows/test.yaml | Adds a test step to run version commands for piglot and piglot-plot. |
Comments suppressed due to low confidence (1)
.github/workflows/test.yaml:44
- [nitpick] Verify that 'piglot-plot' is the intended command. If it’s a typo or unintentional divergence from the 'piglot' command, update it for consistency.
piglot-plot --version
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #48 +/- ##
==========================================
- Coverage 95.05% 94.94% -0.11%
==========================================
Files 35 35
Lines 3071 3084 +13
==========================================
+ Hits 2919 2928 +9
- Misses 152 156 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| # Try to find the piglot version from the git tag | ||
| import os | ||
| import subprocess | ||
| try: | ||
| result = subprocess.run( | ||
| ['git', 'describe', '--tags'], | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| cwd=os.path.dirname(__file__), | ||
| text=True, | ||
| check=True | ||
| ) | ||
| __new_version__ = result.stdout.strip() | ||
|
|
||
| # The Git tag format is expected to start with 'v' followed by the version number | ||
| # (e.g., 'v0.5.1'). This ensures that the tag corresponds to the current version defined | ||
| # in __version__. | ||
| if __new_version__.startswith(f'v{__version__}'): | ||
| __version__ = __new_version__[1:] | ||
| except (FileNotFoundError, subprocess.CalledProcessError): | ||
| pass |
There was a problem hiding this comment.
This subprocess call runs on every import, which can slow down module loading. Consider caching the result or moving this logic to run only when the version is explicitly requested.
| # Try to find the piglot version from the git tag | |
| import os | |
| import subprocess | |
| try: | |
| result = subprocess.run( | |
| ['git', 'describe', '--tags'], | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| cwd=os.path.dirname(__file__), | |
| text=True, | |
| check=True | |
| ) | |
| __new_version__ = result.stdout.strip() | |
| # The Git tag format is expected to start with 'v' followed by the version number | |
| # (e.g., 'v0.5.1'). This ensures that the tag corresponds to the current version defined | |
| # in __version__. | |
| if __new_version__.startswith(f'v{__version__}'): | |
| __version__ = __new_version__[1:] | |
| except (FileNotFoundError, subprocess.CalledProcessError): | |
| pass | |
| import os | |
| import subprocess | |
| _cached_git_version = None | |
| def get_version(): | |
| """ | |
| Returns the piglot version. If a git tag is available, returns the tag version. | |
| Otherwise, returns the static __version__. | |
| Caches the result after the first call. | |
| """ | |
| global _cached_git_version | |
| if _cached_git_version is not None: | |
| return _cached_git_version | |
| try: | |
| result = subprocess.run( | |
| ['git', 'describe', '--tags'], | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| cwd=os.path.dirname(__file__), | |
| text=True, | |
| check=True | |
| ) | |
| new_version = result.stdout.strip() | |
| # The Git tag format is expected to start with 'v' followed by the version number | |
| if new_version.startswith(f'v{__version__}'): | |
| _cached_git_version = new_version[1:] | |
| else: | |
| _cached_git_version = __version__ | |
| except (FileNotFoundError, subprocess.CalledProcessError): | |
| _cached_git_version = __version__ | |
| return _cached_git_version |
No description provided.