Skip to content

Commit 9862577

Browse files
committed
exporter: print warning instead of raising an error when exporting a constraints.txt with editable dependencies
1 parent a52c847 commit 9862577

File tree

4 files changed

+116
-50
lines changed

4 files changed

+116
-50
lines changed

src/poetry_plugin_export/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def handle(self) -> None:
100100
f"Extra [{', '.join(sorted(invalid_extras))}] is not specified."
101101
)
102102

103-
exporter = Exporter(self.poetry)
103+
exporter = Exporter(self.poetry, self.io)
104104
exporter.only_groups(list(self.activated_groups))
105105
exporter.with_extras(list(extras))
106106
exporter.with_hashes(not self.option("without-hashes"))

src/poetry_plugin_export/exporter.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class Exporter:
3434
FORMAT_REQUIREMENTS_TXT: "_export_requirements_txt",
3535
}
3636

37-
def __init__(self, poetry: Poetry) -> None:
37+
def __init__(self, poetry: Poetry, io: IO) -> None:
3838
self._poetry = poetry
39+
self._io = io
3940
self._with_hashes = True
4041
self._with_credentials = False
4142
self._with_urls = True
@@ -106,10 +107,12 @@ def _export_generic_txt(
106107

107108
if package.develop:
108109
if not allow_editable:
109-
raise RuntimeError(
110-
f"{package.pretty_name} is locked in develop (editable) mode,"
111-
" which is incompatible with the constraints.txt format."
110+
self._io.write_error_line(
111+
f"<warning>Warning: {package.pretty_name} is locked in develop"
112+
" (editable) mode, which is incompatible with the"
113+
" constraints.txt format.</warning>"
112114
)
115+
continue
113116
line += "-e "
114117

115118
requirement = dependency.to_pep_508(with_extras=False)

tests/command/test_command_export.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import shutil
4+
35
from typing import TYPE_CHECKING
46
from unittest.mock import Mock
57

@@ -229,3 +231,44 @@ def test_export_with_urls(
229231
monkeypatch.setattr(Exporter, "with_urls", mock_export)
230232
tester.execute("--without-urls")
231233
mock_export.assert_called_once_with(False)
234+
235+
236+
def test_export_exports_constraints_txt_with_warnings(
237+
tmp_path: Path,
238+
fixture_root: Path,
239+
project_factory: ProjectFactory,
240+
command_tester_factory: CommandTesterFactory,
241+
) -> None:
242+
# On Windows we have to make sure that the path dependency and the pyproject.toml
243+
# are on the same drive, otherwise locking fails.
244+
# (in our CI fixture_root is on D:\ but temp_path is on C:\)
245+
editable_dep_path = tmp_path / "project_with_nested_local"
246+
shutil.copytree(fixture_root / "project_with_nested_local", editable_dep_path)
247+
248+
pyproject_content = f"""\
249+
[tool.poetry]
250+
name = "simple-project"
251+
version = "1.2.3"
252+
description = "Some description."
253+
authors = [
254+
"Sébastien Eustace <[email protected]>"
255+
]
256+
257+
[tool.poetry.dependencies]
258+
python = "^3.6"
259+
baz = ">1.0"
260+
project-with-nested-local = {{ path = "{editable_dep_path.as_posix()}", \
261+
develop = true }}
262+
"""
263+
poetry = project_factory(name="export", pyproject_content=pyproject_content)
264+
tester = command_tester_factory("export", poetry=poetry)
265+
tester.execute("--format constraints.txt")
266+
267+
develop_warning = (
268+
"Warning: project-with-nested-local is locked in develop (editable) mode, which"
269+
" is incompatible with the constraints.txt format.\n"
270+
)
271+
expected = 'baz==2.0.0 ; python_version >= "3.6" and python_version < "4.0"\n'
272+
273+
assert develop_warning in tester.io.fetch_error()
274+
assert tester.io.fetch_output() == expected

0 commit comments

Comments
 (0)