Skip to content

[BUG] requires-python invalid value - pyproject.toml #21335

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

Open
srydz-aiclearing opened this issue May 27, 2025 · 5 comments · May be fixed by #21402
Open

[BUG] requires-python invalid value - pyproject.toml #21335

srydz-aiclearing opened this issue May 27, 2025 · 5 comments · May be fixed by #21402

Comments

@srydz-aiclearing
Copy link

Description

This commit breaks our pipelines where we are using openapitools/openapi-generator-cli:latest image to generate some artifacts and later build package (Sorry for watered-down issue details, I don't have time)

openapi-generator version

docker image latest

Error we get:
configuration error: `project.requires-python` must be pep508-versionspec
DESCRIPTION:
    `The Python version requirements of the project
    <https://packaging.python.org/specifications/core-metadata/#requires-
    python>`_.
GIVEN VALUE:
    "^3.9"
OFFENDING RULE: 'format'
DEFINITION:
    {
        "type": "string",
        "format": "pep508-versionspec"
    }
For more details about `format` see
https://validate-pyproject.readthedocs.io/en/latest/api/validate_pyproject.formats.html
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "/usr/local/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
    json_out["return_val"] = hook(**hook_input["kwargs"])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 317, in get_requires_for_build_sdist
    return hook(config_settings)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-2ecltzhr/lib/python3.11/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_sdist
    return self._get_build_requires(config_settings, requirements=[])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-2ecltzhr/lib/python3.11/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires
    self.run_setup()
  File "/tmp/build-env-2ecltzhr/lib/python3.11/site-packages/setuptools/build_meta.py", line 317, in run_setup
    exec(code, locals())
  File "<string>", line 35, in <module>
  File "/tmp/build-env-2ecltzhr/lib/python3.11/site-packages/setuptools/__init__.py", line 115, in setup
    return distutils.core.setup(**attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-2ecltzhr/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 160, in setup
    dist.parse_config_files()
  File "/tmp/build-env-2ecltzhr/lib/python3.11/site-packages/setuptools/dist.py", line 756, in parse_config_files
    pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
  File "/tmp/build-env-2ecltzhr/lib/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 72, in apply_configuration
    config = read_configuration(filepath, True, ignore_option_errors, dist)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-2ecltzhr/lib/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 140, in read_configuration
    validate(subset, filepath)
  File "/tmp/build-env-2ecltzhr/lib/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 61, in validate
    raise ValueError(f"{error}\n{summary}") from None
ValueError: invalid pyproject.toml config: `project.requires-python`.
configuration error: `project.requires-python` must be pep508-versionspec
Steps to reproduce

try building package from artifacts with python>= 3.11?

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/21268/files#diff-1f30eb8ed63b755ee7e2bdee645631802bee0f57d71e8650dcde554dd91a3368R46

Suggest a fix

change syntax

@wing328
Copy link
Member

wing328 commented May 30, 2025

@srydz-aiclearing thanks for reporting the issue

did try setting the option poetry1 to true for fallback?

cc @4c0n

@4c0n
Copy link
Contributor

4c0n commented May 30, 2025

Ah right I guess Poetry is ok with that syntax, but other tools may not be.
I validated the situation using poetry check, which claims that it's all good.
Sorry about that!

I guess we could change "^3.9" to ">3.8", which does not mean the same, but won't be a problem until Python 4.0. Or go for ">3.8,<4".

Which constraint would you prefer?

Also, yes for now you could use the "poetry1" fallback or the previous version of the generator as a workaround.

@adsmith144
Copy link

adsmith144 commented Jun 5, 2025

We experienced the same issue with the caret (^) notation within an openapi-generator created package, which we attributed to setuptools ≥ 80 (released 26 May 2025) which enforces strict PEP508. Error in build:

Step #1 - "build image": Step 13/18 : RUN pip install --no-cache-dir ./project_name
Step #1 - "build image":  ---> Running in 707f63326e01
Step #1 - "build image": Processing ./project_name
Step #1 - "build image":   Installing build dependencies: started
Step #1 - "build image":   Installing build dependencies: finished with status 'done'
Step #1 - "build image":   Getting requirements to build wheel: started
Step #1 - "build image":   Getting requirements to build wheel: finished with status 'error'
Step #1 - "build image":   error: subprocess-exited-with-error
Step #1 - "build image":   
Step #1 - "build image":   × Getting requirements to build wheel did not run successfully.
Step #1 - "build image":   │ exit code: 1
Step #1 - "build image":   ╰─> [53 lines of output]
Step #1 - "build image":       configuration error: `project.requires-python` must be pep508-versionspec
Step #1 - "build image":       DESCRIPTION:
Step #1 - "build image":           `The Python version requirements of the project
Step #1 - "build image":           <https://packaging.python.org/specifications/core-metadata/#requires-
Step #1 - "build image":           python>`_.
Step #1 - "build image":       
Step #1 - "build image":       GIVEN VALUE:
Step #1 - "build image":           "^3.9"
Step #1 - "build image":       
Step #1 - "build image":       OFFENDING RULE: 'format'
Step #1 - "build image":       
Step #1 - "build image":       DEFINITION:
Step #1 - "build image":           {
Step #1 - "build image":               "type": "string",
Step #1 - "build image":               "format": "pep508-versionspec"
Step #1 - "build image":           }
Step #1 - "build image":       
Step #1 - "build image":       For more details about `format` see
Step #1 - "build image":       https://validate-pyproject.readthedocs.io/en/latest/api/validate_pyproject.formats.html

We applied a quick/dirty patch in Dockerfile to replace '^' with '>=':

RUN sed -Ei 's/^[[:space:]]*requires-python[[:space:]]*=[[:space:]]*"\^/requires-python = ">=/' \
        project_name/pyproject.toml

We also encountered a closely related issue with project license name, also attributed to setuptools ≥ 80, which is now validating every PEP-621 field:

Step #1 - "build image":       configuration error: `project.license` must be valid exactly by one definition (0 matches found):
Step #1 - "build image":       
Step #1 - "build image":           - {type: string, format: 'SPDX'}
Step #1 - "build image":           - type: table
Step #1 - "build image":             keys:
Step #1 - "build image":               'file': {type: string}
Step #1 - "build image":             required: ['file']
Step #1 - "build image":           - type: table
Step #1 - "build image":             keys:
Step #1 - "build image":               'text': {type: string}
Step #1 - "build image":             required: ['text']
Step #1 - "build image":       
Step #1 - "build image":       DESCRIPTION:
Step #1 - "build image":           `Project license <https://peps.python.org/pep-0621/#license>`_.
Step #1 - "build image":       
Step #1 - "build image":       GIVEN VALUE:
Step #1 - "build image":           "Apache 2.0"
Step #1 - "build image":       
Step #1 - "build image":       OFFENDING RULE: 'oneOf'
Step #1 - "build image":       
Step #1 - "build image":       DEFINITION:
Step #1 - "build image":           {
Step #1 - "build image":               "oneOf": [
Step #1 - "build image":                   {
Step #1 - "build image":                       "type": "string",
Step #1 - "build image":                       "description": "An SPDX license identifier",
Step #1 - "build image":                       "format": "SPDX"
Step #1 - "build image":                   },
Step #1 - "build image":                   {
Step #1 - "build image":                       "type": "object",
Step #1 - "build image":                       "properties": {
Step #1 - "build image":                           "file": {
Step #1 - "build image":                               "type": "string",
Step #1 - "build image":                               "$$description": [
Step #1 - "build image":                                   "Relative path to the file (UTF-8) which contains the license for the",
Step #1 - "build image":                                   "project."
Step #1 - "build image":                               ]
Step #1 - "build image":                           }
Step #1 - "build image":                       },
Step #1 - "build image":                       "required": [
Step #1 - "build image":                           "file"
Step #1 - "build image":                       ]
Step #1 - "build image":                   },
Step #1 - "build image":                   {
Step #1 - "build image":                       "type": "object",
Step #1 - "build image":                       "properties": {
Step #1 - "build image":                           "text": {
Step #1 - "build image":                               "type": "string",
Step #1 - "build image":                               "$$description": [
Step #1 - "build image":                                   "The license of the project whose meaning is that of the",
Step #1 - "build image":                                   "`License field from the core metadata",
Step #1 - "build image":                                   "<https://packaging.python.org/specifications/core-metadata/#license>`_."
Step #1 - "build image":                               ]
Step #1 - "build image":                           }
Step #1 - "build image":                       },

Again, temporarily patched in Dockerfile with

RUN sed -Ei 's/^[[:space:]]*license[[:space:]]*=[[:space:]]*"Apache 2\.0"/license = "Apache-2.0"/' \
        project_name/pyproject.toml

@4c0n
Copy link
Contributor

4c0n commented Jun 11, 2025

@adsmith144 The license name is taken from the openapi spec, that is where the problem lies. So if the openapi spec provides a valid SPDX identifier, all is well, if it isn't you might see a validation error, not sure what we could do to resolve that situation on the generator's end.

@4c0n
Copy link
Contributor

4c0n commented Jun 11, 2025

I made a PR to solve the issue with the python-version constraint: #21402
Please have a look and let me know if you have any comments or suggestions.

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