Skip to content
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

Fix version parsing for local branches #3190

Merged
merged 3 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions archinstall/lib/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Arguments:

@dataclass
class ArchConfig:
version: str = field(default_factory=lambda: version('archinstall'))
version: str | None = None
locale_config: LocaleConfiguration | None = None
archinstall_language: Language = field(default_factory=lambda: translation_handler.get_language_by_abbr('en'))
disk_config: DiskLayoutConfiguration | None = None
Expand Down Expand Up @@ -82,7 +82,7 @@ def unsafe_json(self) -> dict[str, Any]:
return config

def safe_json(self) -> dict[str, Any]:
config = {
config: Any = {
'version': self.version,
'archinstall-language': self.archinstall_language.json(),
'hostname': self.hostname,
Expand Down Expand Up @@ -215,14 +215,20 @@ def args(self) -> Arguments:
def print_help(self) -> None:
self._parser.print_help()

def _get_version(self) -> str:
try:
return version('archinstall')
except Exception:
return 'Archinstall version not found'

def _define_arguments(self) -> ArgumentParser:
parser = ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
"-v",
"--version",
action="version",
default=False,
version="%(prog)s " + version('archinstall')
version="%(prog)s " + self._get_version()
)
parser.add_argument(
"--config",
Expand Down
4 changes: 4 additions & 0 deletions tests/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def test_config_file_parsing(
handler = ArchConfigHandler()
arch_config = handler.config

# the version is retrieved dynamically from an installed archinstall package
# as there is no version present in the test environment we'll set it manually
arch_config.version = '3.0.2'

# TODO: Use the real values from the test fixture instead of clearing out the entries
arch_config.disk_config.device_modifications = [] # type: ignore[union-attr]

Expand Down
4 changes: 4 additions & 0 deletions tests/test_configuration_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def test_user_config_roundtrip(
handler = ArchConfigHandler()
arch_config = handler.config

# the version is retrieved dynamically from an installed archinstall package
# as there is no version present in the test environment we'll set it manually
arch_config.version = '3.0.2'

config_output = ConfigurationOutput(arch_config)

test_out_dir = Path('/tmp/')
Expand Down