From 8b375c97a5e24128153e4c9bb0586a87b7fd267c Mon Sep 17 00:00:00 2001 From: Daniel Girtler Date: Sun, 23 Feb 2025 19:44:25 +1100 Subject: [PATCH] Fix version parsing for local branches (#3190) * Fix version parsing for local branches * Fix tests * Fix tests --- archinstall/lib/args.py | 12 +++++++++--- tests/test_args.py | 4 ++++ tests/test_configuration_output.py | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/archinstall/lib/args.py b/archinstall/lib/args.py index 1c53e2ea46..559b535ddf 100644 --- a/archinstall/lib/args.py +++ b/archinstall/lib/args.py @@ -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 @@ -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, @@ -215,6 +215,12 @@ 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( @@ -222,7 +228,7 @@ def _define_arguments(self) -> ArgumentParser: "--version", action="version", default=False, - version="%(prog)s " + version('archinstall') + version="%(prog)s " + self._get_version() ) parser.add_argument( "--config", diff --git a/tests/test_args.py b/tests/test_args.py index 6c81a89773..8fbf4bba32 100644 --- a/tests/test_args.py +++ b/tests/test_args.py @@ -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] diff --git a/tests/test_configuration_output.py b/tests/test_configuration_output.py index efa6ccc18e..7733410e26 100644 --- a/tests/test_configuration_output.py +++ b/tests/test_configuration_output.py @@ -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/')