Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions runpod/apps/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions tests/test_apps/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down