poetry: Picking wrong platform installing a dependency with multiple constraints
- I am on the 1.0.5 Poetry version.
- I have searched the issues of this repo and believe that this is not a duplicate.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option).
- OS version and name: Ubuntu 18.04
- Poetry version: 1.0.5
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/leon19/42bf22ddc791e0500c614d461c32a486
Issue
Markers are not working properly with multiple constraints dependencies as stated in the docs
I am trying to install a dependency from an URL based on the platform, different URLs for every platform (markers = "sys_platform == 'linux'"
) and poetry is picking the URL from the platform darwin
when I’m under a linux
platform
I have not tested yet what happens on a Darwin platform. Will update the issue when I do
Update:
If I reverse the order of the dependencies, the first line the darwin url, it works on Linux. The same behaviour applies on Darwin
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 29 (4 by maintainers)
I tried several combinations and none worked. Among the things I tried were the following things:
I tried both and similar variations of the two above with poetry 1.1.0, 1.1.1, 1.1.2, 1.1.3 and 1.1.4
In all cases, the first entry was always used no matter what platform I was on. So on Linux it downloaded the windows wheel. And On Windows, if you changed the order, it took the instructions for linux / mac os.
Could be clarified how exactly this should work and with what poetry versions in specific. So far it failed with all versions, so I’m slightly confused why this issue has been marked as resolved.
@leon19 try chaging it to the following (this is only a partial workaround - see below).
This will work if you are on a linux environment. I did notice that the generated lockfile will only contain the first specified url (in this case command will succeed since I was working on a linux machine and linux platform was specified first). If I were to change the order, it will fail again. However, when building the wheel generated the correct metadata.
From what I can tell, when
markers
are explicitly used the constraints get populated differently.Issue 1: This pertains to the use of “url”. When duplicate dependencies are being merged, url and markers are ignored resulting in only the first entry to be used (in this case the linux url). Ideally, the dependency graph should be branched due to the existance of the platform marker and the url should be considered when merging duplicates.
Additionally, during investigation, I had a quick look at how this was being processed. It did raise a few questions (which might be separate issue(s) to be dealt with).
When markers are explicitly provided (eg:
markers = "sys_platform == 'win32'", python = ">=3.6"
);Issue 2: the python version specified is ignored if
markers
are explicitly specified (unsure if this is expected behaviour). https://github.com/python-poetry/poetry/blob/ae6d64ded40bea9019f7e1de229cd0b360d65e70/poetry/packages/package.py#L349-L359Issue 3: sole use of markers causes solver to be stuck in an infinite loop. As an example, this works.
However, this causes an infinite loop.
@finswimmer would be good to get your thoughts on the above.
I have a similar problem.
python-ldap
package won’t build on Windows, so I have to use an unofficial wheel file. I wanted to tell Poetry that it should use the official package for Linux and the locally stored wheel for Windows:but, judging from the
poetry.lock
file, it seems markers are then merged and just determine whether the library should be installed at all:I’ve also asked a question on StackOverflow.
It looks like this may have regressed in 1.1.4
Now poetry 1.6.1 I still failed to handle different platform versions of torch with poetry.
poetry has a good conception but finally I have to give up using it in platform sensetive projects.
@finswimmer I’m running poetry 1.1.6, and it appears to still have problems resolving multiple constraints dependencies.
Here’s my dependencies spec:
Given the above, when I run
poetry install
on a Mac, it goes for the Linux wheel instead of the vanillatorch
version:Thoughts?
@abn or @eterna2 any new findings or workarounds for this issue?
I am encountering the same behavior using multiple constraints for a package using git and path dependencies based on platform.
The
poetry export -f requirements.txt
command seems to generate the requirements in the following way: given multiple constraints, poetry will simply use the first entry in the list as the sole dependency and attach any constraints/markers onto it via a union (markers separated by “or”) This means that regardless of if the given constraints should conflict (which is the intention of the different constraints), it will simply install the first listed dependency if it meets any of the given constraints.From my understanding, this is not the expected behavior, as multiple constraints dependencies are meant to allow for defining different locations for retrieving a given dependency.
@sinoroc I ran:
Here’s an excerpt from my
pyproject.toml
:I received a requirements list with flags like this:
When attempting to pip install this, I get: