-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/dev 75 add changelog path to toml config #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
46b0bb4
6a5e8c3
a32d1a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,32 @@ | ||||||||||||||||||||
| """Module to parse file configuration values.""" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| from dataclasses import dataclass | ||||||||||||||||||||
| from dataclasses import dataclass, field | ||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||
|
|
||||||||||||||||||||
| from .base import ConfigError, get_str, get_table | ||||||||||||||||||||
| from .base import ConfigError, get_str, get_str_or_str_list, get_table | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @dataclass(frozen=True) | ||||||||||||||||||||
| class FileConfig: | ||||||||||||||||||||
| """Dataclass to hold file configuration values.""" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| encoding: str = "utf-8" | ||||||||||||||||||||
| changelog_paths: list[Path] = field(default_factory=lambda: [Path("CHANGELOG.md")]) | ||||||||||||||||||||
| _default_changelog_path: Path | None = None | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @property | ||||||||||||||||||||
| def default_changelog_path(self) -> Path: | ||||||||||||||||||||
| """Get the default changelog path. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Returns | ||||||||||||||||||||
| ------- | ||||||||||||||||||||
| Path | ||||||||||||||||||||
| The default changelog path. | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| if self._default_changelog_path is not None: | ||||||||||||||||||||
| return self._default_changelog_path | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return self.changelog_paths[0] | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def to_toml_lines(self) -> list[str]: | ||||||||||||||||||||
| """Convert the FileConfig to TOML lines. | ||||||||||||||||||||
|
|
@@ -23,6 +39,9 @@ def to_toml_lines(self) -> list[str]: | |||||||||||||||||||
| """ | ||||||||||||||||||||
| lines = ["[file]\n"] | ||||||||||||||||||||
| lines.append(f'#encoding = "{self.encoding}"\n') | ||||||||||||||||||||
| paths_str = '", "'.join(str(p) for p in self.changelog_paths) | ||||||||||||||||||||
| lines.append(f'#changelog_paths = ["{paths_str}"]\n') | ||||||||||||||||||||
| lines.append(f'#_default_changelog_path = "{self.default_changelog_path}"\n') | ||||||||||||||||||||
|
||||||||||||||||||||
| lines.append(f'#_default_changelog_path = "{self.default_changelog_path}"\n') | |
| lines.append(f'#default_changelog_path = "{self.default_changelog_path}"\n') |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use double hash ## for section comments rather than triple hash ### to maintain consistency with Python documentation conventions. Triple hash is typically reserved for major section headers in documentation.
| ### Validate encoding | |
| ## Validate encoding |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code references FileConfig.changelog_path (singular), but the actual attribute defined in the FileConfig class is changelog_paths (plural). This will cause an AttributeError at runtime. Change FileConfig.changelog_path to FileConfig.changelog_paths.
| table, "changelog_path", FileConfig.changelog_path | |
| table, "changelog_path", FileConfig.changelog_paths |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This normalization logic is redundant because get_str_or_str_list already returns either a string or list. If you want the result to always be a list, this conversion should happen, but the function name and logic suggest it can return either type. Consider returning the value directly and removing this check, or ensure the contract is clear about always returning a list from this function.
| table, "changelog_path", FileConfig.changelog_path | |
| ) | |
| if isinstance(changelog_paths, str): | |
| changelog_paths = [changelog_paths] | |
| table, | |
| "changelog_path", | |
| FileConfig.changelog_paths, | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function performs redundant lookups by calling
get_strorget_str_listafter already retrieving the value. Instead of re-querying the mapping, directly return the validated value to avoid duplicate lookups and potential inconsistencies. The current implementation also doesn't handle the case where the default is provided and used as the value - it will be passed to nested functions unnecessarily.