I’m interested in contributing to pydgraph (or creating a modified fork). For this I need to create a development environment and ensure that I can run tests. Where can I find instructions how to do it?
What you actually did
- cloned the repo
- created and activated a python virtual environment (
python3.8 -m venv venv). I’m using python3.8 because I’ve noticed that tox.ini file defines py38 environment
- within the virtual environment I run
python setup.py install(according to instructions in the Development section of README). There are some issues with this step.
- after resolving issues on previous step I installed
toxand tried to run it (according to instructions in the Running tests section of README). There are also some issues unless I keep modifications in
TL;DR: see the last screenshot (after “As a summary…”)
Why that wasn’t great, with examples
setup.py install fails with an error because it imports a
VERSION variable from the
pydgraph package, which also triggers imports from uninstalled dependencies (
$ python setup.py install Traceback (most recent call last): File "setup.py", line 23, in <module> from pydgraph.meta import VERSION File "/home/ulianich/projects/pydgraph/pydgraph/__init__.py", line 15, in <module> from pydgraph.proto.api_pb2 import Operation, Payload, Request, Response, Mutation, TxnContext,\ File "/home/ulianich/projects/pydgraph/pydgraph/proto/api_pb2.py", line 6, in <module> from google.protobuf import descriptor as _descriptor ModuleNotFoundError: No module named 'google'
As a workaround I could install dependencies either by running
pip install -r requirements.txt or by temporary replacing the problematic line in
# from pydgraph.meta import VERSION VERSION = '21.3.2'
But if I change setup.py back to its original state and run
setup.py install, the following error appears:
Traceback (most recent call last): File "setup.py", line 23, in <module> from pydgraph.meta import VERSION File "/home/ulianich/projects/pydgraph/pydgraph/__init__.py", line 15, in <module> from pydgraph.proto.api_pb2 import Operation, Payload, Request, Response, Mutation, TxnContext,\ File "/home/ulianich/projects/pydgraph/pydgraph/proto/api_pb2.py", line 34, in <module> _descriptor.EnumValueDescriptor( File "/home/ulianich/projects/pydgraph/venv/lib/python3.8/site-packages/protobuf-4.21.12-py3.8-linux-x86_64.egg/google/protobuf/descriptor.py", line 755, in __new__ _message.Message._CheckCalledFromGeneratedFile() TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are: 1. Downgrade the protobuf package to 3.20.x or lower. 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower). More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
According to the message installing an older version of protobuf does fix the issue:
pip install protobuf~=3.20. Is it supposed that pydgraph uses an older version of protobuf? Or should I set the PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION variable instead?
BTW, I’ve installed a pydgraph from pypi in a pure venv and the problem is reproduced in that case as well:
https://imgur.com/a/cCDGfdv (as a new user I cannot embed too may links or media)
tox (running tests)
tox fails to run with “ModuleNotFoundError” as well, so I keep
VERSION hard-coded in
setup.py and comment out the
from pydgraph.meta ... import line. There still is the same issue with “too new protobuf” in tox, so I’m replacing and pinning protobuf version in tox.ini:
# protobuf >= 3.6.1 protobuf == 3.20.3
After these changes
tox manages to run tests (tough my system hanged up at some point on the first try; I’m so happy that draft of this post was saved). Running tests screenshot:
https://imgur.com/a/qBMa2FV (cannot embed too many links or images)
As a summary, I could run tests only after applying these modifications:
So the question is: what is the “intended” way of working with (contributing to) the project? Is it possible to run tox without manually modifying setup.py?
Any external references to support your case
https://stackoverflow.com/a/2073599/7710928. Looks like setup.py does a bad thing by directly importing the pydgraph package (?)