Skip to content

Commit

Permalink
Fix version parsing for local branches (#3190)
Browse files Browse the repository at this point in the history
* Fix version parsing for local branches

* Fix tests

* Fix tests
  • Loading branch information
svartkanin authored Feb 23, 2025
1 parent a51475e commit 8b375c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
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

0 comments on commit 8b375c9

Please sign in to comment.