From be7409c4c7e853dd35eab5318021af895ed8ce1e Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Mon, 15 Mar 2021 23:00:31 +0100 Subject: [PATCH] Fix error due to blank lines in exported requirements (#320) * test: Add failing test for blank lines Co-authored-by: Matteo Santamaria * fix: Ignore blank lines in requirements.txt Co-authored-by: Matteo Santamaria * refactor: Check for blank lines before invoking to_constraint Co-authored-by: Matteo Santamaria --- src/nox_poetry/sessions.py | 9 +++++---- tests/unit/test_sessions.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/nox_poetry/sessions.py b/src/nox_poetry/sessions.py index 1c73174b..3c211aa0 100644 --- a/src/nox_poetry/sessions.py +++ b/src/nox_poetry/sessions.py @@ -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()) diff --git a/tests/unit/test_sessions.py b/tests/unit/test_sessions.py index a1994585..ffd31175 100644 --- a/tests/unit/test_sessions.py +++ b/tests/unit/test_sessions.py @@ -1,4 +1,5 @@ """Unit tests for the sessions module.""" +from textwrap import dedent from typing import Callable from typing import Iterator @@ -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", ), ], )