I’m working on a pure Python package that, for Technical Reasons™, needs to have one set of entry points on Unix systems, and a different set of entry points along with some helper scripts on Windows.
This would be easy enough to do if I just distributed an sdist with setuptools, but I also want to supply built wheels.
The solution I came up with has everything except the entry points specified in pyproject.toml
, and this in my setup.py
:
from setuptools import setup
from wheel.bdist_wheel import bdist_wheel as original_bdist_wheel
class bdist_wheel(original_bdist_wheel):
def run(self):
if self.plat_name.startswith("win"):
self.distribution.entry_points["console_scripts"].remove(
"cmd2 = my_pkg:cmd2"
)
self.distribution.entry_points["console_scripts"].append(
"windows_cmd = my_pkg:windows_cmd"
)
self.distribution.scripts = ["scripts/script1.bat", "scripts/script2.bat"]
super().run()
setup(
cmdclass={"bdist_wheel": bdist_wheel},
entry_points={
"console_scripts": [
"cmd1 = my_pkg:cmd1",
"cmd2 = my_pkg:cmd2",
]
},
)
Then to build my distributions, I can run one of these sets commands:
$ python setup.py sdist bdist_wheel
$ python setup.py bdist_wheel -p win32
$ python setup.py bdist_wheel -p win_amd64
$ python -m build
$ python -m build --wheel --config-setting=--build-option=--plat-name=win32
$ python -m build --wheel --config-setting=--build-option=--plat-name=win_amd64
Is this a good way to do this? Could it be better?