Skip to content

Environment markers with different sources for a dependency #7300

@joshuataylor

Description

@joshuataylor

Issue

I'm trying to use two different sources in Poetry for a dependency using markers:

  1. Apple Silicon markers="sys_platform == 'darwin' and platform_machine == 'arm64'"
  2. Fallback (markers="sys_platform != 'darwin' and platform_machine != 'arm64'")

This is because I'm hosting wheels on a source for Apple Silicon, and want to fallback to PyPI for everything else. grpcio for example does not provide wheels for Apple Silicon, so I'm hosting them on a soon-to-be public source (though you can use it now if you want :-)).

If I have a custom mirror for a marker, let's call it "pythonbuild", then can I fall back to PyPI for the other marker, is this supported in Poetry?

Example:

grpcio = [
   {version="==1.47.2", markers="sys_platform != 'darwin' and platform_machine != 'arm64'", source="pypi"},
   {version="==1.47.2", markers="sys_platform == 'darwin' and platform_machine == 'arm64'", source="pythonbuild"},
]

Doing a poetry update -vvv on MacOS ARM64 (using Poetry from master, as of 2022-01-05, commit ef89e90fc1305e07a62e9e715c91a66c8d7425f7), I get the following output (Gist).

Doing this builds the following lock file: lockfile.

During the update process this works, as it looks at the markers and uses the correct source for the dependency, but when I try to install the lock file, it installs from pypi, as that's listed higher in the lock file. That's how it should work in theory, but there should be a way to tell the lockfile which source to use for a dependency.

You can see an example project here that you can use: https://github.com/kilnbuild/pythonbuild_examples/tree/main/poetry (use poetry install on MacOS ARM64 (Apple Silicon, M1/M2 whatever buzzword Apple is using now) to see the issue).

I've read through the following issues:

#5205
#6710

And this PR:
#6679

And my source looks like this:

[[tool.poetry.source]]
name = "pythonbuild"
url = "https://python.build/simple/"
# tried with true/false for secondary, same result.
default = false
secondary = false

Before each step, I ensure that I'm starting with a clean environment:

rm -rf ~/Library/Caches/pypoetry .venv poetry.lock

I can verify the wheel is being used when using poetry update:

cat .venv/lib/python3.10/site-packages/grpcio-1.47.2.dist-info/WHEEL

Shows

Wheel-Version: 1.0
Generator: bdist_wheel (0.38.4)
Root-Is-Purelib: false
Tag: cp310-cp310-macosx_11_0_arm64

So I should be able to run poetry install now, and have the same results, using the lock file..

rm -rf ~/Library/Caches/pypoetry .venv

I can see via network monitoring, it hits https://pypi.org/pypi/grpcio/1.47.2/json for both the update + install, but during the update it downloads from https://wheels.python.build/grpcio-1.47.2-cp310-cp310-macosx_11_0_arm64.whl, where as during the install it does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions