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

strip out 'data-yanked' from HTML page with package source URLs served by PyPI #3303

Merged
merged 4 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,13 @@ def pypi_source_urls(pkg_name):
_log.debug("Failed to download %s to determine available PyPI URLs for %s", simple_url, pkg_name)
res = []
else:
parsed_html = ElementTree.parse(urls_html)
urls_txt = read_file(urls_html)

# ignore yanked releases (see https://pypi.org/help/#yanked)
# see https://github.com/easybuilders/easybuild-framework/issues/3301
urls_txt = re.sub(r'<a.*?data-yanked.*?</a>', '', urls_txt)

parsed_html = ElementTree.ElementTree(ElementTree.fromstring(urls_txt))
if hasattr(parsed_html, 'iter'):
res = [a.attrib['href'] for a in parsed_html.iter('a')]
else:
Expand Down
9 changes: 9 additions & 0 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,15 @@ def test_pypi_source_urls(self):
# more than 50 releases at time of writing test, which always stay there
self.assertTrue(len(res) > 50)

# check for Python package that has yanked releases,
# see https://github.com/easybuilders/easybuild-framework/issues/3301
res = ft.pypi_source_urls('ipython')
self.assertTrue(isinstance(res, list) and res)
prefix = 'https://pypi.python.org/packages'
for entry in res:
self.assertTrue(entry.startswith(prefix), "'%s' should start with '%s'" % (entry, prefix))
self.assertTrue('ipython' in entry, "Pattern 'ipython' should be found in '%s'" % entry)

def test_derive_alt_pypi_url(self):
"""Test derive_alt_pypi_url() function."""
url = 'https://pypi.python.org/packages/source/e/easybuild/easybuild-2.7.0.tar.gz'
Expand Down