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/komodo/pypi_dependencies.py b/komodo/pypi_dependencies.py index e9f22c7c..8d085a1f 100644 --- a/komodo/pypi_dependencies.py +++ b/komodo/pypi_dependencies.py @@ -114,6 +114,14 @@ def dump_cache(self): def _get_requirements( self, package_name: str, package_version: str ) -> List[Requirement]: + """ + >>> from packaging.requirements import Requirement + >>> PypiDependencies(to_install={}, python_version="3.8.11")._get_requirements( + ... "rips", + ... "2024.3.0.2" + ... ) + [, , ] + """ canonical = canonicalize_name(package_name) if canonical in self._user_specified: return self._user_specified[canonical] @@ -161,10 +169,22 @@ def _get_requirements( f"Got: {files}" ) file = files[0] - if file.endswith(".whl"): - dist = pkginfo.Wheel(os.path.join(tmpdir, file)) - else: - dist = pkginfo.SDist(os.path.join(tmpdir, file)) + if not file.endswith(".whl"): + subprocess.check_output( + [ + "pip", + "wheel", + "--use-pep517", + "--no-verify", + "--no-deps", + "--disable-pip-version-check", + "--no-python-version-warning", + file, + ], + cwd=tmpdir, + ) + file = [f for f in os.listdir(tmpdir) if f.endswith(".whl")][0] + dist = pkginfo.Wheel(os.path.join(tmpdir, file)) self.requirements[canonical][package_version] = dist.requires_dist return [Requirement(r) for r in self.requirements[canonical][package_version]] 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()