Skip to content

Commit

Permalink
Safely parse requirements files everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>
  • Loading branch information
astrojuanlu committed Jun 13, 2023
1 parent f7364fd commit 3fc5cc3
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions kedro/framework/cli/micropkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,6 @@ def _sync_path_list(source: list[tuple[Path, str]], target: Path) -> None:
_sync_dirs(source_path, target_with_suffix)


def _make_install_requires(requirements_txt: Path) -> list[str]:
"""Parses each line of requirements.txt into a version specifier valid to put in
install_requires."""
if not requirements_txt.exists():
return []
requirements = pkg_resources.parse_requirements(requirements_txt.read_text())
return [str(requirement) for requirement in requirements]


def _create_nested_package(project: Project, package_path: Path) -> Path:
# fails if parts of the path exists already
packages = package_path.parts
Expand Down Expand Up @@ -746,9 +737,12 @@ def _generate_sdist_file(

# Build a setup.py on the fly
try:
install_requires = _make_install_requires(
metadata.project_path / "requirements.txt" # type: ignore
)
install_requires = [
str(req)
for req in _safe_parse_requirements(
(metadata.project_path / "requirements.txt").read_text() # type: ignore
)
]
except Exception as exc:
click.secho("FAILED", fg="red")
cls = exc.__class__
Expand Down

0 comments on commit 3fc5cc3

Please sign in to comment.