summaryrefslogtreecommitdiff
path: root/src/tox/tox_env/python
diff options
context:
space:
mode:
authorBernát Gábor <bgabor8@bloomberg.net>2021-01-14 09:41:36 +0000
committerGitHub <noreply@github.com>2021-01-14 09:41:36 +0000
commitd451b7eaed9ea9301ee2c34f98e33faafa654b90 (patch)
treee6b5fc81b40fc734d1aae878bbac66f9f895ae4e /src/tox/tox_env/python
parentbad3dc570438385ccd84648a6050a89cb5ced0fa (diff)
downloadtox-git-d451b7eaed9ea9301ee2c34f98e33faafa654b90.tar.gz
Support legacy way of specifying constraint files (and expand constraint files too) (#1823)
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
Diffstat (limited to 'src/tox/tox_env/python')
-rw-r--r--src/tox/tox_env/python/req_file.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/tox/tox_env/python/req_file.py b/src/tox/tox_env/python/req_file.py
index 3a035273..2796e492 100644
--- a/src/tox/tox_env/python/req_file.py
+++ b/src/tox/tox_env/python/req_file.py
@@ -58,10 +58,14 @@ class RequirementsFile:
def __init__(self, raw: str, allow_short_req_file: bool = True, root: Optional[Path] = None) -> None:
self._root = Path().cwd() if root is None else root
- if allow_short_req_file: # patch tox supporting requirements files via -rrequirements.txt
- r = ((f"-r {i[2:]}" if len(i) >= 3 and i.startswith("-r") and i[2] != " " else i) for i in raw.splitlines())
- adjusted = "\n".join(r)
- raw = f"{adjusted}\n" if raw.endswith("\\\n") else adjusted
+ if allow_short_req_file: # patch for tox<4 supporting requirement/constraint files via -rreq.txt/-creq.txt
+ lines: List[str] = []
+ for line in raw.splitlines():
+ if len(line) >= 3 and (line.startswith("-r") or line.startswith("-c")) and not line[2].isspace():
+ line = f"{line[:2]} {line[2:]}"
+ lines.append(line)
+ adjusted = "\n".join(lines)
+ raw = f"{adjusted}\n" if raw.endswith("\\\n") else adjusted # preserve trailing newline if input has it
self._raw = raw
def __str__(self) -> str:
@@ -93,8 +97,8 @@ class RequirementsFile:
if len(words) != 2:
raise ValueError(line)
else:
- if first == "-r":
- path = Path(line[3:].strip())
+ if first in ("-r", "--requirement", "-c", "--constraint"):
+ path = Path(line[len(first) + 1 :].strip())
if not path.is_absolute():
path = ini_dir / path
req_file = RequirementsFile(path.read_text(), allow_short_req_file=False, root=self.root)