Skip to content

Commit

Permalink
Merge pull request #42 from stfc/bugfix/fix-missing-pkg-resources
Browse files Browse the repository at this point in the history
Bugfix: Update requirements-parser to v0.11.0 to fix pkg_resources bug
  • Loading branch information
Alex-JG3 authored Feb 12, 2025
2 parents 1c1657e + 833b123 commit 1539306
Show file tree
Hide file tree
Showing 3 changed files with 1,114 additions and 830 deletions.
14 changes: 9 additions & 5 deletions hooks/check_missing_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import subprocess
import sys
from pathlib import Path
from typing import List
from typing import List, Optional

import requirements

from .utils import Hook


def _parse_package_name(name: str) -> str:
def _parse_package_name(name: Optional[str]) -> Optional[str]:
"""
Force lower case and replace underscore with dash to compare environment
packages (see https://www.python.org/dev/peps/pep-0426/#name)
Expand All @@ -22,7 +22,7 @@ def _parse_package_name(name: str) -> str:
Returns:
Formatted package name
"""
return name.lower().replace("_", "-")
return name.lower().replace("_", "-") if name else None


def _get_installed_packages() -> List[str]:
Expand All @@ -33,7 +33,7 @@ def _get_installed_packages() -> List[str]:
Returns:
List of formatted names of installed packages
"""
return [
package_names = [
_parse_package_name(req.name)
for req in requirements.parse(
subprocess.check_output(
Expand All @@ -42,6 +42,8 @@ def _get_installed_packages() -> List[str]:
)
]

return [name for name in package_names if name]


def _get_required_packages(filepath: str) -> List[str]:
"""
Expand All @@ -58,12 +60,14 @@ def _get_required_packages(filepath: str) -> List[str]:
Returns:
List of formatted names of installed packages
"""
return [
package_names = [
_parse_package_name(req.name)
for req in requirements.parse(Path(filepath).read_text())
if req.name
]

return [name for name in package_names if name]


class CheckMissingRequirements(Hook): # pylint: disable=too-few-public-methods
"""Hook to check all requirements are installed within the current dev
Expand Down
Loading

0 comments on commit 1539306

Please sign in to comment.