Skip to content

Commit

Permalink
Merge pull request #2794 from bollwyvl/check-pep625-sdist-urls
Browse files Browse the repository at this point in the history
Also try mangling sdist urls to match pep625
  • Loading branch information
beckermr authored Jun 14, 2024
2 parents 2c96e01 + 2bea2c2 commit efadfca
Show file tree
Hide file tree
Showing 2 changed files with 300 additions and 12 deletions.
50 changes: 38 additions & 12 deletions conda_forge_tick/url_transforms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import re
from itertools import permutations

EXTS = [".tar.gz", ".zip", ".tar", ".tar.bz2", ".tar.xz", ".tgz"]
PYPI_URLS = ["https://pypi.io", "https://files.pythonhosted.org"]


def _ext_munger(url):
Expand Down Expand Up @@ -48,23 +50,42 @@ def _v_munger(url):


def _pypi_domain_munger(url):
for old_d, new_d in permutations(
["https://pypi.io", "https://files.pythonhosted.org"],
2,
):
for old_d, new_d in permutations(PYPI_URLS, 2):
yield url.replace(old_d, new_d, 1)


def _pypi_name_munger(url):
bn = os.path.basename(url)
if (
url.startswith("https://pypi.io")
or url.startswith("https://files.pythonhosted.org")
) and ("{{ version }}" in bn and "{{ name" not in bn):
yield os.path.join(os.path.dirname(url), "{{ name }}-{{ version }}.tar.gz")

dn = os.path.dirname(url)
dist_bn = os.path.basename(os.path.dirname(url))
is_sdist = url.endswith(".tar.gz")
is_pypi = any(url.startswith(pypi) for pypi in PYPI_URLS)
has_version = re.search(r"\{\{\s*version", bn)
has_name = re.search(r"\{\{\s*name", bn)

# try the original URL first, as a fallback (probably can't be removed?)
yield url

if is_pypi and has_version and not has_name:
yield os.path.join(dn, "{{ name }}-{{ version }}.tar.gz")

if not (is_sdist and is_pypi and has_version):
return

# try static PEP625 name with PEP345 distribution name (_ not -)
patterns = [
# fully normalized
r"[\.\-]+",
# older, partial normalization
r"[\-]+",
]

for pattern in patterns:
for dist_bn_case in {dist_bn, dist_bn.lower()}:
yield os.path.join(
dn, "%s-{{ version }}.tar.gz" % re.sub(pattern, "_", dist_bn_case)
)


def _pypi_munger(url):
names = [
Expand Down Expand Up @@ -141,7 +162,9 @@ def gen_transformed_urls(url):
url : str
The URL to transform.
"""
yield from _gen_new_urls(
yielded = set()

for new_url in _gen_new_urls(
url,
[
_ext_munger,
Expand All @@ -154,4 +177,7 @@ def gen_transformed_urls(url):
_pypi_name_munger,
_github_munger,
],
)
):
if new_url not in yielded:
yield new_url
yielded.add(new_url)
Loading

0 comments on commit efadfca

Please sign in to comment.