Skip to content

Commit

Permalink
Merge pull request #1807 from JonasT/run_setup_py_transform_fix
Browse files Browse the repository at this point in the history
Fix corner case of pip hack workaround we should get rid of anyway
  • Loading branch information
inclement authored May 12, 2019
2 parents 6f08f52 + eb3fbce commit 61e092c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
13 changes: 9 additions & 4 deletions pythonforandroid/pythonpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@


def transform_dep_for_pip(dependency):
if dependency.find("@") > 0:
if dependency.find("@") > 0 and (
dependency.find("@") < dependency.find("://") or
"://" not in dependency
):
# WORKAROUND FOR UPSTREAM BUG:
# https://github.com/pypa/pip/issues/6097
# (Please REMOVE workaround once that is fixed & released upstream!)
#
# Basically, setup_requires() can contain a format pip won't install
# from a requirements.txt (PEP 508 URLs).
# To avoid this, translate to an #egg-name= reference:
url = (dependency.partition("@")[2].strip() +
"#egg-name=" +
# To avoid this, translate to an #egg= reference:
if dependency.endswith("#"):
dependency = dependency[:-1]
url = (dependency.partition("@")[2].strip().partition("#egg")[0] +
"#egg=" +
dependency.partition("@")[0].strip()
)
return url
Expand Down
28 changes: 22 additions & 6 deletions tests/test_pythonpackage_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,31 @@ def test_get_dep_names_of_package():


def test_transform_dep_for_pip():
transformed = transform_dep_for_pip(
"python-for-android @ https://github.com/kivy/"
"python-for-android/archive/master.zip"
# A reminder, this entire function we test here is just a workaround
# for https://github.com/pypa/pip/issues/6097 (and not a nice one.)
# As soon as upstream fixes it, we should throw it & this test out
transformed = (
transform_dep_for_pip(
"python-for-android @ https://github.com/kivy/" +
"python-for-android/archive/master.zip"
),
transform_dep_for_pip(
"python-for-android @ https://github.com/kivy/" +
"python-for-android/archive/master.zip" +
"#egg=python-for-android-master"
),
transform_dep_for_pip(
"python-for-android @ https://github.com/kivy/" +
"python-for-android/archive/master.zip" +
"#" # common hack variant used by others to make pip parse it
),
)
expected = (
"https://github.com/kivy/python-for-android/archive/master.zip"
"#egg-name=python-for-android"
"https://github.com/kivy/python-for-android/archive/master.zip" +
"#egg=python-for-android"
)
assert transformed == expected
assert transformed == (expected, expected, expected)
assert transform_dep_for_pip("https://a@b/") == "https://a@b/"


def test_is_filesystem_path():
Expand Down

0 comments on commit 61e092c

Please sign in to comment.