Skip to content

Introduce --version command#48

Open
ruicoelhopedro wants to merge 6 commits intomainfrom
version-command
Open

Introduce --version command#48
ruicoelhopedro wants to merge 6 commits intomainfrom
version-command

Conversation

@ruicoelhopedro
Copy link
Member

No description provided.

@ruicoelhopedro ruicoelhopedro requested a review from Copilot April 30, 2025 14:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

ruicoelhopedro and others added 3 commits April 30, 2025 16:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Apr 30, 2025

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.94%. Comparing base (a2b0240) to head (1e4058d).

Files with missing lines Patch % Lines
piglot/__init__.py 66.66% 3 Missing ⚠️
piglot/bin/piglot.py 50.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +10 to +30
# 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
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants