Skip to content

Commit

Permalink
exporter: print warning instead of raising an error when exporting a …
Browse files Browse the repository at this point in the history
…constraints.txt with editable dependencies
  • Loading branch information
radoering committed Oct 8, 2022
1 parent a52c847 commit 8511181
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/poetry_plugin_export/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def handle(self) -> None:
f"Extra [{', '.join(sorted(invalid_extras))}] is not specified."
)

exporter = Exporter(self.poetry)
exporter = Exporter(self.poetry, self.io)
exporter.only_groups(list(self.activated_groups))
exporter.with_extras(list(extras))
exporter.with_hashes(not self.option("without-hashes"))
Expand Down
11 changes: 7 additions & 4 deletions src/poetry_plugin_export/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class Exporter:
FORMAT_REQUIREMENTS_TXT: "_export_requirements_txt",
}

def __init__(self, poetry: Poetry) -> None:
def __init__(self, poetry: Poetry, io: IO) -> None:
self._poetry = poetry
self._io = io
self._with_hashes = True
self._with_credentials = False
self._with_urls = True
Expand Down Expand Up @@ -106,10 +107,12 @@ def _export_generic_txt(

if package.develop:
if not allow_editable:
raise RuntimeError(
f"{package.pretty_name} is locked in develop (editable) mode,"
" which is incompatible with the constraints.txt format."
self._io.write_error_line(
f"<warning>Warning: {package.pretty_name} is locked in develop"
" (editable) mode, which is incompatible with the"
" constraints.txt format.</warning>"
)
continue
line += "-e "

requirement = dependency.to_pep_508(with_extras=False)
Expand Down
34 changes: 34 additions & 0 deletions tests/command/test_command_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,37 @@ def test_export_with_urls(
monkeypatch.setattr(Exporter, "with_urls", mock_export)
tester.execute("--without-urls")
mock_export.assert_called_once_with(False)


def test_export_exports_constraints_txt_with_warnings(
fixture_root: Path,
project_factory: ProjectFactory,
command_tester_factory: CommandTesterFactory,
) -> None:
pyproject_content = f"""\
[tool.poetry]
name = "simple-project"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
]
[tool.poetry.dependencies]
python = "^3.6"
baz = ">1.0"
project-with-nested-local = {{ path = \
"{(fixture_root / "project_with_nested_local").as_posix()}", develop = true }}
"""
poetry = project_factory(name="export", pyproject_content=pyproject_content)
tester = command_tester_factory("export", poetry=poetry)
tester.execute("--format constraints.txt")

develop_warning = (
"Warning: project-with-nested-local is locked in develop (editable) mode, which"
" is incompatible with the constraints.txt format.\n"
)
expected = 'baz==2.0.0 ; python_version >= "3.6" and python_version < "4.0"\n'

assert develop_warning in tester.io.fetch_error()
assert tester.io.fetch_output() == expected
Loading

0 comments on commit 8511181

Please sign in to comment.