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

Add support for flit scripts #493

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions grayskull/strategy/py_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,25 @@ def is_poetry_present(toml_metadata: dict) -> bool:
return "poetry" in toml_metadata.get("tool", {})


def is_flit_present(toml_metadata: dict) -> bool:
return "flit" in toml_metadata.get("tool", {})


def add_flit_metadata(metadata: dict, toml_metadata: dict) -> dict:
if not is_flit_present(toml_metadata):
return metadata

flit_metadata = toml_metadata["tool"]["flit"]
flit_scripts = flit_metadata.get("scripts", {})
for entry_name, entry_path in flit_scripts.items():
if "build" not in metadata:
metadata["build"] = {}
if "entry_points" not in metadata["build"]:
metadata["build"]["entry_points"] = []
metadata["build"]["entry_points"].append(f"{entry_name} = {entry_path}")
return metadata


def get_all_toml_info(path_toml: Union[Path, str]) -> dict:
with open(path_toml, "rb") as f:
toml_metadata = tomli.load(f)
Expand Down Expand Up @@ -268,5 +287,6 @@ def get_all_toml_info(path_toml: Union[Path, str]) -> dict:
metadata["name"] = metadata.get("name") or toml_project.get("name")

add_poetry_metadata(metadata, toml_metadata)
add_flit_metadata(metadata, toml_metadata)

return metadata
8 changes: 8 additions & 0 deletions tests/test_flit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from grayskull.strategy.py_toml import add_flit_metadata


def test_add_flit_metadata():
metadata = {"build": {"entry_points": []}}
toml_metadata = {"tool": {"flit": {"scripts": {"key": "value"}}}}
result = add_flit_metadata(metadata, toml_metadata)
assert result == {"build": {"entry_points": ["key = value"]}}
Loading