Skip to content

Commit

Permalink
Adding -e flag to editable local references (#258)
Browse files Browse the repository at this point in the history
Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
  • Loading branch information
fredsensibill and radoering committed Apr 30, 2024
1 parent a06b7e4 commit d2b2afe
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
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}"
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

0 comments on commit d2b2afe

Please sign in to comment.