How do I pass command line arguments to setup.py with a pyproject.toml project?

0
6
Asked By CuriousCoder97 On

I'm working on a Python project that uses pyproject.toml, which is part of the PEP517 feature set. While this file often utilizes setuptools, I still rely on a setup.py file that includes arguments like --no-cuda. I'm trying to figure out how to pass these arguments to setup.py when my project is configured and built with pyproject.toml. Any insights would be appreciated!

5 Answers

Answered By DevGuru45 On

Instead of passing arguments to setup.py directly, consider making CUDA support optional dependencies. For instance, you could structure it like this: `pip install foo[cuda]`.

HelpfulHacker -

That's a great point! It makes it easier for users to install only the features they need.

Answered By SyntaxSavant On

Can you share an example of what you're trying to achieve? Generally, with a pyproject.toml, setup.py isn't even needed anymore, and using install-time CLI arguments isn't recommended since they can be tough to access via package managers.

Answered By AntiSetupGuy On

You might just want to stop using setup.py altogether. It's quite outdated.

Answered By ConfigWizard On

Have you thought about using a config.yaml file instead? Users could easily edit the YAML file to toggle settings like this. The PyYAML library makes loading it into your scripts super simple! For example:
```yaml
# config.yaml

use_cuda: true
```
And then in your Python script, you can load it like this:
```python
import yaml

config_path = 'path/to/config.yaml'

with open(config_path, 'r') as file:
config_dict = yaml.safe_load(file)

use_cuda = config['use_cuda']
...```

Answered By NextGenDev On

Are you really looking to pass CLI arguments to setup.py, or do you actually want to send CLI args to your app's entry point when it's executing?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.