Smarter splitting without try/except

pull/943/head
Tim Head 2020-08-17 08:03:36 +02:00
rodzic 4e3016981d
commit 10a0cdd04b
1 zmienionych plików z 15 dodań i 15 usunięć

Wyświetl plik

@ -463,48 +463,48 @@ def is_local_pip_requirement(line):
line = line.split("#", 1)[0].strip()
if not line:
return False
if line.startswith(("-r", "-c")):
# local -r or -c references break isolation
return True
if line.startswith(("--requirement", "--constraint")):
# as above but flags are spelt out
return True
# the `--pre` flag is a global flag and should appear on a line by itself
# 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("--"):
# 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
# if there is no = it is probably because the line contains
# a syntax error or our "parser" is too simplistic
if line.startswith("--") and "=" in line:
_, line = line.split("=", 1)
# 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("-"):
# 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
_, *rest = line.split(None, 1)
if not rest:
# no argument after `--flag`, skip line
return False
line = rest[0]
if "file://" in line:
# file references break isolation
return True
if "://" in line:
# handle git://../local/file
path = line.split("://", 1)[1]
else:
path = line
if path.startswith("."):
# references a local file
return True
return False