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

Allow third coordinate in release name #96

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions src/komodoenv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from komodoenv.colors import blue, strip_color, yellow
from komodoenv.creator import Creator
from komodoenv.statfs import is_nfs
from komodoenv.update import get_tracked_release


def get_release_maturity_text(release_path):
Expand Down Expand Up @@ -91,23 +92,31 @@ def resolve_release( # noqa: C901
sys.exit(f"An error occurred while detecting the version of Python of '{root}'")
major, minor = match.groups()
pyver = "-py" + major + minor
path_name = name

base_name = re.match("^(.*?)(?:-py[0-9]+)?(?:-rhel[0-9]+)?$", name)
# skip last coordinate to allow custom coordinates
if "-" in path_name:
parts = name.split("-")
path_name = "-".join(parts[0:-1])

base_name = re.match("^(.*?)(?:-py[0-9]+)?(?:-rhel[0-9]+)?$", path_name)
if base_name is None:
msg = "Could not find the release."
raise ValueError(msg)
name = base_name[1] + pyver

print(f"Looking for {name}")

distribution_suffix = distro_suffix()
for mode in "stable", "testing", "bleeding":
for rhver in "", distro_suffix():
for rhver in "", distribution_suffix:
dir_ = root / (mode + pyver + rhver)
track = root / (mode + pyver)

if not (dir_ / "root").is_dir():
# stable-rhel7 isn't a thing. Try resolving and appending 'rhver'
dir_ = (root / (mode + pyver)).resolve()
dir_ = dir_.parent / (dir_.name + distro_suffix())
dir_ = get_tracked_release(dir_, distribution_suffix)

if not (dir_ / "root").is_dir():
continue
symlink = dir_.resolve()
Expand Down
48 changes: 38 additions & 10 deletions src/komodoenv/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ def can_update(config: Dict[str, str]) -> bool:
layout is identical, and can be safely updated with this script.
"""
track_path = (Path(config["komodo-root"]) / config["tracked-release"]).resolve()
if not (track_path / "root").is_dir():
track_path = Path(str(track_path) + rhel_version_suffix()).resolve()
track_path = get_tracked_release(track_path)
version = get_pkg_version(config, track_path / "root")
if "komodoenv-version" not in config or version is None:
return False
Expand All @@ -319,18 +318,47 @@ def write_config(config: Dict[str, str]):
f.write(f"{key} = {val}\n")


def get_tracked_release(
tracked_release: Path, rhel_suffix: Optional[str] = None
) -> Path:
if (tracked_release / "root").is_dir():
return tracked_release

custom_coordinate = find_custom_coordinate(tracked_release)

if not rhel_suffix:
rhel_suffix = rhel_version_suffix()

tracked_release = Path(str(tracked_release) + rhel_suffix).resolve()

if (tracked_release / "root").is_dir():
return tracked_release

return Path(str(tracked_release) + custom_coordinate).resolve()


def find_custom_coordinate(release_path: Path) -> str:
if (release_path / "enable").is_file():
with open(release_path / "enable", "r") as file:
for line in file:
if "CUSTOM_COORDINATE=" in line:
custom_coordinate_value = (
line.strip().split("CUSTOM_COORDINATE=")[1].strip('"')
)
return "-" + custom_coordinate_value
return ""


def current_track(config: Dict[str, str]) -> Dict[str, str]:
path = Path(config["komodo-root"]) / config["tracked-release"]

tracked_release = path.resolve()
tracked_release = get_tracked_release(path.resolve())
if not (tracked_release / "root").is_dir():
tracked_release = Path(str(tracked_release) + rhel_version_suffix()).resolve()
if not (tracked_release / "root").is_dir():
print(
f"Not able to find the tracked komodo release {config['tracked-release']}. Will not update.",
file=sys.stderr,
)
sys.exit(0)
print(
f"Not able to find the tracked komodo release {config['tracked-release']}. Will not update.",
file=sys.stderr,
)
sys.exit(0)
st = path.stat()

return {
Expand Down
26 changes: 20 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ def komodo_root(tmp_path_factory, python311_path):
_install(python311_path, path / "2030.02.00-py311")
_install(python311_path, path / "2030.03.00-py311-rhel9")
_install(python311_path, path / f"bleeding-py311-rhel{rhel_version()}")
_install(python311_path, path / f"2025.04.01-py311-rhel{rhel_version()}-numpy1")

for chain in (
("2030.01", "2030.01-py3", "2030.01-py311", "2030.01.00-py311"),
("2030.02", "2030.02-py3", "2030.02-py311", "2030.02.00-py311"),
("2030.03", "2030.03-py3", "2030.03-py311", "2030.03.00-py311"),
("2025.04", "2025.04-py3", "2025.04-py311", "2025.04.01-py311"),
# Stable points to py311, unspecified-rhel
("stable", "stable-py3", "stable-py311", "2030.01-py311"),
# Testing points to py311, rhel8
("testing", "testing-py3", "testing-py311", "2030.02-py311"),
# Testing points to py311, rhel8, numpy1
("testing", "testing-py3", "testing-py311", "2025.04-py311"),
# Bleeding points to py311, rhel8
("bleeding", "bleeding-py3", "bleeding-py311"),
):
Expand Down Expand Up @@ -76,13 +78,25 @@ def _install(python: str, path: Path, packages=None):
f"setenv KOMODO_RELEASE {path.name}\nsetenv PATH {path}/root/bin:$PATH\n",
)

# Create a redirect script if path ends in '-rhelX'
match = re.match("^(.+)-rhel[0-9]+$", path.name)
# Create a redirect script if path contains '-rhelX'
match = re.match("^(.+)-rhel[0-9]", path.name)

optional_custom_coordinate = path.name.split("-")[-1]
custom_coordinate = ""
if optional_custom_coordinate and not any(
optional_custom_coordinate.startswith(substring) for substring in ["py", "rhel"]
):
custom_coordinate = optional_custom_coordinate

if match is not None:
p = path.parent / match[1]
p.mkdir()
(p / "enable").write_text(f"source {path}/enable")
(p / "enable.csh").write_text(f"source {path}/enable.csh")
(p / "enable").write_text(
f'CUSTOM_COORDINATE="{custom_coordinate}"\nsource {path}/enable'
)
(p / "enable.csh").write_text(
f'set CUSTOM_COORDINATE="{custom_coordinate}"\nsource {path}/enable.csh'
)

# Install additional packages
if packages:
Expand Down
12 changes: 11 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ def generate_test_params_simple(rhel_version):
(f"bleeding-py311-rhel{rhel_version}", "bleeding-py311", "bleeding"),
(f"bleeding-py311-rhel{rhel_version}", "bleeding-py311", "bleeding-py3"),
(f"bleeding-py311-rhel{rhel_version}", "bleeding-py311", "bleeding-py311"),
(f"2025.04.01-py311-rhel{rhel_version}-numpy1", "testing-py311", "testing"),
(
f"2025.04.01-py311-rhel{rhel_version}-numpy1",
"testing-py311",
"testing-py311",
),
]


@pytest.mark.parametrize(
"expect, track_name,name",
"expect, track_name, name",
generate_test_params_simple(rhel_version()),
)
def test_resolve_simple(komodo_root, track_name, name, expect):
Expand Down Expand Up @@ -65,6 +71,10 @@ def generate_test_params_no_update(rhel_version):
(f"bleeding-py311-rhel{rhel_version}", "bleeding"),
(f"bleeding-py311-rhel{rhel_version}", "bleeding-py3"),
(f"bleeding-py311-rhel{rhel_version}", "bleeding-py311"),
(f"2025.04.01-py311-rhel{rhel_version}-numpy1", "2025.04"),
(f"2025.04.01-py311-rhel{rhel_version}-numpy1", "2025.04-py3"),
(f"2025.04.01-py311-rhel{rhel_version}-numpy1", "2025.04-py311"),
(f"2025.04.01-py311-rhel{rhel_version}-numpy1", "2025.04.01-py311"),
]


Expand Down