Skip to content

Commit 7e6222f

Browse files
authored
pay attention to package sources in export (#111)
1 parent f8cbb9c commit 7e6222f

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/poetry_plugin_export/walker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def get_locked_package(
229229
for package in candidates
230230
if package.python_constraint.allows_all(dependency.python_constraint)
231231
and dependency.constraint.allows(package.version)
232+
and (dependency.source_type is None or dependency.is_same_source_as(package))
232233
]
233234

234235
# If we have an overlapping candidate, we must use it.

tests/test_exporter.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
from poetry_plugin_export.exporter import Exporter
2020
from tests.markers import MARKER_CPYTHON
21+
from tests.markers import MARKER_DARWIN
22+
from tests.markers import MARKER_LINUX
2123
from tests.markers import MARKER_PY
2224
from tests.markers import MARKER_PY27
2325
from tests.markers import MARKER_PY36
@@ -2321,3 +2323,78 @@ def test_exporter_omits_unwanted_extras(
23212323
exporter.export("requirements.txt", Path(tmp_dir), io)
23222324

23232325
assert io.fetch_output() == "\n".join(expected) + "\n"
2326+
2327+
2328+
def test_exporter_respects_package_sources(tmp_dir: str, poetry: Poetry) -> None:
2329+
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
2330+
{
2331+
"package": [
2332+
{
2333+
"name": "foo",
2334+
"python-versions": ">=3.6",
2335+
"version": "1.0.0",
2336+
"category": "main",
2337+
"optional": False,
2338+
"dependencies": {},
2339+
"source": {
2340+
"type": "url",
2341+
"url": "https://example.com/foo-darwin.whl",
2342+
},
2343+
},
2344+
{
2345+
"name": "foo",
2346+
"python-versions": ">=3.6",
2347+
"version": "1.0.0",
2348+
"category": "main",
2349+
"optional": False,
2350+
"dependencies": {},
2351+
"source": {
2352+
"type": "url",
2353+
"url": "https://example.com/foo-linux.whl",
2354+
},
2355+
},
2356+
],
2357+
"metadata": {
2358+
"lock-version": "1.1",
2359+
"python-versions": "^3.6",
2360+
"content-hash": (
2361+
"832b13a88e5020c27cbcd95faa577bf0dbf054a65c023b45dc9442b640d414e6"
2362+
),
2363+
"hashes": {
2364+
"foo": [],
2365+
},
2366+
},
2367+
}
2368+
)
2369+
root = poetry.package.with_dependency_groups([], only=True)
2370+
root.python_versions = "^3.6"
2371+
root.add_dependency(
2372+
Factory.create_dependency(
2373+
name="foo",
2374+
constraint={
2375+
"url": "https://example.com/foo-linux.whl",
2376+
"platform": "linux",
2377+
},
2378+
)
2379+
)
2380+
root.add_dependency(
2381+
Factory.create_dependency(
2382+
name="foo",
2383+
constraint={
2384+
"url": "https://example.com/foo-darwin.whl",
2385+
"platform": "darwin",
2386+
},
2387+
)
2388+
)
2389+
poetry._package = root
2390+
2391+
io = BufferedIO()
2392+
exporter = Exporter(poetry)
2393+
exporter.export("requirements.txt", Path(tmp_dir), io)
2394+
2395+
expected = f"""\
2396+
foo @ https://example.com/foo-darwin.whl ; {MARKER_PY36} and {MARKER_DARWIN}
2397+
foo @ https://example.com/foo-linux.whl ; {MARKER_PY36} and {MARKER_LINUX}
2398+
"""
2399+
2400+
assert io.fetch_output() == expected

0 commit comments

Comments
 (0)