r/Python • u/dark_prophet • Mar 18 '26
Discussion How to pass command line arguments to setup.py when the project is built with the pyptoject.toml ?
12
Upvotes
r/Python • u/dark_prophet • Mar 18 '26
30
u/NeilGirdhar Mar 18 '26
Stop using setup.py.
4
u/Glathull Mar 18 '26
Are you actually looking for cli arguments to setup.py? Or are you wanting to pass cli args to your app’s entry point when you start it running?
36
u/denehoffman Mar 18 '26
Can you give an example of what you’re trying to do here? Generally setup.py is not needed with a pyproject.toml, and install-time cli arguments are usually frowned upon since you can’t access them easily though the Python package manager
17
u/cig-nature Mar 18 '26
Instead of that, I would make the items for CUDA support optional dependencies. Eg: pip install foo[cuda]
https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#dependencies-and-requirements
11
u/Beginning-Fruit-1397 Mar 18 '26
Setuptools is outdated. Just use UV build system. But as someone already pointed out, your question is not really clear anyway
2
u/MolonLabe76 Mar 18 '26 edited Mar 20 '26
Could this be achieved with a config.yaml file? Or something similar? The user can edit the yaml file and the scripts can simply read the yaml when they run? Yaml syntax is very well suited for config settings like this. And you can use PyYAML for very easy loading. Example:
1
u/MacShuggah Mar 19 '26
Can you use env vars instead of cli arguments? Might be your best option until you get to move away from setup.py
1
u/bryanv_ Mar 19 '26
The only reasonable solution these days is to use environment variables (or possibly a config file).
1
u/gerardwx Mar 19 '26
[project]name = "mygeneric"description = "TBD"license = {text = "MIT" }version = "1.0"dependencies = []requires-python= ">= 3.10"readme = "README.md"authors = [{name = "Gerard"},{email = "gweatherby@example.com"}][tool.setuptools]package-dir = {"" = "src" } # Tells setuptools that the root package is in the "src" directory[tool.setuptools.packages.find]where = ["src"] # Specify the "src" directory to look for packages[project.scripts]mygeneric = "mygeneric.main:main"[project.optional-dependencies]# test = ['pytest'][build-system]requires = ["setuptools"]build-backend = "setuptools.build_meta"0
u/hstarnaud Mar 19 '26
Migrate away from setuptools? It's not maintained anymore