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

Also try mangling sdist urls to match pep625 #2794

Merged
merged 9 commits into from
Jun 14, 2024
37 changes: 25 additions & 12 deletions conda_forge_tick/url_transforms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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):
for old_ext, new_ext in permutations(EXTS, 2):
Expand Down Expand Up @@ -48,23 +50,29 @@ 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")
bollwyvl marked this conversation as resolved.
Show resolved Hide resolved
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)

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

if not (is_sdist and is_pypi and has_version):
return

# try static PEP625 name with PEP345 distribution name (_ not -)
yield os.path.join(dn, '%s-{{ version }}.tar.gz' % dist_bn.replace("-", "_"))
bollwyvl marked this conversation as resolved.
Show resolved Hide resolved
# many legacy names had - which would match the name
yield os.path.join(dn, '%s-{{ version }}.tar.gz' % dist_bn)


def _pypi_munger(url):
names = [
Expand Down Expand Up @@ -141,7 +149,9 @@ def gen_transformed_urls(url):
url : str
The URL to transform.
"""
yield from _gen_new_urls(
yielded = []
bollwyvl marked this conversation as resolved.
Show resolved Hide resolved

for new_url in _gen_new_urls(
url,
[
_ext_munger,
Expand All @@ -154,4 +164,7 @@ def gen_transformed_urls(url):
_pypi_name_munger,
_github_munger,
],
)
):
if new_url not in yielded:
yield new_url
yielded.append(new_url)
bollwyvl marked this conversation as resolved.
Show resolved Hide resolved