From 81dd696ef47b86111bd172639395b4be528f59db Mon Sep 17 00:00:00 2001 From: Zohar Malamant Date: Wed, 10 Jan 2024 13:44:31 +0100 Subject: [PATCH] Make komodo RHEL agnostic --- docs/komodo.rst | 8 ---- komodo/cli.py | 1 - komodo/data/activator_switch.csh.tmpl | 12 ------ komodo/data/activator_switch.tmpl | 10 ----- komodo/matrix.py | 17 ++++---- komodo/release_transpiler.py | 6 +-- komodo/show_version.py | 2 +- komodo/switch.py | 56 -------------------------- komodo/yaml_file_types.py | 7 ++-- tests/test_switch.py | 58 --------------------------- tests/test_yaml_file_types.py | 5 +-- 11 files changed, 14 insertions(+), 168 deletions(-) delete mode 100644 komodo/data/activator_switch.csh.tmpl delete mode 100644 komodo/data/activator_switch.tmpl delete mode 100644 komodo/switch.py delete mode 100644 tests/test_switch.py diff --git a/docs/komodo.rst b/docs/komodo.rst index 56100eabb..5f31509a3 100644 --- a/docs/komodo.rst +++ b/docs/komodo.rst @@ -205,14 +205,6 @@ komodo.snyk\_reporting module :undoc-members: :show-inheritance: -komodo.switch module --------------------- - -.. automodule:: komodo.switch - :members: - :undoc-members: - :show-inheritance: - komodo.yaml\_file\_type module ------------------------------ diff --git a/komodo/cli.py b/komodo/cli.py index a427c6a02..4fa3e50ff 100755 --- a/komodo/cli.py +++ b/komodo/cli.py @@ -11,7 +11,6 @@ import jinja2 from ruamel.yaml import YAML -from komodo import switch from komodo.build import make from komodo.data import Data from komodo.fetch import fetch diff --git a/komodo/data/activator_switch.csh.tmpl b/komodo/data/activator_switch.csh.tmpl deleted file mode 100644 index 643b291a4..000000000 --- a/komodo/data/activator_switch.csh.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -if ( `uname -r` =~ *el7* ) then - setenv KOMODO_ROOT {{ prefix }} - set KOMODO_RELEASE_REAL = "{{ release }}" - - source $KOMODO_ROOT/$KOMODO_RELEASE_REAL-rhel7/enable.csh - if ( $?_KOMODO_OLD_PROMPT ) then - set prompt = "[$KOMODO_RELEASE_REAL] $_KOMODO_OLD_PROMPT" - endif - setenv KOMODO_RELEASE $KOMODO_RELEASE_REAL -else - echo -e "{{ migration_warning }}" -endif diff --git a/komodo/data/activator_switch.tmpl b/komodo/data/activator_switch.tmpl deleted file mode 100644 index a287d61d1..000000000 --- a/komodo/data/activator_switch.tmpl +++ /dev/null @@ -1,10 +0,0 @@ -if [[ $(uname -r) == *el7* ]] ; then - export KOMODO_ROOT={{ prefix }} - KOMODO_RELEASE_REAL={{ release }} - - source $KOMODO_ROOT/$KOMODO_RELEASE_REAL-rhel7/enable - export PS1="(${KOMODO_RELEASE_REAL}) ${_PRE_KOMODO_PS1}" - export KOMODO_RELEASE=$KOMODO_RELEASE_REAL -else - echo -e "{{ migration_warning }}" -fi diff --git a/komodo/matrix.py b/komodo/matrix.py index 0ed1977f9..f30798323 100644 --- a/komodo/matrix.py +++ b/komodo/matrix.py @@ -3,28 +3,25 @@ handling an arbitrary large and funky matrix, without having to guess and/or repeat itself. """ -import itertools import re -from typing import Iterator, Sequence, Tuple +from typing import Iterable, Sequence def get_matrix( - rhel_versions: Sequence[str], py_versions: Sequence[str], -) -> Iterator[Tuple[str, str]]: +) -> Iterable[str]: """Return tuples of rhel version and Python version, representing the current release matrix. """ - for product in itertools.product(rhel_versions, py_versions): - rh_ver, py_ver = product - yield (f"rhel{rh_ver}", f"py{str(py_ver).replace('.', '')}") + for py_ver in py_versions: + yield f"py{str(py_ver).replace('.', '')}" -def format_release(base: str, rhel_ver: str, py_ver: str) -> str: +def format_release(base: str, py_ver: str) -> str: """Format a base (e.g. a matrix file without the .yml suffix) such that it looks like a concrete release. """ - return f"{base}-{py_ver}-{rhel_ver}" + return f"{base}-{py_ver}" def get_matrix_base(release_name: str) -> str: @@ -32,7 +29,7 @@ def get_matrix_base(release_name: str) -> str: inverse of format_release for actual, concrete matrix releases. Hard-coded the suffix pattern '-py..-rhel.' or '-py...-rhel.'. """ - suffix = format_release("", "rhel[0-9]", r"py\d{2,3}") + suffix = format_release("", r"py\d{2,3}") if re.search(suffix, release_name): return re.split(suffix, release_name)[0] # no matrix suffix at all diff --git a/komodo/release_transpiler.py b/komodo/release_transpiler.py index 1c2addb84..adc00eac9 100755 --- a/komodo/release_transpiler.py +++ b/komodo/release_transpiler.py @@ -145,19 +145,17 @@ def transpile_releases(matrix_file: str, output_folder: str, matrix: dict) -> No Write one dimension file for each element in the matrix (e.g. rhel7 and py3.8, rhel6 and py3.6). """ - rhel_versions = matrix["rhel"] python_versions = matrix["py"] release_base = os.path.splitext(os.path.basename(matrix_file))[0] release_folder = os.path.dirname(matrix_file) release_matrix = load_yaml(f"{os.path.join(release_folder, release_base)}.yml") - for rhel_ver, py_ver in get_matrix(rhel_versions, python_versions): + for py_ver in get_matrix(python_versions): release_dict = _pick_package_versions_for_release( release_matrix, - rhel_ver, py_ver, ) - filename = f"{format_release(release_base, rhel_ver, py_ver)}.yml" + filename = f"{format_release(release_base, py_ver)}.yml" write_to_file(release_dict, os.path.join(output_folder, filename)) diff --git a/komodo/show_version.py b/komodo/show_version.py index bcb8601e1..fc647d94c 100644 --- a/komodo/show_version.py +++ b/komodo/show_version.py @@ -84,7 +84,7 @@ def get_komodo_path(release: str) -> Path: """Use the release name to find the 'real' release path in an ordinary komodo environment. E.g., the release may be something like '2023.01.02-py38' but the 'real' release (where the release manifest - is stored) might be platform-specific, e.g. '2023.01.02-py38-rhel7'. + is stored) might be platform-specific, e.g. '2023.01.02-py38'. The real path is in the PATH, so we try to get it from there. Args: diff --git a/komodo/switch.py b/komodo/switch.py deleted file mode 100644 index cdf937f9d..000000000 --- a/komodo/switch.py +++ /dev/null @@ -1,56 +0,0 @@ -import os -import shutil - -from jinja2 import Template - -MIGRATION_WARNING = ( - "Attention! Your machine is running on an environment " - "that is not supported. RHEL6 has been phased out.\n" - "From October 2020, komodo versions only support RHEL7.\n" - "Please migrate as soon as possible. If you have any questions or issues - " - "contact us on #ert-users on Slack or Equinor's Yammer." -) - - -def create_activator_switch(data, prefix, release): - """Given a prefix and a release, create an activator switch which - will vary the selected activator based on the RHEL version. The data - argument is expected to be a komodo.data.Data instance. - """ - # drop "-rheln" - try: - release_py, _ = release.rsplit("-", 1) - except ValueError: - # likely a build that does not require an activator switch - return - - release_path = os.path.join(prefix, release_py) - if os.path.exists(release_path): - if os.path.islink(release_path): - os.unlink(release_path) - else: - shutil.rmtree(release_path) - - os.makedirs(release_path) - - with open(os.path.join(release_path, "enable"), "w") as activator, open( - data.get("activator_switch.tmpl"), - ) as activator_tmpl: - activator.write( - Template(activator_tmpl.read(), keep_trailing_newline=True).render( - prefix=prefix, - release=release_py, - migration_warning=MIGRATION_WARNING, - ), - ) - - with open(os.path.join(release_path, "enable.csh"), "w") as activator, open( - data.get("activator_switch.csh.tmpl"), - ) as activator_tmpl: - activator.write( - Template(activator_tmpl.read(), keep_trailing_newline=True).render( - prefix=prefix, - release=release_py, - migration_warning=MIGRATION_WARNING, - ), - ) diff --git a/komodo/yaml_file_types.py b/komodo/yaml_file_types.py index 06de5d764..054353e2d 100644 --- a/komodo/yaml_file_types.py +++ b/komodo/yaml_file_types.py @@ -112,10 +112,9 @@ def lint_release_name(packagefile_path: str) -> List[komodo_error]: relname = os.path.basename(packagefile_path) found = False for py_suffix in "-py27", "-py36", "-py38", "-py310": - for rh_suffix in "", "-rhel6", "-rhel7", "-rhel8": - if relname.endswith(py_suffix + rh_suffix + ".yml"): - found = True - break + if relname.endswith(f"{py_suffix}.yml"): + found = True + break if not found: return [ _komodo_error( diff --git a/tests/test_switch.py b/tests/test_switch.py deleted file mode 100644 index 71d783938..000000000 --- a/tests/test_switch.py +++ /dev/null @@ -1,58 +0,0 @@ -import pytest - -from komodo import switch -from komodo.data import Data -from komodo.switch import MIGRATION_WARNING - - -def test_write_activator_switches(tmpdir): - prefix = tmpdir / "prefix" - release = "2020.01.01-py27-rhel6" - expected_release = "2020.01.01-py27" - switch.create_activator_switch(Data(), prefix, release) - - actual_bash_activator = prefix / f"{expected_release}/enable" - assert ( - actual_bash_activator.read_text(encoding="utf-8").strip() - == f""" -if [[ $(uname -r) == *el7* ]] ; then - export KOMODO_ROOT={prefix} - KOMODO_RELEASE_REAL={expected_release} - - source $KOMODO_ROOT/$KOMODO_RELEASE_REAL-rhel7/enable - export PS1="(${{KOMODO_RELEASE_REAL}}) ${{_PRE_KOMODO_PS1}}" - export KOMODO_RELEASE=$KOMODO_RELEASE_REAL -else - echo -e "{MIGRATION_WARNING}" -fi -""".strip() - ) - - actual_csh_activator = prefix / f"{expected_release}/enable.csh" - assert ( - actual_csh_activator.read_text(encoding="utf-8").strip() - == f""" -if ( `uname -r` =~ *el7* ) then - setenv KOMODO_ROOT {prefix} - set KOMODO_RELEASE_REAL = "{expected_release}" - - source $KOMODO_ROOT/$KOMODO_RELEASE_REAL-rhel7/enable.csh - if ( $?_KOMODO_OLD_PROMPT ) then - set prompt = "[$KOMODO_RELEASE_REAL] $_KOMODO_OLD_PROMPT" - endif - setenv KOMODO_RELEASE $KOMODO_RELEASE_REAL -else - echo -e "{MIGRATION_WARNING}" -endif -""".strip() - ) - - -def test_write_activator_switches_for_non_matrix_build(tmpdir): - prefix = tmpdir / "prefix" - release = "foobar" - - try: - switch.create_activator_switch(Data(), prefix, release) - except ValueError as e: - pytest.fail("Unexpected ValueError " + e) diff --git a/tests/test_yaml_file_types.py b/tests/test_yaml_file_types.py index ba6cee9f7..26c9a3bde 100644 --- a/tests/test_yaml_file_types.py +++ b/tests/test_yaml_file_types.py @@ -71,12 +71,9 @@ def test_release_file_yaml_type(content, expectations): "valid", ( "bleeding-py36.yml", - "/home/anyuser/komodo/2020.01.03-py36-rhel6.yml", + "/home/anyuser/komodo/2020.01.03-py36.yml", "myrelease-py36.yml", "myrelease-py310.yml", - "myrelease-py310-rhel8.yml", - "myrelease-py36-rhel6.yml", - "myrelease-py36-rhel7.yml", ), ) def test_release_name_valid(valid):