Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding -e flag to editable local references #258

Merged
merged 3 commits into from
Apr 30, 2024
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
21 changes: 11 additions & 10 deletions src/poetry_plugin_export/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,13 @@ def _export_generic_txt(
dependency = dependency_package.dependency
package = dependency_package.package

if package.develop:
if not allow_editable:
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 "
if package.develop and not allow_editable:
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

requirement = dependency.to_pep_508(with_extras=False, resolved=True)
is_direct_local_reference = (
Expand All @@ -129,7 +127,10 @@ def _export_generic_txt(
elif is_direct_local_reference:
assert dependency.source_url is not None
dependency_uri = path_to_url(dependency.source_url)
line = f"{package.complete_name} @ {dependency_uri}"
if package.develop:
line = f"-e {dependency_uri}"
radoering marked this conversation as resolved.
Show resolved Hide resolved
else:
line = f"{package.complete_name} @ {dependency_uri}"
else:
line = f"{package.complete_name}=={package.version}"

Expand Down
41 changes: 41 additions & 0 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,47 @@ def test_exporter_can_export_requirements_txt_with_directory_packages(
assert content == expected


def test_exporter_can_export_requirements_txt_with_directory_packages_editable(
tmp_path: Path, poetry: Poetry, fixture_root_uri: str
) -> None:
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
{
"package": [
{
"name": "foo",
"version": "1.2.3",
"optional": False,
"python-versions": "*",
"develop": True,
"source": {
"type": "directory",
"url": "sample_project",
"reference": "",
},
}
],
"metadata": {
"python-versions": "*",
"content-hash": "123456789",
"files": {"foo": []},
},
}
)
set_package_requires(poetry)

exporter = Exporter(poetry, NullIO())
exporter.export("requirements.txt", tmp_path, "requirements.txt")

with (tmp_path / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()

expected = f"""\
-e {fixture_root_uri}/sample_project ; {MARKER_PY}
"""

assert content == expected


def test_exporter_can_export_requirements_txt_with_nested_directory_packages(
tmp_path: Path, poetry: Poetry, fixture_root_uri: str
) -> None:
Expand Down
Loading