cloudstateio / python-support

User Language Support for Python
Apache License 2.0
7 stars 5 forks source link

start shopping_cart.py on local development #23

Closed marcellanz closed 4 years ago

marcellanz commented 4 years ago

I can't to get shopping_cart.py or ./tck.sh running out of the box on macOS with a fresh cloned repository, but found a way to do it. I setup a virtual environment to get not interfered with potential earlier dependencies installed.

What I did This is my command history in a fresh directory:

> git clone https://github.com/cloudstateio/python-support.git
Cloning into 'python-support'...
remote: Enumerating objects: 237, done.
remote: Counting objects: 100% (237/237), done.
remote: Compressing objects: 100% (135/135), done.
remote: Total 237 (delta 105), reused 203 (delta 76), pack-reused 0
Receiving objects: 100% (237/237), 85.49 KiB | 818.00 KiB/s, done.
Resolving deltas: 100% (105/105), done.
> cd python-support
> python3 -m venv ./venv 
> source ./venv/bin/activate
> python --version     
Python 3.7.3
> pip --version 
pip 19.0.3 from /Users/lanzm/tmp/python-support/venv/lib/python3.7/site-packages/pip (python 3.7)

> pip install . 
Successfully installed appier-1.19.16 attrs-19.3.0 cloudstate-0.5.0 google-api-0.1.12 grpcio-1.28.1 grpcio-tools-1.28.1 protobuf-3.11.3 six-1.14.0
> export PYTHONPATH=`pwd`

then I try to start the shopping cart:

> python shoppingcart/shopping_cart.py
Traceback (most recent call last):
  File "shoppingcart/shopping_cart.py", line 2, in <module>
    from shoppingcart.shopping_cart_entity import entity as shopping_cart_entity
  File "/Users/lanzm/tmp/python-support/shoppingcart/shopping_cart_entity.py", line 9, in <module>
    from shoppingcart.shoppingcart_pb2 import (Cart, LineItem, AddLineItem, RemoveLineItem)
  File "/Users/lanzm/tmp/python-support/shoppingcart/shoppingcart_pb2.py", line 18, in <module>
    from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2
ModuleNotFoundError: No module named 'google.api'
>
> pip install googleapis-common-protos
Successfully installed googleapis-common-protos-1.51.0
>
> python shoppingcart/shopping_cart.py
Traceback (most recent call last):
  File "shoppingcart/shopping_cart.py", line 7, in <module>
    CloudState().register_event_sourced_entity(shopping_cart_entity).serve()
AttributeError: 'CloudState' object has no attribute 'serve'

Then replace `.serve()

if __name__ == '__main__':
    logging.basicConfig()
    CloudState().register_event_sourced_entity(shopping_cart_entity).serve()

with .start():

    CloudState().register_event_sourced_entity(shopping_cart_entity).start()

and this gets me the shopping cart started:

> python shoppingcart/shopping_cart.py
'Starting Cloudstate on 127.0.0.1:8080'

Suggested Fix

The module error ModuleNotFoundError: No module named 'google.api' shows that the *pb2.py file we have under python-support/google/api/ can't be found, but perhaps we even should not distribute by ourselfs so I installed them a a dependency with pip install googleapis-common-protos. We can add this dependency in general in setup.cfg I think.

sleipnir commented 4 years ago

Close this in #24