Skip to content

Commit 839e6bf

Browse files
authored
Move get_version() to version module (#4270)
1 parent 74a230d commit 839e6bf

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

archinstall/lib/args.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import urllib.parse
77
from argparse import ArgumentParser, Namespace
88
from dataclasses import dataclass, field
9-
from importlib.metadata import version
109
from pathlib import Path
1110
from typing import Any, Self
1211
from urllib.request import Request, urlopen
@@ -28,6 +27,7 @@
2827
from archinstall.lib.output import debug, error, logger, warn
2928
from archinstall.lib.plugins import load_plugin
3029
from archinstall.lib.translationhandler import Language, tr, translation_handler
30+
from archinstall.lib.version import get_version
3131

3232

3333
@p_dataclass
@@ -263,7 +263,7 @@ def __init__(self) -> None:
263263

264264
try:
265265
self._config = ArchConfig.from_config(config, args)
266-
self._config.version = self._get_version()
266+
self._config.version = get_version()
267267
except ValueError as err:
268268
warn(str(err))
269269
sys.exit(1)
@@ -288,20 +288,14 @@ def get_script(self) -> str:
288288
def print_help(self) -> None:
289289
self._parser.print_help()
290290

291-
def _get_version(self) -> str:
292-
try:
293-
return version('archinstall')
294-
except Exception:
295-
return 'Archinstall version not found'
296-
297291
def _define_arguments(self) -> ArgumentParser:
298292
parser = ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
299293
parser.add_argument(
300294
'-v',
301295
'--version',
302296
action='version',
303297
default=False,
304-
version='%(prog)s ' + self._get_version(),
298+
version='%(prog)s ' + get_version(),
305299
)
306300
parser.add_argument(
307301
'--config',

archinstall/lib/plugins.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pathlib import Path
99

1010
from archinstall.lib.output import error, info, warn
11+
from archinstall.lib.version import get_version
1112

1213
plugins = {}
1314

@@ -94,11 +95,9 @@ def load_plugin(path: Path) -> None:
9495
namespace = _import_via_path(localized)
9596

9697
if namespace and namespace in sys.modules:
97-
from archinstall.lib.args import arch_config_handler
98-
9998
# Version dependency via __archinstall__version__ variable (if present) in the plugin
10099
# Any errors in version inconsistency will be handled through normal error handling if not defined.
101-
version = arch_config_handler.config.version
100+
version = get_version()
102101

103102
if version is not None:
104103
version_major_and_minor = version.rsplit('.', 1)[0]

archinstall/lib/version.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from importlib.metadata import version
2+
3+
4+
def get_version() -> str:
5+
try:
6+
return version('archinstall')
7+
except Exception:
8+
return 'Archinstall version not found'

0 commit comments

Comments
 (0)