Skip to content

Commit d42beb6

Browse files
committed
refactor: streamline version retrieval in __init__.py
- Removed unnecessary tomllib and pathlib imports. - Simplified version retrieval using importlib.metadata. - Updated pyproject.toml to include additional file patterns for ruff.
1 parent ef84e8c commit d42beb6

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

autotarcompress/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
This package provides a complete backup solution with encryption capabilities.
44
"""
55

6-
import tomllib
7-
from pathlib import Path
8-
9-
try:
10-
pyproject_path = Path(__file__).parent.parent / "pyproject.toml"
11-
with pyproject_path.open("rb") as f:
12-
data = tomllib.load(f)
13-
__version__ = data.get("project", {}).get("version", "unknown")
14-
except (OSError, ValueError):
15-
__version__ = "unknown"
6+
from importlib.metadata import PackageNotFoundError, version
167

178
# Expose managers for direct imports
189
from autotarcompress.backup_manager import BackupManager
1910
from autotarcompress.cleanup_manager import CleanupManager
2011
from autotarcompress.extract_manager import ExtractManager
2112
from autotarcompress.info_manager import InfoManager
2213

14+
try:
15+
# "autotarcompress" should match the 'name' field in your pyproject.toml
16+
__version__ = version("autotarcompress")
17+
except PackageNotFoundError:
18+
# This happens if the package isn't installed (e.g., running raw scripts)
19+
__version__ = "dev"
20+
21+
2322
__all__ = ["BackupManager", "CleanupManager", "ExtractManager", "InfoManager"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ markers = [
5151
[tool.ruff]
5252
line-length = 79
5353
indent-width = 4
54-
include = ["pyproject.toml"]
54+
include = ["pyproject.toml", "src/**/*.py", "scripts/**/*.py"]
5555

5656
[tool.ruff.format]
5757
# Like Black, use double quotes for strings.

0 commit comments

Comments
 (0)