Skip to content

Setup is not working - package name?  #492

Description

@Leem0sh

Describe the bug
Unable to import client even after successful generation with setup

To Reproduce

Having a dir
-openapi-gen (ROOT)
--schemas
----dimensions.json

Steps to reproduce the behavior:
Created new env with conda conda create --name Generators python==3.9.6
conda activate Generators
pip install openapi-python-client
openapi-python-client generate --meta setup --path schemas/dimensionsService.json
Generates dimensions-service-client

openapi-gen directory has now 2 directories - schemas + dimensions-service-client

cd dimensions-service-client
pip install .

Client is successfully installed.

But now I have a problem. In Pycharm I see that lib is installed, but in site-packages is only ....dist-info directory and not any other dir with api, models etc. THEN I noticed that api and models directories are directly inside the site-packages and not inside its own directory.

pycharm-dims

pycharm-dims-ext

Expected behavior
Expected to have it's own directory so I can just use import dimensions_service_client and not import api (not mentioning that I'm not able to initiate the Client)

The issue is probably connected with package name inside setup.py?

OpenAPI Spec File
Any

Desktop (please complete the following information):

  • OS: Win10
  • Python Version: 3.9.6
  • openapi-python-client version 0.1.0

Activity

  1. changed the title [-]Setup issue - package name? [/-] [+]Setup is not working - package name? [/+] on Sep 15, 2021
  2. added this to the 0.10.5 milestone on Sep 25, 2021
  3. dbanty commented on Sep 26, 2021

    @dbanty
    Collaborator

    @Leem0sh I'm not able to reproduce this on macOS with Python 3.9.7 (no conda) and the latest openapi-python-client 0.10.4. Here's what I did:

    1. openapi-python-client generate --path end_to_end_tests/openapi.json --meta setup (so just using the spec we use for end to end tests)
    2. cd my-test-api-client
    3. python3 -m venv .venv
    4. source .venv/bin/activate
    5. pip install .
    6. python
    7. >>> from my_test_api_client import Client, models, api

    No errors. I'm not familiar with conda at all, does it require something special in the setup.py? Or maybe this is a Windows thing? I'm really not sure.

    Would you be able to tinker with the setup.py file and see what it takes to get it working?

    BTW my pip version in the generated virtual environment is 21.2.4.

    Thanks!

  4. modified the milestones: 0.10.5, 0.10.6 on Sep 26, 2021
  5. dbanty commented on Oct 12, 2021

    @dbanty
    Collaborator

    @Leem0sh is there any update on this? I'm hoping to sweep up most of the open bugs this weekend.

  6. Leem0sh commented on Oct 13, 2021

    @Leem0sh
    Author

    Hey @dbanty!

    So we were just debugging the issue with my colleague a bit and found out that your example is working, but only bcs you are using python and importing the library with relative pathing. If you'd go into different directory, the import wouldn't be working.

    Issue is with using package_dir and find_pakage(where=...)

    We tried code below and it was working nicely. What do you think?

    import pathlib
    
    from setuptools import find_packages, setup
    
    here = pathlib.Path(__file__).parent.resolve()
    long_description = (here / "README.md").read_text(encoding="utf-8")
    
    setup(
        name="<service_name>",
        version="0.3.0",
        description="A client library for accessing <service_name>",
        long_description=long_description,
        long_description_content_type="text/markdown",
        packages=find_packages(),
        python_requires=">=3.6, <4",
        install_requires=["httpx >= 0.15.0, < 0.19.0", "attrs >= 20.1.0, < 22.0.0", "python-dateutil >= 2.8.0, < 3"],
        package_data={"": ["CHANGELOG.md"], "<service_name>": ["py.typed"]},
    

    Basically in your solution - after creating a wheel file with python setup.py bdist_wheel and extracting the dist/<wheel_file.WHL>, you can find 3 dirs (image).
    snipp

    When you try our solution, you are getting 2 dirs (the ones, you should get)
    snip

    and inside, the client dir, you have all the modules.
    snippp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions