Skip to content

Commit

Permalink
Make micropkg package use pyproject.toml
Browse files Browse the repository at this point in the history
Fix gh-2414.

Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>
  • Loading branch information
astrojuanlu committed Jul 10, 2023
1 parent 2ca65ab commit 80055fd
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions kedro/framework/cli/micropkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@
)
from kedro.framework.startup import ProjectMetadata

_SETUP_PY_TEMPLATE = """# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(
name="{name}",
version="{version}",
description="Micro-package `{name}`",
packages=find_packages(),
include_package_data=True,
install_requires={install_requires},
)
_PYPROJECT_TOML_TEMPLATE = """
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "{name}"
version = "{version}"
description = "Micro-package `{name}`"
dependencies = {install_requires}
[tool.setuptools.packages]
find = {{}}
"""


Expand Down Expand Up @@ -212,7 +214,7 @@ def _pull_package(
# without making assumptions on the project metadata.
library_meta = project_wheel_metadata(project_root_dir)

# Project name will be `my-pipeline` even if `setup.py` says `my_pipeline`
# Project name will be `my-pipeline` even if `pyproject.toml` says `my_pipeline`
# because standards mandate normalization of names for comparison,
# see https://packaging.python.org/en/latest/specifications/core-metadata/#name
# The proper way to get it would be
Expand Down Expand Up @@ -836,7 +838,7 @@ def _generate_sdist_file(
if conf_target.is_dir() and alias:
_rename_files(conf_target, micropkg_name, alias)

# Build a setup.py on the fly
# Build a pyproject.toml on the fly
try:
install_requires = _make_install_requires(
package_source / "requirements.txt" # type: ignore
Expand All @@ -847,7 +849,7 @@ def _generate_sdist_file(
raise KedroCliError(f"{cls.__module__}.{cls.__qualname__}: {exc}") from exc

_generate_manifest_file(temp_dir_path)
_generate_setup_file(package_name, version, install_requires, temp_dir_path)
_generate_pyproject_file(package_name, version, install_requires, temp_dir_path)

package_file = destination / _get_sdist_name(name=package_name, version=version)

Expand Down Expand Up @@ -883,19 +885,19 @@ def _generate_manifest_file(output_dir: Path):
)


def _generate_setup_file(
def _generate_pyproject_file(
package_name: str, version: str, install_requires: list[str], output_dir: Path
) -> Path:
setup_file = output_dir / "setup.py"
pyproject_file = output_dir / "pyproject.toml"

setup_file_context = {
pyproject_file_context = {
"name": package_name,
"version": version,
"install_requires": install_requires,
}

setup_file.write_text(_SETUP_PY_TEMPLATE.format(**setup_file_context))
return setup_file
pyproject_file.write_text(_PYPROJECT_TOML_TEMPLATE.format(**pyproject_file_context))
return pyproject_file


def _get_package_artifacts(
Expand Down

0 comments on commit 80055fd

Please sign in to comment.