diff --git a/runpod/apps/build.py b/runpod/apps/build.py index c9cb31e0..b72c152b 100644 --- a/runpod/apps/build.py +++ b/runpod/apps/build.py @@ -70,6 +70,8 @@ MAX_ARTIFACT_MB = 1500 _REQ_NAME_RE = re.compile(r"^\s*([A-Za-z0-9][A-Za-z0-9._-]*)") +# same rule as pip: "#" at line start or after whitespace starts a comment +_REQ_COMMENT_RE = re.compile(r"(^|\s+)#.*$") class BuildError(AppError): @@ -97,8 +99,8 @@ def _requirements_txt(project_root: Path) -> List[str]: req_file = project_root / "requirements.txt" if req_file.exists(): for line in req_file.read_text().splitlines(): - line = line.strip() - if line and not line.startswith("#") and not line.startswith("-"): + line = _REQ_COMMENT_RE.sub("", line).strip() + if line and not line.startswith("-"): requirements.append(line) return requirements diff --git a/tests/test_apps/test_build.py b/tests/test_apps/test_build.py index b100387b..e8d452c8 100644 --- a/tests/test_apps/test_build.py +++ b/tests/test_apps/test_build.py @@ -62,6 +62,24 @@ def q(): # numpy deduped by name, requirements.txt wins on order assert reqs == ["numpy==1.26", "pandas", "requests"] + def test_strips_inline_comments(self, tmp_path): + (tmp_path / "requirements.txt").write_text( + "requests==2.32.3 # http client\n" + "numpy==1.26\t# tab before the comment\n" + "pkg @ https://example.com/pkg-1.0-py3-none-any.whl#sha256=abc\n" + ) + app = App("a") + + @app.queue(name="q", cpu="cpu3c-1-2") + def q(): + pass + + assert collect_requirements(tmp_path, app) == [ + "requests==2.32.3", + "numpy==1.26", + "pkg @ https://example.com/pkg-1.0-py3-none-any.whl#sha256=abc", + ] + def test_no_requirements_file(self, tmp_path): app = App("a")