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

Fixed string list concatenation error #2876

Merged
merged 5 commits into from
Feb 12, 2022
Merged

Fixed string list concatenation error #2876

merged 5 commits into from
Feb 12, 2022

Conversation

gentlegiantJGC
Copy link
Contributor

I am using build to build my project and want to pass custom settings into the setup.py file.

The suggested way is to use the config-setting flag chained with your global-option flag however this errors if only one global option is defined because they pass it in as a string not a list of strings.

Your code tries concatenating a list of strings with a single string which causes an error.

Summary of changes

If config_settings["--global-option"] is a string wrap it in a list

@jaraco
Copy link
Member

jaraco commented Nov 13, 2021

Can you provide an example of what usage results in a list and what usage results in a string, and what commands you run to get that behavior? Does setuptools need to accept both forms (list and string)? I believe the global-option is poorly-defined, so this might be a good time to evaluate a better way for Setuptools to solicit configuration.

In any case, it would also be nice to have a test for the desired behavior to capture that it's required and why.

@gentlegiantJGC
Copy link
Contributor Author

This command does not work
python -m build -C--global-option=--find-libs=True

This command does work
python -m build -C--global-option=--find-libs=True -C--global-option=--find-libs=True

I am using the --config-setting argument in build (-C for short) which is parsing the command into a dictionary.

In the first case that is

{
    "--global-option": "--find-libs=True"
}

and in the second case is

{
    "--global-option": [
        "--find-libs=True",
        "--find-libs=True"
    ]
}

If it finds the same argument more than once it will convert it to a list and append subsequent values.

That dictionary gets passed onto setuptools where it pulls out the --global-option value which assumes it is a list. That is where the error happens.
https://github.com/pypa/setuptools/blob/main/setuptools/build_meta.py#L213

@jaraco
Copy link
Member

jaraco commented Nov 18, 2021

My god, that syntax is atrocious (-C--global-option=--find-libs=True). Do we know where --global-option is defined outside of the setuptools implementation?

@gentlegiantJGC
Copy link
Contributor Author

gentlegiantJGC commented Nov 18, 2021

Yeh it isn't great.
Build just takes all the config settings and feeds them to the build system (in this case setuptools). They don't have a flag just for global option because I think that is a thing implemented by setuptools and they work with other build systems afaik.

Build parses the --config-setting here https://github.com/pypa/build/blob/main/src/build/__main__.py#L346
Setuptools parses the --global-option here https://github.com/pypa/setuptools/blob/main/setuptools/build_meta.py#L213

Edit:
Setuptools passes the global option values onto the build command so it must be a sequence of strings at that point.
The question is if you would be open to supporting a single string as input and converting it to the correct format.

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

Successfully merging this pull request may close these issues.

None yet

2 participants