Skip to content

Commit

Permalink
Fix error due to blank lines in exported requirements (#320)
Browse files Browse the repository at this point in the history
* test: Add failing test for blank lines

Co-authored-by: Matteo Santamaria <[email protected]>

* fix: Ignore blank lines in requirements.txt

Co-authored-by: Matteo Santamaria <[email protected]>

* refactor: Check for blank lines before invoking to_constraint

Co-authored-by: Matteo Santamaria <[email protected]>
  • Loading branch information
cjolowicz and matteosantama authored Mar 15, 2021
1 parent e077ba6 commit be7409c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/nox_poetry/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ def to_constraints(requirements: str) -> str:
"""Convert requirements to constraints."""

def _to_constraints() -> Iterator[str]:
lines = requirements.strip().splitlines()
lines = requirements.splitlines()
for line, requirement in enumerate(lines, start=1):
constraint = to_constraint(requirement, line)
if constraint is not None:
yield constraint
if requirement.strip():
constraint = to_constraint(requirement, line)
if constraint is not None:
yield constraint

return "\n".join(_to_constraints())

Expand Down
12 changes: 10 additions & 2 deletions tests/unit/test_sessions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for the sessions module."""
from textwrap import dedent
from typing import Callable
from typing import Iterator

Expand Down Expand Up @@ -153,9 +154,16 @@ def test_session_build_package(proxy: nox_poetry.Session) -> None:
'regex==2020.10.28; python_version == "3.5"',
),
("-e ../lib/foo", ""),
("--extra-index-url https://example.com/pypi/simple", ""),
(
"--extra-index-url https://example.com/pypi/simple",
"",
dedent(
"""
--extra-index-url https://example.com/pypi/simple
boltons==20.2.1
"""
),
"boltons==20.2.1",
),
],
)
Expand Down

0 comments on commit be7409c

Please sign in to comment.