Skip to content

Commit

Permalink
Refactor config module with type annotations
Browse files Browse the repository at this point in the history
- Added type annotations to  and  functions
- Removed unnecessary variable assignments
  • Loading branch information
raghavpillai committed Jul 21, 2024
1 parent 6ffd018 commit e94a6b8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
CONFIG_FILE: str = os.path.join(HOME_DIR, ".gen-commit")


def read_config():
def read_config() -> dict:
if not os.path.exists(CONFIG_FILE):
print(
f"Config file not found at {CONFIG_FILE}. Please run `gencommit --init` to create a config file."
)
sys.exit(1)

config = {}
config: dict[str, str] = {}
with open(CONFIG_FILE, "r") as f:
for line in f:
key, value = line.strip().split("=", 1)
config[key] = value
return config


def read_version_from_pyproject():
def read_version_from_pyproject() -> str:
try:
with open("pyproject.toml", "rb") as f:
pyproject_data = tomli.load(f)
pyproject_data: dict[str, any] = tomli.load(f)
return pyproject_data["project"]["version"]
except (FileNotFoundError, KeyError):
return "0.0.0" # Default version if not found

0 comments on commit e94a6b8

Please sign in to comment.