Skip to content
Merged
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
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
43 changes: 43 additions & 0 deletions tests/command/test_command_export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import shutil

from typing import TYPE_CHECKING
from unittest.mock import Mock

Expand Down Expand Up @@ -229,3 +231,44 @@ 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(
tmp_path: Path,
fixture_root: Path,
project_factory: ProjectFactory,
command_tester_factory: CommandTesterFactory,
) -> None:
# On Windows we have to make sure that the path dependency and the pyproject.toml
# are on the same drive, otherwise locking fails.
# (in our CI fixture_root is on D:\ but temp_path is on C:\)
editable_dep_path = tmp_path / "project_with_nested_local"
shutil.copytree(fixture_root / "project_with_nested_local", editable_dep_path)

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 = "{editable_dep_path.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