Skip to content

Conversation

@LittleCoinCoin
Copy link
Member

Summary

Implements hatch --version command to display the Hatch application version following modern Python best practices.

Changes

This PR includes 4 focused commits:

  1. test: Add comprehensive test suite (5 tests, 100% pass rate)
  2. refactor: Remove outdated __version__ from hatch/__init__.py
  3. feat: Add --version flag to CLI argument parser
  4. docs: Update documentation with version flag and installation verification

Implementation Details

  • Version Retrieval: Uses importlib.metadata.version('hatch') for dynamic version retrieval from pyproject.toml
  • Error Handling: Gracefully falls back to "unknown (development mode)" if package not installed
  • Output Format: Standard format hatch <version> (e.g., hatch 0.6.1)
  • No Conflicts: No -v short form to avoid conflict with existing package version flag

Test Results

5/5 tests passing (100% pass rate)

  • test_get_hatch_version_retrieves_from_metadata - Unit test for version retrieval
  • test_get_hatch_version_handles_package_not_found - Unit test for error handling
  • test_version_command_displays_correct_format - Integration test for CLI flow
  • test_import_hatch_without_version_attribute - Integration test for import safety
  • test_no_conflict_with_package_version_flag - Regression test for flag conflicts

Documentation Updates

  • ✅ CLI Reference: Added --version to global options table
  • ✅ Getting Started: Updated installation verification to use hatch --version
  • ✅ Installation Tutorial: Added version check to verification steps
  • ✅ README: Added version check after installation instructions

Breaking Changes

⚠️ Removal of __version__ attribute: Code that relied on hatch.__version__ will need to use importlib.metadata.version('hatch') instead.

This establishes pyproject.toml as the single source of truth for version information.

Implementation Reports

Detailed implementation documentation available in Laghari/Augment/Cracking_Shells/Hatch/version_command/:

  • Implementation Summary: Complete implementation report with code changes and validation
  • Knowledge Transfer Report: Lessons learned, what went wrong/right, and reusable patterns
  • Test Execution Results: Detailed test execution log with debugging process

Verification

# Test version command
$ hatch --version
hatch 0.6.1

# Verify help includes version flag
$ hatch --help | grep version
  --version             show program's version number and exit

# Verify no conflict with package version flag
$ hatch package add test-package -v 1.0.0
Successfully added package: test-package

Related Issues

N/A - New feature implementation


Ready for review - All phases complete (Analysis, Test Definition, Implementation, Debugging, Git Commits, Documentation, Knowledge Transfer)


Pull Request opened by Augment Code with guidance from the PR author

LittleCoinCoin added 4 commits October 2, 2025 19:18
Add comprehensive test suite for hatch --version command implementation:
- test_get_hatch_version_retrieves_from_metadata: Unit test for version retrieval
- test_get_hatch_version_handles_package_not_found: Unit test for error handling
- test_version_command_displays_correct_format: Integration test for CLI flow
- test_import_hatch_without_version_attribute: Integration test for import safety
- test_no_conflict_with_package_version_flag: Regression test for flag conflicts

Tests follow CrackingShells testing standards using wobble framework.
All 5 tests pass with 100% pass rate.

Related to: Phase 2 test definition (test_definition_v1.md)
Remove hardcoded version string (__version__ = '0.4.0') from hatch/__init__.py.

This eliminates version duplication and establishes pyproject.toml as the single
source of truth for version information. Version will now be retrieved dynamically
via importlib.metadata.version('hatch').

Breaking change: Code that relied on hatch.__version__ will need to use
importlib.metadata.version('hatch') instead.

Related to: Phase 1 analysis (version_command_analysis_v1.md)
Implement hatch --version command to display application version:

- Add importlib.metadata imports (version, PackageNotFoundError)
- Add get_hatch_version() helper function with error handling
- Add --version argument to main parser using argparse action='version'

The version is retrieved dynamically from package metadata via
importlib.metadata.version('hatch'). Falls back to 'unknown (development mode)'
if package is not installed.

Output format: 'hatch <version>' (e.g., 'hatch 0.6.1')

No short form (-v) to avoid conflict with existing package version flag
in subcommands.

Related to: Phase 1 analysis (version_command_analysis_v1.md)
Update documentation to include the new --version flag:

- CLI Reference: Add --version to global options table with usage example
- Getting Started: Update Step 3 verification to use 'hatch --version' first
- Installation Tutorial: Add version check to installation verification steps
- README: Add version check after installation instructions

The --version flag provides a quick way to verify successful installation
and check the installed Hatch version.

Related to: feature/hatch-version-command
@LittleCoinCoin LittleCoinCoin merged commit 1664bea into CrackingShells:dev Oct 2, 2025
1 check passed
@LittleCoinCoin LittleCoinCoin deleted the feature/hatch-version-command branch October 29, 2025 00:10
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.

1 participant