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

Attempt to fix some URL bugs #525

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions grayskull/strategy/py_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def discover_license(metadata: dict) -> List[ShortLicense]:
the license.
"""
git_url = metadata.get("dev_url")
project_url = metadata.get("project_urls", "") or metadata.get("project_url", "")
project_url = 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
Expand Down Expand Up @@ -716,7 +716,7 @@ def merge_setup_toml_metadata(setup_metadata: dict, pyproject_metadata: dict) ->
if pyproject_metadata["about"]["summary"]:
setup_metadata["summary"] = pyproject_metadata["about"]["summary"]
if pyproject_metadata["about"]["home"]:
setup_metadata["projects_url"]["Homepage"] = pyproject_metadata["about"]["home"]
setup_metadata["project_urls"]["Homepage"] = pyproject_metadata["about"]["home"]
if pyproject_metadata["build"]["entry_points"]:
setup_metadata["entry_points"]["console_scripts"] = pyproject_metadata["build"][
"entry_points"
Expand Down
43 changes: 34 additions & 9 deletions grayskull/strategy/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ def get_val(key):
pypi_metadata.get("requires_python")
or sdist_metadata.get("python_requires")
),
"doc_url": get_val("doc_url"),
"docs_url": get_val("docs_url"),
"dev_url": get_val("dev_url"),
"license": get_val("license"),
"setup_requires": get_val("setup_requires"),
"extra_requires": get_val("extra_requires"),
"project_url": get_val("project_url"),
"project_urls": get_val("project_urls"),
"extras_require": get_val("extras_require"),
"requires_dist": requires_dist,
"sdist_path": get_val("sdist_path"),
Expand Down Expand Up @@ -270,7 +271,6 @@ def get_pypi_metadata(config: Configuration) -> dict:
json.dump(metadata, f, indent=4)
config.files_to_copy.append(download_file)
info = metadata["info"]
project_urls = info.get("project_urls") or {}
log.info(f"Package: {config.name}=={info['version']}")
log.debug(f"Full PyPI metadata:\n{metadata}")
sdist_url = get_sdist_url_from_pypi(metadata)
Expand All @@ -282,10 +282,10 @@ 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_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"),
"project_url": info.get("project_url"),
"project_urls": info.get("project_urls") or {},
"docs_url": info.get("docs_url"),
"home_page": info.get("home_page"),
"license": info.get("license"),
"source": {
"url": "https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/"
Expand Down Expand Up @@ -401,11 +401,36 @@ def get_metadata(recipe, config) -> dict:
test_requirements = optional_requirements.pop(config.extras_require_test, [])
test_section = compose_test_section(metadata, test_requirements)

# Compute home, doc_url, and dev_url for the "about" section

if metadata.get("project_urls") and metadata["project_urls"].get("Homepage"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you encapsulate all this handling for the URLs in a function please?
so we can test that easily :)

home = metadata["project_urls"]["Homepage"]
elif metadata.get("project_url"):
home = metadata["project_url"]
elif metadata.get("url"):
home = metadata["url"]
else:
home = None

if metadata.get("project_urls") and metadata["project_urls"].get("Documentation"):
doc_url = metadata["project_urls"]["Documentation"]
elif metadata.get("docs_url"):
doc_url = metadata["docs_url"]
else:
doc_url = None

if metadata.get("project_urls") and metadata["project_urls"].get("Source"):
dev_url = metadata["project_urls"]["Source"]
elif metadata.get("dev_url"):
dev_url = metadata["dev_url"]
else:
dev_url = None

about_section = {
"home": metadata["url"] if metadata.get("url") else metadata.get("project_url"),
"home": home,
"summary": metadata.get("summary"),
"doc_url": metadata.get("doc_url"),
"dev_url": metadata.get("dev_url"),
"doc_url": doc_url,
"dev_url": dev_url,
"license": license_name,
"license_file": license_file,
}
Expand Down
Loading