If I want to develop a Python package which works only in Linux and macOS. How do I specify this restriction in Python Poetry?
-
Could you share your `pyproject.toml` file? – Sabil Aug 24 '21 at 05:52
-
Sure! https://gitlab.com/JoD/exact/-/blob/master/python/pyproject.toml – HolKann Aug 25 '21 at 11:39
2 Answers
Trove classifiers in the pyproject.toml
file can be used to specify which operating systems are supported. For Linux and MacOS this would be:
[tool.poetry]
classifiers = [
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux"
]
This will however not prevent poetry from attempting to install the package on other platforms when the poetry install
command is used. Support for platform-specific wheel tags has been suggested in GitHub issue #2051, which is on the to do list for poetry's 1.2 release at the time of writing.
To specify which platforms to install the package on as a dependency of another poetry project, environment markers can be used:
[tool.poetry.dependencies]
yourpackage = {version = "*", markers = "sys_platform == 'linux' or sys_platform == 'darwin'"}
Poetry will then ignore yourpackage
when poetry install
is used on other platforms, but not give any errors. If it is a hard dependency, it would therefore be better to indicate elsewhere which platforms are supported.

- 2,534
- 1
- 15
- 22
In the documentation here, they mention environment markers are supported, you could use the sys_platform
marker.

- 532
- 1
- 5
- 14
-
Interesting, I missed that. So now I've added two lines to the `pyproject.toml` file of the package: ``` [tool.poetry.dependencies] ... sys_platform = "linux" platform_machine = "x86_64" ``` and ran `poetry build`. However, the resulting wheel name still is `package-version-py3-none-any.whl` instead of the expected `package-version-py3-linux-x86_64.whl`. I'm not quite getting the hang of it yet... – HolKann Aug 25 '21 at 11:35
-
I do not know if this would work but try this, `[tool.poetry.dependencies] python = {version="^3.7", markers="sys_platform=='linux'"}` – Sujal Singh Aug 25 '21 at 13:31
-
Hmm, yeah, using `[tool.poetry.dependencies] cppyy = {version="^2.1.0", markers="sys_platform=='linux'"}` compiles, but does not change the `none-any.whl`. I also have the feeling this changes the platform constraints of the dependency of the package, rather than the platform constraints of the package itself. – HolKann Aug 25 '21 at 15:33