Skip to content

Commit

Permalink
Add support for flit scripts (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrevisani authored Sep 21, 2023
1 parent fce7663 commit 18fbf5f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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"]}}

0 comments on commit 18fbf5f

Please sign in to comment.