diff --git a/komodo/check_unused_package.py b/komodo/check_unused_package.py index a92020a5..e01c3476 100644 --- a/komodo/check_unused_package.py +++ b/komodo/check_unused_package.py @@ -28,7 +28,7 @@ def check_for_unused_package( full_python_version = builtin_python_versions[python_version] dependencies = PypiDependencies( - release_file.content, python_version=full_python_version + release_file.content, release_file.content, python_version=full_python_version ) for name, version in release_file.content.items(): metadata = repository.content.get(name, {}).get(version, {}) diff --git a/komodo/lint.py b/komodo/lint.py index 28719b5a..920d2830 100755 --- a/komodo/lint.py +++ b/komodo/lint.py @@ -93,9 +93,10 @@ def lint( maintainers.append(komodo_exception.error) if check_dependencies: + all_dependencies = dict(release_file.content.items()) pypi_dependencies = { name: version - for name, version in release_file.content.items() + for name, version in all_dependencies.items() if repository_file.content.get(name, {}).get(version, {}).get("source") == "pypi" } @@ -105,7 +106,7 @@ def lint( full_python_version = yaml.safe_load(f)[python_version] dependencies = PypiDependencies( - pypi_dependencies, python_version=full_python_version + pypi_dependencies, all_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 838ef250..501584b7 100644 --- a/komodo/pypi_dependencies.py +++ b/komodo/pypi_dependencies.py @@ -40,6 +40,7 @@ def format_full_version(info) -> str: class PypiDependencies: def __init__( self, + pypi_dependencies: Dict[str, str], to_install: Dict[str, str], python_version: str, cachefile: str = "./pypi_dependencies.yml", @@ -51,9 +52,11 @@ def __init__( self._failed_requirements: Dict[Requirement, str] = {} self._used_packages = set() - self._to_install = to_install - self._install_names = {canonicalize_name(name): name for name in to_install} + self._pypi_dependencies = { + canonicalize_name(name): version + for name, version in pypi_dependencies.items() + } self._to_install = { canonicalize_name(name): version for name, version in to_install.items() } @@ -70,13 +73,34 @@ def __init__( self._user_specified = {} def _update_package_sets(self, packages=None): - for package_name, version in packages or self._to_install.items(): + for package_name, version in packages or self._pypi_dependencies.items(): requirements = self._get_requirements(package_name, version) self._used_packages.add(package_name) for r in requirements: _ = self.satisfied(r, package_name) def failed_requirements(self, packages=None): + """ + >>> + >>> pypi_packages = { + ... "ert": "11.1.0", + ... "aiohttp": "3.10.10", + ... "deprecation": "2.1.0", + ... "filelock": "3.16.1", + ... "jinja2": "3.1.4", + ... "aiohappyeyeballs": "2.4.3", + ... "cryptography": "43.0.1", + ... "PyJWT": "2.3.0"} + >>> all_packages = { + ... **pypi_packages, + ... "xtgeo": "main", + ... "iterative_ensemble_smoother": "main"} + >>> dependencies = PypiDependencies(pypi_packages, all_packages, python_version="3.8") + >>> dependencies.add_user_specified("xtgeo", []) + >>> dependencies.add_user_specified("iterative_ensemble_smoother", []) + >>> dependencies.failed_requirements() # doctest: +ELLIPSIS + Not installed: aiosignal... + """ self._update_package_sets(packages) return self._failed_requirements @@ -114,7 +138,7 @@ def _get_requirements( ) -> List[Requirement]: """ >>> from packaging.requirements import Requirement - >>> PypiDependencies(to_install={}, python_version="3.8.11")._get_requirements( + >>> PypiDependencies({}, {}, python_version="3.8.11")._get_requirements( ... "rips", ... "2024.3.0.2" ... ) @@ -226,12 +250,13 @@ def satisfied( ) -> bool: """ >>> from packaging.requirements import Requirement - >>> PypiDependencies(to_install={}, python_version="3.8").satisfied( + >>> PypiDependencies({}, {}, python_version="3.8").satisfied( ... Requirement("PyJWT[crypto] (<3, >=1.0.0)") ... ) Not installed: pyjwt False - >>> PypiDependencies(to_install={"PyJWT": "2.3.0"}, python_version="3.8").satisfied( + >>> packages = {"PyJWT": "2.3.0"} + >>> PypiDependencies(packages, packages, python_version="3.8").satisfied( ... Requirement("PyJWT (<3, >=1.0.0)") ... ) True