Skip to content

Commit fbd0042

Browse files
authored
Merge pull request #2785 from regro/revert-2782-revert-2649-fix/github_tag_version_source
Revert "Revert "Use version prefix from github URL""
2 parents 951e7c5 + 7bbb11e commit fbd0042

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

conda_forge_tick/update_sources.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,34 @@ def get_url(self, meta_yaml) -> Optional[str]:
553553

554554
class Github(VersionFromFeed):
555555
name = "Github"
556+
version_prefix = None
557+
558+
def set_version_prefix(self, version: str, split_url: list[str]):
559+
self.version_prefix = self.get_version_prefix(version, split_url)
560+
if self.version_prefix is None:
561+
return
562+
logger.debug(f"Found version prefix from url: {self.version_prefix}")
563+
self.ver_prefix_remove = [self.version_prefix] + self.ver_prefix_remove
564+
565+
def get_version_prefix(self, version: str, split_url: list[str]):
566+
"""Returns prefix for the first split that contains version. If prefix
567+
is empty - returns None."""
568+
r = re.compile(rf"^(.*){version}")
569+
for split in split_url:
570+
match = r.match(split)
571+
if match is not None:
572+
if match.group(1) == "":
573+
return None
574+
return match.group(1)
575+
576+
return None
556577

557578
def get_url(self, meta_yaml) -> Optional[str]:
558579
if "github.com" not in meta_yaml["url"]:
559580
return None
560581
split_url = meta_yaml["url"].lower().split("/")
582+
version = meta_yaml["version"]
583+
self.set_version_prefix(version, split_url)
561584
package_owner = split_url[split_url.index("github.com") + 1]
562585
gh_package_name = split_url[split_url.index("github.com") + 2]
563586
return f"https://github.com/{package_owner}/{gh_package_name}/releases.atom"

tests/test_upstream_versions.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,3 +1643,54 @@ def test_main(
16431643
update_upstream_versions_mock.assert_called_once_with(
16441644
gx, debug=debug, job=3, n_jobs=10, package="testpackage"
16451645
)
1646+
1647+
1648+
@pytest.mark.parametrize(
1649+
"url, version, version_prefix",
1650+
[
1651+
("https://example.com/archs/1.2.3.tar.gz", "1.2.3", None),
1652+
# we don't want any assumptions on non github urls
1653+
("https://example.com/archs/example-1.2.3.tar.gz", "1.2.3", None),
1654+
(
1655+
"https://github.com/example/example/archive/refs/tags/1.2.3.tar.gz",
1656+
"1.2.3",
1657+
None,
1658+
),
1659+
(
1660+
"https://github.com/example/example/archive/refs/tags/example-1.2.3.tar.gz",
1661+
"1.2.3",
1662+
"example-",
1663+
),
1664+
(
1665+
"https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.6/llvm-18.1.6.src.tar.xz",
1666+
"18.1.6",
1667+
"llvmorg-",
1668+
),
1669+
(
1670+
"https://github.com/simplejson/simplejson/releases/download/1.2.3/simplejson-1.2.3.tar.gz",
1671+
"1.2.3",
1672+
None,
1673+
),
1674+
# Test URLs without source version (if any)
1675+
("https://example.com/archs/sources.tar.gz", "1.2.3", None),
1676+
("https://github.com/archs/sources.tar.gz", "1.2.3", None),
1677+
],
1678+
)
1679+
@flaky
1680+
def test_github_version_prefix(url, version, version_prefix, tmpdir):
1681+
gh = Github()
1682+
meta_yaml = LazyJson(os.path.join(tmpdir, "cf-scripts-test.json"))
1683+
with meta_yaml as _meta_yaml:
1684+
_meta_yaml.update(
1685+
{
1686+
"version": version,
1687+
"url": url,
1688+
}
1689+
)
1690+
1691+
gh.get_url(meta_yaml)
1692+
1693+
if version_prefix is None:
1694+
assert gh.version_prefix is None
1695+
else:
1696+
assert gh.version_prefix == version_prefix

0 commit comments

Comments
 (0)