Skip to content

Commit

Permalink
Support none version for matrix files in insert proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Apr 3, 2024
1 parent 1b779db commit 78f7ebd
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 31 deletions.
16 changes: 10 additions & 6 deletions komodo/insert_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ def recursive_update(
package_name1: version_x
package_name2:
py38: version_y
py312: version_z
py38: version_y
py312: version_z
package_name3:
py38:
rhel7: version_x
rhel8: version_y
rhel7:
py38: version_x
rhel8:
py38: version_x
py311: version_y
Args:
to_be_upgraded (Mapping[str, Union[str, Mapping[str, str]]]):
Expand Down Expand Up @@ -125,7 +127,7 @@ def validate_upgrades(

def recursive_validate_package_entries(
package_name,
package_version_or_matrix: Union[str, Mapping],
package_version_or_matrix: Union[str, Mapping, None],
repository_file: RepositoryFile,
errors: MutableSet,
) -> None:
Expand All @@ -136,6 +138,8 @@ def recursive_validate_package_entries(
)
except KomodoException as komodo_exception:
errors.add(komodo_exception.error)
elif package_version_or_matrix is None:
return
else:
for nested_version_or_matrix in package_version_or_matrix.values():
recursive_validate_package_entries(
Expand Down
40 changes: 28 additions & 12 deletions komodo/yaml_file_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def validate_release_file(release_file_content: Mapping) -> None:
def lint_release_name(packagefile_path: str) -> List[KomodoError]:
relname = os.path.basename(packagefile_path)
found = False
for py_suffix in "-py27", "-py36", "-py38", "-py310":
for py_suffix in "-py27", "-py36", "-py38", "-py311":
for rh_suffix in "", "-rhel6", "-rhel7", "-rhel8":
if relname.endswith(py_suffix + rh_suffix + ".yml"):
found = True
Expand Down Expand Up @@ -161,7 +161,7 @@ def validate_release_matrix_file(release_matrix_file_content: Mapping) -> None:
def lint_release_name(packagefile_path: str) -> List[KomodoError]:
relname = os.path.basename(packagefile_path)
found = False
for py_suffix in "-py27", "-py36", "-py38", "-py310":
for py_suffix in "-py27", "-py36", "-py38", "-py311":
for rh_suffix in "", "-rhel6", "-rhel7", "-rhel8":
if relname.endswith(py_suffix + rh_suffix + ".yml"):
found = True
Expand Down Expand Up @@ -527,28 +527,42 @@ def validate_package_name(package_name: str) -> None:
raise TypeError(msg)

@staticmethod
def validate_package_version(package_name: str, package_version: str) -> None:
if isinstance(package_version, str):
def validate_package_version(
package_name: Union[str, None],
package_version: str,
is_matrix_file: bool = False,
) -> None:
if isinstance(package_version, str) or (
is_matrix_file and package_version is None
):
return
msg = f"Package '{package_name}' has invalid version type ({package_version})"
raise TypeError(
msg,
)
else:
msg = (
f"Package '{package_name}' has invalid version type ({package_version})"
)
raise TypeError(
msg,
)

@staticmethod
def validate_package_entry(package_name: str, package_version) -> None:
def validate_package_entry(
package_name: str, package_version, is_matrix_file=False
) -> None:
Package.validate_package_name(package_name)
Package.validate_package_version(package_name, package_version)
Package.validate_package_version(package_name, package_version, is_matrix_file)

@staticmethod
def validate_package_entry_with_errors(
package_name: str,
package_version: str,
is_matrix_file: bool = False,
) -> List[str]:
"""Validates package name and version, and returns a list of error messages."""
errors = []
try:
Package.validate_package_entry(package_name, package_version)
Package.validate_package_entry(
package_name, package_version, is_matrix_file
)
except (ValueError, TypeError) as value_or_type_error:
errors.append(str(value_or_type_error))
return errors
Expand Down Expand Up @@ -757,7 +771,9 @@ def _recursive_validate_version_matrix(
)
else:
new_errors = Package.validate_package_entry_with_errors(
package_name, version_or_matrix
package_name,
version_or_matrix,
is_matrix_file=True,
)
for new_error in new_errors:
errors.add(new_error)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ disable = [
"use-implicit-booleaness-not-comparison",
"use-symbolic-message-instead",
"useless-object-inheritance",
"too-many-lines",
]

[tool.pylint.MASTER]
Expand Down
2 changes: 1 addition & 1 deletion tests/data/cli/minimal_repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ python:
make: sh
makefile: test_python_builtin.sh
maintainer: [email protected]
makeopts: --python-version 3.10
makeopts: --python-version 3.11

treelib:
1.7.0:
Expand Down
10 changes: 5 additions & 5 deletions tests/data/test_release_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ lib1:
py27: 0.1.2+builtin
py36: 1.2.3+builtin
py38: 1.2.4+builtin
py310: 1.2.5+builtin
py311: 1.2.5+builtin
rhel8:
py38: 1.2.5+builtin
py310: 1.2.6+builtin
py311: 1.2.6+builtin
lib2:
py27: 1.2.3
py36: 2.3.4
py38: 2.3.4
py310: 2.3.6
py311: 2.3.6
lib3:
py27: 2.3.4
py36: 3.4.5
py38: 3.4.6
py310: 5.4.0
py311: 5.4.0
lib4:
py27: 3.4.5
py36:
py38:
py310: 4.0.0
py311: 4.0.0
71 changes: 67 additions & 4 deletions tests/test_insert_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,65 @@ def create_pull(self, title, body, head, base):
"testlib2": "1.1.1",
},
"upgrade_proposals.yml": {
"1111-11": {"testlib2": {"rhel7": "1.1.2", "rhel8": "1.1.1"}},
"1111-11": {
"testlib2": {
"rhel7": {"py38": "1.1.2"},
"rhel8": {"py38": "1.1.1", "py311": "1.1.2"},
},
},
},
"repository.yml": VALID_REPOSITORY_CONTENT,
},
{
"releases/matrices/1111.11.rc2.yml": {
"testlib1": "1.1.1",
"testlib2": {"rhel7": "1.1.2", "rhel8": "1.1.1"},
"testlib2": {
"rhel7": {"py38": "1.1.2"},
"rhel8": {"py38": "1.1.1", "py311": "1.1.2"},
},
},
"upgrade_proposals.yml": {"1111-11": None},
},
["Temporary PR 1111.11.rc2", "Add release 1111.11.rc2"],
type(None),
"",
id="update_from_version_to_matrix",
id="update_from_version_to_full_matrix",
),
pytest.param(
"1111.11.rc1",
"1111.11.rc2",
{
"releases/matrices/1111.11.rc1.yml": {
"testlib1": "1.1.1",
"testlib2": "1.1.1",
},
"upgrade_proposals.yml": {
"1111-11": {"testlib2": {"py38": "1.1.2", "py311": "1.1.1"}},
},
"repository.yml": VALID_REPOSITORY_CONTENT,
},
{
"releases/matrices/1111.11.rc2.yml": {
"testlib1": "1.1.1",
"testlib2": {"py38": "1.1.2", "py311": "1.1.1"},
},
"upgrade_proposals.yml": {"1111-11": None},
},
["Temporary PR 1111.11.rc2", "Add release 1111.11.rc2"],
type(None),
"",
id="update_from_version_to_py_matrix",
),
pytest.param(
"1111.11.rc1",
"1111.11.rc2",
{
"releases/matrices/1111.11.rc1.yml": {
"testlib1": "1.1.1",
"testlib2": {"rhel7": "1.1.2", "rhel8": "1.1.1"},
"testlib2": {
"rhel7": {"py38": "1.1.2"},
"rhel8": {"py38": "1.1.1", "py311": "1.1.2"},
},
},
"upgrade_proposals.yml": {
"1111-11": {"testlib2": "1.1.2"},
Expand All @@ -209,6 +245,33 @@ def create_pull(self, title, body, head, base):
"",
id="update_from_matrix_to_version",
),
pytest.param(
"1111.11.rc1",
"1111.11.rc2",
{
"releases/matrices/1111.11.rc1.yml": {
"testlib1": "1.1.1",
"testlib2": "1.1.1",
},
"upgrade_proposals.yml": {
"1111-11": {
"testlib2": {"py38": None, "py311": "1.1.2"},
},
},
"repository.yml": VALID_REPOSITORY_CONTENT,
},
{
"releases/matrices/1111.11.rc2.yml": {
"testlib1": "1.1.1",
"testlib2": {"py38": None, "py311": "1.1.2"},
},
"upgrade_proposals.yml": {"1111-11": None},
},
["Temporary PR 1111.11.rc2", "Add release 1111.11.rc2"],
type(None),
"",
id="remove_package_from_one_py_version",
),
pytest.param(
"1111.11.rc1",
"1111.12.rc2",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_release_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_build_release_matrix_py_coords(

@pytest.mark.parametrize(
"matrix",
[({"py": ["3.8"], "rhel": ["7"]}), ({"py": ["3.8", "3.10"], "rhel": ["7", "8"]})],
[({"py": ["3.8"], "rhel": ["7"]}), ({"py": ["3.8", "3.11"], "rhel": ["7", "8"]})],
)
def test_transpile_add_argument(tmpdir, matrix):
release_file = os.path.join(_get_test_root(), "data", "test_release_matrix.yml")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_yaml_file_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def test_release_file_yaml_type(content, expectations):
"bleeding-py36.yml",
"/home/anyuser/komodo/2020.01.03-py36-rhel6.yml",
"myrelease-py36.yml",
"myrelease-py310.yml",
"myrelease-py310-rhel8.yml",
"myrelease-py311.yml",
"myrelease-py311-rhel8.yml",
"myrelease-py36-rhel6.yml",
"myrelease-py36-rhel7.yml",
),
Expand Down

0 comments on commit 78f7ebd

Please sign in to comment.