Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make kedro micropkg package use pyproject.toml #2761

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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