Skip to content

Commit cbafe4d

Browse files
committed
Refactor & fix get_tracked_release
1 parent 254cd6b commit cbafe4d

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/komodoenv/__main__.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def distro_suffix():
5454
return f"-rhel{distro.major_version()}"
5555

5656

57-
def resolve_release( # noqa: C901
57+
def resolve_release(
5858
*,
5959
root: Path,
6060
name: str,
@@ -95,18 +95,15 @@ def resolve_release( # noqa: C901
9595
distribution_suffix = distro_suffix()
9696

9797
for mode in "stable", "testing", "bleeding":
98-
for rhver in "", distribution_suffix:
99-
track = root / (mode + pyver)
100-
dir_ = (root / (mode + pyver + rhver)).resolve()
101-
102-
if not (dir_ / "root").is_dir():
103-
dir_ = (root / (mode + pyver)).resolve()
104-
dir_ = get_tracked_release(dir_, distribution_suffix)
105-
106-
if (dir_ / "root").is_dir():
107-
symlink = dir_.resolve()
108-
if symlink.name == actual_path.name:
109-
return symlink, track
98+
track = root / (mode + pyver)
99+
dir_ = get_tracked_release(
100+
(root / (mode + pyver)).resolve(), distribution_suffix
101+
)
102+
103+
if (dir_ / "root").is_dir():
104+
symlink = dir_.resolve()
105+
if symlink.name == actual_path.name:
106+
return symlink, track
110107

111108
sys.exit(
112109
"Could not automatically detect an appropriate Komodo release to track (one of: stable, testing, bleeding).\n"

src/komodoenv/update.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,22 +321,31 @@ def write_config(config: Dict[str, str]):
321321
def get_tracked_release(
322322
tracked_release: Path, rhel_suffix: Optional[str] = None
323323
) -> Path:
324-
abs_path = Path(tracked_release).resolve()
325-
326-
if (abs_path / "root").is_dir():
327-
return abs_path
328-
329-
custom_coordinate = find_custom_coordinate(tracked_release)
330-
331324
if not rhel_suffix:
332325
rhel_suffix = rhel_version_suffix()
333326

334-
tracked_release = Path(str(tracked_release) + rhel_suffix).resolve()
335-
336-
if (tracked_release / "root").is_dir():
337-
return tracked_release
338-
339-
return Path(str(tracked_release) + custom_coordinate).resolve()
327+
custom_coordinate = find_custom_coordinate(tracked_release)
328+
detected_python_version = ""
329+
parts = Path(tracked_release).name.split("-")
330+
abs_path = Path(tracked_release).parent
331+
base_release = f"{abs_path}/{parts[0]}"
332+
for p in parts:
333+
if re.match(r"^(?:\d{8}|\d{4})$", p):
334+
base_release += f"-{p}"
335+
elif p.startswith("py"):
336+
detected_python_version = f"-{p}"
337+
338+
for rp in [
339+
f"{base_release}{detected_python_version}{rhel_suffix}{custom_coordinate}",
340+
f"{base_release}{detected_python_version}{rhel_suffix}",
341+
f"{base_release}{detected_python_version}{custom_coordinate}",
342+
f"{base_release}{detected_python_version}",
343+
]:
344+
possible_root_release = Path(rp).resolve()
345+
if (possible_root_release / "root").is_dir():
346+
return possible_root_release
347+
348+
return Path()
340349

341350

342351
def find_custom_coordinate(release_path: Path) -> str:

0 commit comments

Comments
 (0)