Vonage / vonage-python-sdk

Vonage Server SDK for Python. API support for Voice, SMS, WhatsApp, Verify (2FA), Video Meetings and more.
https://developer.vonage.com
Apache License 2.0
187 stars 115 forks source link

When using vonage as dependency in submodules NCCO_Builder errors on import #239

Closed Zethtren closed 1 year ago

Zethtren commented 1 year ago

Expected Behavior

That using the example code would work when imported from within in a sub-module

Current Behavior

Traceback (most recent call last):
  File "C:\~\Documents\--\test.py", line 1, in <module>
    from my-module import SMSFrom
  File "C:\~\AppData\Local\Programs\Python\Python310\lib\site-packages\my-module\__init__.py", line 3, in <module>
    from .Messengers.SMS import SMSSender, SMSFrom
  File "C:\~\AppData\Local\Programs\Python\Python310\lib\site-packages\my-module\Messengers\SMS\__init__.py", line 1, in <module>
    from .sms import SMSFrom, SMSSender
  File "C:\~\AppData\Local\Programs\Python\Python310\lib\site-packages\my-module\Messengers\SMS\sms.py", line 5, in <module>
    import vonage
  File "C:\~\AppData\Local\Programs\Python\Python310\lib\site-packages\vonage\__init__.py", line 1, in <module>
    from .client import *
  File "C:\~\AppData\Local\Programs\Python\Python310\lib\site-packages\vonage\client.py", line 7, in <module>
    from .ncco_builder.ncco import Ncco, ConnectEndpoints, InputTypes, PayPrompts
ModuleNotFoundError: No module named 'vonage.ncco_builder'

Possible Solution

This code works perfectly fine on Linux. But not on Windows.
Potentially due to some kind of import optimizations.

Steps to Reproduce (for bugs)

  1. Run sample sms code successfully
  2. Wrap sample in module for other usage. Runs successfully on linux
  3. Install the module to Windows via pip install my-module
  4. import and use my-module which calls to vonage

Context

It is creating problems with multi-user development teams since we are all on different platforms.

Your Environment

Zethtren commented 1 year ago

Suggested fix add

from .ncco import *

to

https://github.com/Vonage/vonage-python-sdk/blob/main/src/vonage/ncco_builder/__init__.py

and

from .ncco_builder import *

to

https://github.com/Vonage/vonage-python-sdk/blob/main/src/vonage/__init__.py

The second one is the only one strictly needed to handle this error. The first import is simply being extra expicit

maxkahan commented 1 year ago

Hi, thanks for raising this. I will investigate and push a fix today.

maxkahan commented 1 year ago

Have made your suggested changes and released v3.2.2. You can install the new version with pip install --upgrade vonage. I made the first change too as I didn't like how we were importing it with the objects actually needed in the Client class.

Let me know if this helps!

Zethtren commented 1 year ago

Amazing! Thanks!

I am not at my computer right now but I will launch my dual boot in the morning and confirm!

Thanks for being so responsive!

I will run the upgrade and test tomorrow!

Zethtren commented 1 year ago

Confirmed successful run without import error. Thanks!

maxkahan commented 1 year ago

Great stuff, glad to hear. I'll close this now, but feel free to open an issue on here if you have any more issues. You can also join our community slack and ask questions there: https://developer.vonage.com/community/slack