Skip to content

Commit 9d3e5d4

Browse files
committed
strip out 'data-yanked' from HTML page with package source URLs served by PyPI (fixes #3301)
1 parent 7c1c288 commit 9d3e5d4

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+
# strip out data-yanked attributes before parsing HTML
501+
# see https://github.com/easybuilders/easybuild-framework/issues/3301
502+
urls_txt = re.sub('\s*data-yanked', '', 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
@@ -1303,6 +1303,15 @@ def test_pypi_source_urls(self):
13031303
# more than 50 releases at time of writing test, which always stay there
13041304
self.assertTrue(len(res) > 50)
13051305

1306+
# check for Python package that has yanked releases,
1307+
# see https://github.com/easybuilders/easybuild-framework/issues/3301
1308+
res = ft.pypi_source_urls('ipython')
1309+
self.assertTrue(isinstance(res, list) and res)
1310+
prefix = 'https://pypi.python.org/packages'
1311+
for entry in res:
1312+
self.assertTrue(entry.startswith(prefix), "'%s' should start with '%s'" % (entry, prefix))
1313+
self.assertTrue('ipython' in entry, "Pattern 'ipython' should be found in '%s'" % entry)
1314+
13061315
def test_derive_alt_pypi_url(self):
13071316
"""Test derive_alt_pypi_url() function."""
13081317
url = 'https://pypi.python.org/packages/source/e/easybuild/easybuild-2.7.0.tar.gz'

0 commit comments

Comments
 (0)