diff --git a/komodo/check_unused_package.py b/komodo/check_unused_package.py index 92a287f7..579a80ed 100644 --- a/komodo/check_unused_package.py +++ b/komodo/check_unused_package.py @@ -1,8 +1,10 @@ #!/usr/bin/env python - import argparse import os import sys +from typing import Dict + +import yaml from komodo.prettier import load_yaml from komodo.yaml_file_types import ReleaseFile, RepositoryFile @@ -11,7 +13,10 @@ def check_for_unused_package( - release_file: ReleaseFile, package_status_file: str, repository: RepositoryFile + release_file: ReleaseFile, + package_status_file: str, + repository: RepositoryFile, + builtin_python_versions: Dict[str, str], ): package_status = load_yaml(package_status_file) public_and_plugin_packages = [ @@ -20,9 +25,11 @@ def check_for_unused_package( if package_status[pkg]["visibility"] in ("public", "private-plugin") ] python_version = release_file.content["python"] - # For pypi we need to change '3.8.6-builtin' -> '3.8.6' - python_version = python_version[: python_version.rindex("-")] - dependencies = PypiDependencies(release_file.content, python_version=python_version) + full_python_version = builtin_python_versions[python_version] + + dependencies = PypiDependencies( + release_file.content, python_version=full_python_version + ) for name, version in release_file.content.items(): metadata = repository.content.get(name, {}).get(version, {}) if metadata.get("source") != "pypi": @@ -69,7 +76,11 @@ def main(): ) args = parser.parse_args() - check_for_unused_package(args.release_file, args.status_file, args.repo) + with open("builtin_python_versions.yml", "r", encoding="utf-8") as f: + builtin_python_versions = yaml.safe_load(f) + check_for_unused_package( + args.release_file, args.status_file, args.repo, builtin_python_versions + ) if __name__ == "__main__": diff --git a/komodo/lint.py b/komodo/lint.py index e6feb075..c732ce6c 100755 --- a/komodo/lint.py +++ b/komodo/lint.py @@ -6,6 +6,7 @@ import warnings from collections import namedtuple +import yaml from packaging.version import parse from .pypi_dependencies import PypiDependencies @@ -101,10 +102,11 @@ def lint( } python_version = release_file.content["python"] - # For pypi we need to change '3.8.6-builtin' -> '3.8.6' - python_version = python_version[: python_version.rindex("-")] + with open("builtin_python_versions.yml", "r", encoding="utf-8") as f: + full_python_version = yaml.safe_load(f)[python_version] + dependencies = PypiDependencies( - pypi_dependencies, python_version=python_version + pypi_dependencies, python_version=full_python_version ) for name, version in release_file.content.items(): if ( diff --git a/tests/test_check_unused_package.py b/tests/test_check_unused_package.py index adc4463d..1ad26845 100644 --- a/tests/test_check_unused_package.py +++ b/tests/test_check_unused_package.py @@ -82,7 +82,7 @@ @pytest.mark.parametrize("repo, release, package_status", test_case) def test_check_unused_package(repo, release, package_status, capsys, tmpdir): package_status["python"] = {"visibility": "public"} - release["python"] = "3.8.6-builtin" + release["python"] = "3.8-builtin" # Use tmpdir to create a temporary file for package status package_status_file = tmpdir.join("package_status.yml") @@ -97,6 +97,7 @@ def test_check_unused_package(repo, release, package_status, capsys, tmpdir): release_file=release, package_status_file=str(package_status_file), repository=repo, + builtin_python_versions={"3.8-builtin": "3.8.6"}, ) assert sys_exit_info.value.code == 1 captured = capsys.readouterr()