Skip to content

Commit

Permalink
Group komodo_check_up_to_date_pypi upgrades
Browse files Browse the repository at this point in the history
Add grouping and formatting of pypi upgrade suggestions.
  • Loading branch information
jonathan-eq committed Oct 2, 2023
1 parent a8f53f4 commit 39ffad8
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 35 deletions.
51 changes: 40 additions & 11 deletions komodo/check_up_to_date_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def get_upgrade_proposals_from_pypi(
pypi_responses = get_pypi_info(pypi_packages)

upgrade_proposals_from_pypi = {}

for package_name, response in pypi_responses:
komodo_version = get_version.parse(strip_version(releases[package_name]))
if response.ok:
Expand Down Expand Up @@ -166,15 +167,43 @@ def run_check_up_to_date(
yaml.dump(releases, fout)
write_to_file(repository, repository_file)

errors = []
major_upgrades, minor_upgrades, patch_upgrades, other_upgrades = [], [], [], []
for name, versions in upgrade_proposals_from_pypi.items():
pypi_latest = versions["suggested"]
current_version = versions["previous"]
errors.append(
f"{name} not at latest pypi version: {pypi_latest}, "
f"is at: {current_version}",
pypi_latest = get_version.Version(versions["suggested"])
current_version = get_version.Version(versions["previous"])
if pypi_latest.major > current_version.major:
major_upgrades.append(
f"{name} not at latest pypi version: {pypi_latest}, "
f"is at: {current_version}"
)
elif pypi_latest.minor > current_version.minor:
minor_upgrades.append(
f"{name} not at latest pypi version: {pypi_latest}, "
f"is at: {current_version}"
)
elif pypi_latest.micro > current_version.micro:
patch_upgrades.append(
f"{name} not at latest pypi version: {pypi_latest}, "
f"is at: {current_version}"
)
else:
other_upgrades.append(
f"{name} not at latest pypi version: {pypi_latest}, "
f"is at: {current_version}"
)
print(
"\n".join(
["\nMajor upgrades:"]
+ (major_upgrades if major_upgrades else ["None"])
+ ["\nMinor upgrades:"]
+ (minor_upgrades if minor_upgrades else ["None"])
+ ["\nPatch upgrades:"]
+ (patch_upgrades if patch_upgrades else ["None"])
+ ["\nOther upgrades:"]
+ (other_upgrades if other_upgrades else ["None"])
+ ["\n\nFound out of date packages!"]
)
print("\n".join(errors) + "\nFound out of date packages!")
)

else:
print("All packages up to date!!!")
Expand Down Expand Up @@ -247,9 +276,9 @@ def main():
)


def validate_release_file(release_file_path: str) -> None:
ReleaseFile()(release_file_path)
def validate_release_file(file_path: str) -> None:
ReleaseFile()(file_path)


def validate_repository_file(repository_file_path: str) -> None:
RepositoryFile()(repository_file_path)
def validate_repository_file(file_path: str) -> None:
RepositoryFile()(file_path)
106 changes: 82 additions & 24 deletions tests/test_up_to_date_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,42 +450,100 @@ def test_run_up_to_date(


@pytest.mark.parametrize(
("release", "repository", "expectation"),
"release_file_content",
[
pytest.param(
"""dummy_package: 1.0.0\ncustom_package: 1.1.1""",
"""dummy_package:\n 1.0:\n make: unknown""",
pytest.raises(SystemExit, match="does not appear to be a repository file"),
id="invalid_repository",
"""
dummy_package_patch: 1.0.0
dummy_package_minor: 1.0.0
dummy_package_major: 1.0.0
""",
id="patch_minor_major",
),
pytest.param(
"""dummy_package: 1.0\ncustom_package: yes""",
"""dummy_package:\n 1.0:\n maintainer: unknown""",
pytest.raises(SystemExit, match="does not appear to be a release file"),
id="invalid_release",
"""
dummy_package_patch: 1.0.0
dummy_package_major: 1.0.0
dummy_package_minor: 1.0.0
""",
id="patch_major_minor",
),
pytest.param(
"""
dummy_package_minor: 1.0.0
dummy_package_major: 1.0.0
dummy_package_patch: 1.0.0
""",
id="minor_major_patch",
),
],
)
def test_integration_with_invalid_yaml_files(
tmpdir,
monkeypatch,
release,
repository,
expectation,
):
def test_upgrade_type_grouping(release_file_content, tmpdir, monkeypatch, capsys):
repository_file_content = """
dummy_package_patch:
1.0.0:
source: pypi
make: pip
maintainer: scout
dummy_package_minor:
1.0.0:
source: pypi
make: pip
maintainer: scout
dummy_package_major:
1.0.0:
source: pypi
make: pip
maintainer: scout
"""

with tmpdir.as_cwd():
with open("repository_file.yml", "w") as fout:
fout.write(repository_file_content)
with open("release_file.yml", "w") as fout:
fout.write(release_file_content)
folder_name = os.getcwd()

def side_effect(url: str, timeout):
if "dummy_package_patch" in url.split("/"):
request_mock = MagicMock()
request_json = {
"releases": {"1.0.1": []},
}
request_mock.json.return_value = request_json
return request_mock
elif "dummy_package_minor" in url.split("/"):
request_mock = MagicMock()
request_json = {
"releases": {"1.1.0": []},
}
request_mock.json.return_value = request_json
return request_mock
elif "dummy_package_major" in url.split("/"):
request_mock = MagicMock()
request_json = {
"releases": {"2.0.0": []},
}
request_mock.json.return_value = request_json
return request_mock
else:
raise ValueError("INCORRECT PACKAGE NAME ENTERED! " + str(url))

arguments = [
"script_name",
"release_file",
"repository_file",
f"{folder_name}/release_file.yml",
f"{folder_name}/repository_file.yml",
"--propose-upgrade",
"new_file",
]
monkeypatch.setattr(sys, "argv", arguments)
with open("repository_file", "w") as fout:
fout.write(str(repository))
with open("release_file", "w") as fout:
fout.write(str(release))
monkeypatch.setattr(requests, "get", MagicMock(side_effect=side_effect))
check_up_to_date_pypi.main()
system_print = capsys.readouterr().out

with expectation:
check_up_to_date_pypi.main()
assert (
"Major upgrades:\ndummy_package_major not at latest pypi version: 2.0.0, is at: 1.0.0\n\nMinor upgrades:\ndummy_package_minor not at latest pypi version: 1.1.0, is at: 1.0.0\n\nPatch upgrades:\ndummy_package_patch not at latest pypi version: 1.0.1, is at: 1.0.0"
in system_print
)

0 comments on commit 39ffad8

Please sign in to comment.