Skip to content

Commit bb02431

Browse files
authored
Merge pull request #3303 from boegel/pypi_yanked_releases
strip out 'data-yanked' from HTML page with package source URLs served by PyPI
2 parents 8f02741 + 5fa16cb commit bb02431

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

easybuild/tools/filetools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,13 @@ def pypi_source_urls(pkg_name):
495495
_log.debug("Failed to download %s to determine available PyPI URLs for %s", simple_url, pkg_name)
496496
res = []
497497
else:
498-
parsed_html = ElementTree.parse(urls_html)
498+
urls_txt = read_file(urls_html)
499+
500+
# ignore yanked releases (see https://pypi.org/help/#yanked)
501+
# see https://github.com/easybuilders/easybuild-framework/issues/3301
502+
urls_txt = re.sub(r'<a.*?data-yanked.*?</a>', '', urls_txt)
503+
504+
parsed_html = ElementTree.ElementTree(ElementTree.fromstring(urls_txt))
499505
if hasattr(parsed_html, 'iter'):
500506
res = [a.attrib['href'] for a in parsed_html.iter('a')]
501507
else:

test/framework/filetools.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,15 @@ def test_pypi_source_urls(self):
13271327
# more than 50 releases at time of writing test, which always stay there
13281328
self.assertTrue(len(res) > 50)
13291329

1330+
# check for Python package that has yanked releases,
1331+
# see https://github.com/easybuilders/easybuild-framework/issues/3301
1332+
res = ft.pypi_source_urls('ipython')
1333+
self.assertTrue(isinstance(res, list) and res)
1334+
prefix = 'https://pypi.python.org/packages'
1335+
for entry in res:
1336+
self.assertTrue(entry.startswith(prefix), "'%s' should start with '%s'" % (entry, prefix))
1337+
self.assertTrue('ipython' in entry, "Pattern 'ipython' should be found in '%s'" % entry)
1338+
13301339
def test_derive_alt_pypi_url(self):
13311340
"""Test derive_alt_pypi_url() function."""
13321341
url = 'https://pypi.python.org/packages/source/e/easybuild/easybuild-2.7.0.tar.gz'

0 commit comments

Comments
 (0)