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

[BUG] setup.py incorrect using python or python-pydantic-v1 generators when no paths are specified #20090

Closed
2 tasks
loic-seguin opened this issue Nov 12, 2024 · 14 comments

Comments

@loic-seguin
Copy link
Contributor

loic-seguin commented Nov 12, 2024

Bug Report Checklist

  • [ x] Have you provided a full/minimal spec to reproduce the issue?
  • [ x] Have you validated the input using an OpenAPI validator (example)?
  • [ x] Have you tested with the latest master to confirm the issue still exists?
  • [ x] Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I generate a python client based on my really simple openapi.yaml.
But the setup.py that is generated does not contain the setup() method.
So it is not possible to import this library with poetry or pip.

openapi-generator version

7.9.0 but it seems to have the same issue on 7.0.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: RepositoryActions
  version: '1.0'
servers:
  - url: 'http://localhost:3000'
paths: {}
components:
  schemas:
    RepositoryActions:
      type: object
      properties:
        repository_url:
          type: string
        actions:
          type: array
          items:
            $ref: '#/components/schemas/CreateCommentAction'
    CreateCommentAction:
      type: object
      properties:
        text:
          type: string
Generation Details

openapi-generator-cli generate -i openapi.yaml -g python -o ./generated-python-client

Steps to reproduce

openapi-generator-cli generate -i openapi.yaml -g python -o ./generated-python-client

  • Create a new folder testpoetry at the same level of the folder that has been generated
  • Create a new file testpoetry/pyproject.toml with this content
[tool.poetry]
name = "poetrytest"
version = "0.1.0"
description = ""
authors = ["me"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
openapi-client = {path="../generated-python-client/"}

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Run the command 'poetry install'

You will get this error

poetry install
Updating dependencies
Resolving dependencies... (0.5s)

Package operations: 1 install, 0 updates, 0 removals

  - Installing openapi-client (1.0.0 /home/lseguin/Documents/github_describe_issue/generated-python-client): Failed

  ChefBuildError

  Backend subprocess exited when trying to invoke build_wheel
  
  Traceback (most recent call last):
    File "/home/lseguin/.local/share/pypoetry/venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
      main()
    File "/home/lseguin/.local/share/pypoetry/venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
      json_out["return_val"] = hook(**hook_input["kwargs"])
    File "/home/lseguin/.local/share/pypoetry/venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 280, in build_wheel
      return _build_backend().build_wheel(
    File "/tmp/tmp8o7fzmxu/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 435, in build_wheel
      return _build(['bdist_wheel'])
    File "/tmp/tmp8o7fzmxu/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 426, in _build
      return self._build_with_temp_dir(
    File "/tmp/tmp8o7fzmxu/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 409, in _build_with_temp_dir
      result_basename = _file_with_extension(tmp_dist_dir, result_extension)
    File "/tmp/tmp8o7fzmxu/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 128, in _file_with_extension
      raise ValueError(
  ValueError: No distribution was found. Ensure that `setup.py` is not empty and that it calls `setup()`.
  

  at ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/chef.py:164 in _prepare
      160│ 
      161│                 error = ChefBuildError("\n\n".join(message_parts))
      162│ 
      163│             if error is not None:
    → 164│                 raise error from None
      165│ 
      166│             return path
      167│ 
      168│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with openapi-client (1.0.0 /home/lseguin/Documents/github_describe_issue/generated-python-client) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "openapi-client @ file:///home/lseguin/Documents/github_describe_issue/generated-python-client"'.
Suggest a fix

The generation of the setup.py is incorrect, as it should call the setup method for me :

from setuptools import setup, find_packages

NAME = "openapi-client"
VERSION = "1.0.0"
PYTHON_REQUIRES = ">=3.7"
setup(name=NAME,version=VERSION,python_requires=PYTHON_REQUIRES)

This file does not seem to be used properly ->

@loic-seguin loic-seguin changed the title [BUG] Description [BUG] setup.py incorrect using python or python-pydantic-v1 generators Nov 12, 2024
@loic-seguin
Copy link
Contributor Author

loic-seguin commented Nov 13, 2024

I have found the problem I think, the paths property is not present in my openapi.yaml because I don't need any APIs for now. I just need the models to be generated. It should also work without paths property in the yaml. Trying to fix the problem in a PR.

@loic-seguin loic-seguin changed the title [BUG] setup.py incorrect using python or python-pydantic-v1 generators [BUG] setup.py incorrect using python or python-pydantic-v1 generators when no paths are specified Nov 13, 2024
@wing328
Copy link
Member

wing328 commented Nov 16, 2024

thanks for providing the steps to reproduce the issue but I couldn't repeat it as poetry install works fine for me

i'm using Poetry (version 1.8.4).

Updating dependencies
Resolving dependencies... (5.7s)

Package operations: 31 installs, 0 updates, 0 removals

  - Installing distlib (0.3.9)
  - Installing exceptiongroup (1.2.2)
  - Installing filelock (3.16.1)
  - Installing iniconfig (2.0.0)
  - Installing packaging (24.2)
  - Installing platformdirs (4.3.6)
  - Installing pluggy (1.5.0)
  - Installing tomli (2.1.0)
  - Installing typing-extensions (4.12.2)
  - Installing annotated-types (0.7.0)
  - Installing cachetools (5.5.0)
  - Installing chardet (5.2.0)
  - Installing colorama (0.4.6)
  - Installing coverage (7.6.1)
  - Installing mccabe (0.7.0)
  - Installing mypy-extensions (1.0.0)
  - Installing pycodestyle (2.9.1)
  - Installing pydantic-core (2.23.4)
  - Installing pyflakes (2.5.0)
  - Installing pyproject-api (1.8.0)
  - Installing pytest (8.3.3)
  - Installing six (1.16.0)
  - Installing virtualenv (20.27.1)
  - Installing flake8 (5.0.4)
  - Installing mypy (1.13.0)
  - Installing pydantic (2.9.2)
  - Installing pytest-cov (5.0.0)
  - Installing python-dateutil (2.9.0.post0)
  - Installing tox (4.23.2)
  - Installing types-python-dateutil (2.9.0.20241003)
  - Installing urllib3 (2.2.3)

Writing lock file

Installing the current project: openapi_client (1.0.0)

@loic-seguin
Copy link
Contributor Author

Could you print out your testpoetry/pyproject.toml please.
I don't see in your log thé dependency to your python client generated by openApi

@wing328
Copy link
Member

wing328 commented Nov 16, 2024

wing328@MSI /tmp/python23 % cat testpoetry/pyproject.toml
[tool.poetry]
name = "poetrytest"
version = "0.1.0"
description = ""
authors = ["me"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
openapi-client = {path="../generated-python-client/"}

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

@loic-seguin
Copy link
Contributor Author

Could you show me your openapi.yaml
I will send you the version of my poetry install

@wing328
Copy link
Member

wing328 commented Nov 16, 2024

i used the one you provided above:

openapi: 3.0.0
info:
  title: RepositoryActions
  version: '1.0'
servers:
  - url: 'http://localhost:3000'
paths: {}
components:
  schemas:
    RepositoryActions:
      type: object
      properties:
        repository_url:
          type: string
        actions:
          type: array
          items:
            $ref: '#/components/schemas/CreateCommentAction'
    CreateCommentAction:
      type: object
      properties:
        text:
          type: string

did you test it in another machine or environment to see if the issue is caused by something else?

@loic-seguin
Copy link
Contributor Author

Well, so I guess that the setup.py generated on your side contains the method setup right ?

@wing328
Copy link
Member

wing328 commented Nov 16, 2024

that's what i got

wing328@MSI /tmp/python23 % cat setup.py
# coding: utf-8

"""
    RepositoryActions

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from setuptools import setup, find_packages  # noqa: H301

# To install the library, run the following
#
# python setup.py install
#
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools
NAME = "openapi-client"
VERSION = "1.0.0"
PYTHON_REQUIRES = ">= 3.8"

@wing328
Copy link
Member

wing328 commented Nov 16, 2024

7.9.0 but it seems to have the same issue on 7.0.0

can you please give it another try with the latest master (which is what i used in this test)?

https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.10.0-SNAPSHOT/

@loic-seguin
Copy link
Contributor Author

Will try this on monday

@loic-seguin
Copy link
Contributor Author

Just sent you the tar.gz of my test.

issue_20090.tar.gz

My poetry version is 1.8.4.

I did the following commands :

tar -xzvf issue_20090.tar.gz
cd issue_20090/
wget https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.10.0-SNAPSHOT/openapi-generator-cli-7.10.0-20241118.101601-94.jar -O openapi-generator-cli.jar
java -jar openapi-generator-cli.jar generate -i openapi.yaml -g python -o ./generated-python-client
cd poetrytest
poetry install

I got the same log issue :

Package operations: 8 installs, 0 updates, 0 removals

  - Installing typing-extensions (4.12.2)
  - Installing annotated-types (0.7.0)
  - Installing pydantic-core (2.23.4)
  - Installing six (1.16.0)
  - Installing pydantic (2.9.2)
  - Installing python-dateutil (2.9.0.post0)
  - Installing urllib3 (2.2.3)
  - Installing openapi-client (1.0.0 /home/lseguin/Documents/issue_20090/generated-python-client): Failed

  ChefBuildError

  Backend subprocess exited when trying to invoke build_wheel
  
  Traceback (most recent call last):
    File "/home/lseguin/.local/share/pypoetry/venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
      main()
    File "/home/lseguin/.local/share/pypoetry/venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
      json_out["return_val"] = hook(**hook_input["kwargs"])
    File "/home/lseguin/.local/share/pypoetry/venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 280, in build_wheel
      return _build_backend().build_wheel(
    File "/tmp/tmpj8hl8kle/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 435, in build_wheel
      return _build(['bdist_wheel'])
    File "/tmp/tmpj8hl8kle/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 426, in _build
      return self._build_with_temp_dir(
    File "/tmp/tmpj8hl8kle/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 409, in _build_with_temp_dir
      result_basename = _file_with_extension(tmp_dist_dir, result_extension)
    File "/tmp/tmpj8hl8kle/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 128, in _file_with_extension
      raise ValueError(
  ValueError: No distribution was found. Ensure that `setup.py` is not empty and that it calls `setup()`.
  

  at ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/chef.py:164 in _prepare
      160│ 
      161│                 error = ChefBuildError("\n\n".join(message_parts))
      162│ 
      163│             if error is not None:
    → 164│                 raise error from None
      165│ 
      166│             return path
      167│ 
      168│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with openapi-client (1.0.0 /home/lseguin/Documents/issue_20090/generated-python-client) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "openapi-client @ file:///home/lseguin/Documents/issue_20090/generated-python-client"'.

@wing328
Copy link
Member

wing328 commented Nov 19, 2024

thanks for the info

did you test the fix (PR) locally (build the CLI JAR and test with the spec)?

@loic-seguin
Copy link
Contributor Author

Nope will do it asap

@loic-seguin
Copy link
Contributor Author

loic-seguin commented Nov 26, 2024

Ok done I have done these actions :

mvn clean install
cp modules/openapi-generator-cli/target/openapi-generator-cli.jar ~/issue_20090
cd ~/issue_20090
java -jar openapi-generator-cli.jar generate -i openapi.yaml -g python -o ./generated-python-client
cd poetrytest
poetry install

I got

Creating virtualenv poetrytest in /home/lseguin/issue_20090/poetrytest/.venv
Updating dependencies
Resolving dependencies... (1.7s)

Package operations: 8 installs, 0 updates, 0 removals

  - Installing typing-extensions (4.12.2)
  - Installing annotated-types (0.7.0)
  - Installing pydantic-core (2.27.1)
  - Installing six (1.16.0)
  - Installing pydantic (2.10.1)
  - Installing python-dateutil (2.9.0.post0)
  - Installing urllib3 (2.2.3)
  - Installing openapi-client (1.0.0 /home/lseguin/issue_20090/generated-python-client)

Writing lock file

Installing the current project: poetrytest (0.1.0)

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

No branches or pull requests

2 participants