Allow multiple lockfiles targeting different platforms
Now that we have #1898, it could be interesting to have platform-specific lockfiles, each generated by something like --no-cross-platform.
My primary use case for this is pytorch: ideally, you would get different results depending on your platform: the CUDA version on Linux and the MPS version on macOS. As it stands, I'm getting the CPU version on Linux if I use the lockfile generated on macOS.
My current solution is not to commit the lockfile and let PDM figure it out every time I do a pdm install. Instead, if we have multiple lockfiles, I could generate specific ones for each platform I support.
The UX for this could be something like this:
- Manual: new flag
--lockfile <file>that creates a lockfile in pathfileif it doesn't exist or uses it to install dependencies. This would be required for everypdm install. - Supply once, use it always:
pdm installneeds the argument once per instance, but after that, you don't need to specify it anymore - Automated: when using
--no-cross-platform, the lockfile generated encodes the platform in its name, andpdm installwould automatically use that if it exists, prioritising it over other lockfiles.
Isn't the more obvious to add package based on the platform:
pdm add "pytorch; sys_platform==\"Darwin\""
Another solution is to just do:
On linux:
pdm add pytorch --lockfile pdm-linux.lock
On macos:
pdm add pytorch --lockfile pdm-macos.lock
I will add that this can be easily automated as lockfile is on default set to this:
Specify another lockfile path. Default: pdm.lock. [env var: PDM_LOCKFILE]
So well specify PDM_LOCKFILE on macos to something different, on linux to something different and you are set.
Resolved by #2995