Skip to content

Commit

Permalink
Have separate file for managing the builtin python
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed May 2, 2024
1 parent 2361e15 commit 5418439
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
23 changes: 17 additions & 6 deletions komodo/check_unused_package.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = [
Expand All @@ -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":
Expand Down Expand Up @@ -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__":
Expand Down
8 changes: 5 additions & 3 deletions komodo/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import warnings
from collections import namedtuple

import yaml
from packaging.version import parse

from .pypi_dependencies import PypiDependencies
Expand Down Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion tests/test_check_unused_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand Down

0 comments on commit 5418439

Please sign in to comment.