diff --git a/repo2docker/utils.py b/repo2docker/utils.py index 10347198..d9d48dfc 100644 --- a/repo2docker/utils.py +++ b/repo2docker/utils.py @@ -473,14 +473,29 @@ def is_local_pip_requirement(line): # we just care that this isn't a "local pip requirement" if line.startswith("--pre"): return False + # strip off things like `--editable=`. Long form arguments require a = if line.startswith("--"): - line = line.split("=", 1)[1] + # if splitting doesn't work it is probably because the line contains + # a syntax error or our "parser" is too simplistic so we return True + # just in case + try: + line = line.split("=", 1)[1] + except IndexError: + return True + # strip off short form arguments like `-e`. Short form arguments can be # followed by a space `-e foo` or use `-e=foo`. The latter is not handled # here. We can deal with it when we see someone using it. if line.startswith("-"): - line = line.split(None, 1)[1] + # if splitting doesn't work it is probably because the line contains + # a syntax error or our "parser" is too simplistic so we return True + # just in case + try: + line = line.split(None, 1)[1] + except IndexError: + return True + if "file://" in line: # file references break isolation return True diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 7b45ffff..38b8beb6 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -147,7 +147,13 @@ def test_open_guess_encoding(): ("numpy", False), ("# -e .", False), ("--pre", False), + # pip ignores the package name and treats this like `--pre` on a line + # by itself ("--pre pandas", False), + # These are invalid lines as far as pip is concerned, check that our + # code is robust and continues running + ("--unrecognized", True), + ("-e", True), ], ) def test_local_pip_requirement(req, is_local):