Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use --config-setting to pass custom argument to setup.py #638

Open
LIONEFAN opened this issue Jul 4, 2023 · 1 comment
Open

How to use --config-setting to pass custom argument to setup.py #638

LIONEFAN opened this issue Jul 4, 2023 · 1 comment

Comments

@LIONEFAN
Copy link

LIONEFAN commented Jul 4, 2023

Before, I use this command to pass arguments to setup.py to modify the wheel name and version suffix flexibility.
python setup.py bdist_wheel --project_name my_test_project --weekly_build

And my setyp.py use the following codes.

if '--project_name' in sys.argv:
     project_name_idx = sys.argv.index('--project_name')
     project_name = sys.argv[project_name_idx + 1]
     sys.argv.remove('--project_name')
     sys.argv.pop(project_name_idx)

if "--weekly_build" in sys.argv:
        VERSION = _VERSION + ".dev"
        sys.argv.remove("--weekly_build")
        project_name = project_name+"weekly"

It warning that avoid running setup.py directly. So I want to use the command python -m build .
I find it has a flag "--config-setting", and I use the command
python -m build -w -n -C="--build-option=--project_name" -C="--build-option=test_project" refers to this issue

But I don't know how to modify the codes in setup.py to receive the argument "project_name".
Can you help me to solve it?

@henryiii
Copy link
Contributor

henryiii commented Jul 6, 2023

I think there are two ways. The most flexible is to add a custom backend, and process them there. This would allow any form of config setting, and not just ones prefixed by --build-option. But this seems heavy for this sort of thing. I'd say it's exactly the same concept, though, as processing sys.argv before. You'd have to figure out how to pass something through to setup.py this way, though. Possibly by transforming the option then using the built-in system mentioned below 🤦? Or with a global or similar. :/

The built-in way would be to add them via setuptools' option system. I believe you'd do this by overriding the build command with a custom one and adding an option (this is technically how you should be doing this now, too; I don't think you were ever supposed to process sys.argv yourself).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants