Skip to content

Commit

Permalink
Load micropackage dependencies statically
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 Sep 1, 2023
1 parent 7c14263 commit 1932817
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
16 changes: 5 additions & 11 deletions kedro/framework/cli/micropkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
from typing import Any, Iterable, Iterator, List, Tuple, Union

import click
from build.util import project_wheel_metadata
from packaging.requirements import InvalidRequirement, Requirement
from packaging.utils import canonicalize_name
from pyproject_metadata import StandardMetadata
from rope.base.project import Project
from rope.contrib import generate
from rope.refactor.move import MoveModule
from rope.refactor.rename import Rename
from setuptools.discovery import FlatLayoutPackageFinder
import toml

from kedro.framework.cli.pipeline import (
_assert_pkg_name_ok,
Expand Down Expand Up @@ -210,12 +211,8 @@ def _pull_package( # noqa: too-many-arguments
)
project_root_dir = contents[0]

# This is much slower than parsing the requirements
# directly from the metadata files
# because it installs the package in an isolated environment,
# but it's the only reliable way of doing it
# without making assumptions on the project metadata.
library_meta = project_wheel_metadata(project_root_dir)
with open(project_root_dir / "pyproject.toml") as fh:
library_meta = StandardMetadata.from_pyproject(toml.load(fh))

# Project name will be `my-pipeline` even if `pyproject.toml` says `my_pipeline`
# because standards mandate normalization of names for comparison,
Expand Down Expand Up @@ -971,10 +968,7 @@ def _get_all_library_reqs(metadata):
"""Get all library requirements from metadata, leaving markers intact."""
# See https://discuss.python.org/t/\
# programmatically-getting-non-optional-requirements-of-current-directory/26963/2
return [
str(_EquivalentRequirement(dep_str))
for dep_str in metadata.get_all("Requires-Dist", [])
]
return [str(_EquivalentRequirement(str(dep))) for dep in metadata.dependencies]


def _safe_parse_requirements(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ requires-python = ">=3.7"
dependencies = [
"anyconfig>=0.10.0",
"attrs>=21.3",
"build>=0.7.0,",
"cachetools>=4.1",
"click>=4.0",
"cookiecutter>=2.1.1,<3.0",
Expand All @@ -30,6 +29,7 @@ dependencies = [
"parse>=1.19.0",
"pip-tools>=6.5",
"pluggy>=1.0,<1.3", # TODO: Uncap when dropping Python 3.7 support, see https://github.com/kedro-org/kedro/issues/2979
"pyproject_metadata",
"PyYAML>=4.2,<7.0",
"rich>=12.0,<14.0",
"rope>=0.21,<2.0", # subject to LGPLv3 license
Expand Down
11 changes: 0 additions & 11 deletions tests/framework/cli/micropkg/test_micropkg_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,17 +589,6 @@ def test_pull_from_pypi(
return_value=tmp_path,
)

# Mock needed to avoid an error when build.util.project_wheel_metadata
# calls tempfile.TemporaryDirectory, which is mocked
class _FakeWheelMetadata:
def get_all(self, name, failobj=None): # pylint: disable=unused-argument
return []

mocker.patch(
"kedro.framework.cli.micropkg.project_wheel_metadata",
return_value=_FakeWheelMetadata(),
)

options = ["-e", env] if env else []
options += ["--alias", alias] if alias else []

Expand Down

0 comments on commit 1932817

Please sign in to comment.