Skip to content

Commit

Permalink
Fix project urls (sagemath#439)
Browse files Browse the repository at this point in the history
* Fix project url naming

* Add homepage and source urls from pyproject.toml in case it exists
  • Loading branch information
marcelotrevisani authored Feb 1, 2023
1 parent 2f1af4b commit ac11dca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions grayskull/strategy/py_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,9 @@ def discover_license(metadata: dict) -> List[ShortLicense]:
the license.
"""
git_url = metadata.get("dev_url")
if not git_url and urlparse(metadata.get("project_url", "")).netloc == "github.com":
git_url = metadata.get("project_url")
project_url = metadata.get("project_urls", "") or metadata.get("project_url", "")
if not git_url and urlparse(project_url).netloc == "github.com":
git_url = project_url
# "url" is always present but sometimes set to None
if not git_url and urlparse((metadata.get("url") or "")).netloc == "github.com":
git_url = metadata.get("url")
Expand Down
28 changes: 16 additions & 12 deletions grayskull/strategy/py_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,39 @@ def get_all_toml_info(path_toml: Union[Path, str]) -> dict:
toml_metadata = tomli.load(f)
toml_metadata = defaultdict(dict, toml_metadata)
metadata = nested_dict()

toml_project = toml_metadata.get("project", {}) or {}
metadata["requirements"]["host"] = toml_metadata["build-system"].get("requires", [])
metadata["requirements"]["run"] = toml_metadata["project"].get("dependencies", [])
license = toml_metadata["project"].get("license")
metadata["requirements"]["run"] = toml_project.get("dependencies", [])
license = toml_project.get("license")
if isinstance(license, dict):
license = license.get("text", "")
metadata["about"]["license"] = license
optional_deps = toml_metadata["project"].get("optional-dependencies", {})
optional_deps = toml_project.get("optional-dependencies", {})
metadata["test"]["requires"] = (
optional_deps.get("testing", [])
or optional_deps.get("test", [])
or optional_deps.get("tests", [])
)

if toml_metadata["project"].get("requires-python"):
py_constrain = f"python {toml_metadata['project']['requires-python']}"
tom_urls = toml_project.get("urls", {})
if homepage := tom_urls.get("Homepage"):
metadata["about"]["home"] = homepage
if dev_url := tom_urls.get("Source"):
metadata["about"]["dev_url"] = dev_url

if toml_project.get("requires-python"):
py_constrain = f"python {toml_project['requires-python']}"
metadata["requirements"]["host"].append(py_constrain)
metadata["requirements"]["run"].append(py_constrain)

if toml_metadata["project"].get("scripts"):
if toml_project.get("scripts"):
metadata["build"]["entry_points"] = []
for entry_name, entry_path in (
toml_metadata["project"].get("scripts", {}).items()
):
for entry_name, entry_path in toml_project.get("scripts", {}).items():
metadata["build"]["entry_points"].append(f"{entry_name} = {entry_path}")
if all_urls := toml_metadata["project"].get("urls"):
if all_urls := toml_project.get("urls"):
metadata["about"]["dev_url"] = all_urls.get("Source", None)
metadata["about"]["home"] = all_urls.get("Homepage", None)
metadata["about"]["summary"] = toml_metadata["project"].get("description")
metadata["about"]["summary"] = toml_project.get("description")

add_poetry_metadata(metadata, toml_metadata)

Expand Down
2 changes: 1 addition & 1 deletion grayskull/strategy/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def get_pypi_metadata(config: Configuration) -> dict:
"requires_dist": info.get("requires_dist", []),
"requires_python": info.get("requires_python", None),
"summary": info.get("summary"),
"project_url": info.get("project_url"),
"project_urls": info.get("project_urls") or info.get("project_url"),
"doc_url": info.get("docs_url"),
"dev_url": project_urls.get("Source"),
"url": info.get("home_page"),
Expand Down

0 comments on commit ac11dca

Please sign in to comment.