peeringdb / peeringdb-py

PeeringDB python client
BSD 2-Clause "Simplified" License
89 stars 22 forks source link

Python3 support #13

Closed FliesLikeABrick closed 5 years ago

FliesLikeABrick commented 7 years ago

The peeringdb module fails import under python3 on all platforms tested so far (Cygwin, Ubuntu, MacOS)

import peeringdb Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.4/dist-packages/peeringdb/init.py", line 3, in from client import PeeringDB # noqa ImportError: No module named 'client'

I imagine the issues run deeper than this particular import issue, so this is a general request for Python3 support in peeringdb

scoulondre commented 7 years ago

I went through a lot of problems upgrading to the latest release. Probably because it relies on the latest versions of some packages, and previous versions of others... This is the full list of commands that work (I spent several hours trying different versions):

virtualenv venv --no-site-package
. venv/bin/activate
pip install --upgrade pip
pip install --upgrade setuptools
pip install peeringdb
peeringdb configure
pip install django==1.8.17 # It does not work with versions 1.9.12 and 1.10.5
pip install django-peeringdb
peeringdb sync

and hopefully you are done

jaredthecoder commented 7 years ago

I'm down to help here if needed.

grizz commented 7 years ago

@jaredthecoder patches are always welcome :)

esundberg commented 7 years ago

+1 for code update to Python3.0

joshniec commented 7 years ago

@grizz Unfortunately twentyc hasn't been updated for Python 3.

I was able to get peeringdb-py API to work with Python 3.6.1 by making a few changes to twentyc's code, and one small import change to init.py on peeringdb-py, however, this does break the cli functionality as I have not had time to go back and fix cli.py/anything else to work with Python 3.

For those that want to get the API functionality to work with Python 3, and do not mind breaking the cli functionality: Go to: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/twentyc/rpc

Go to: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peeringdb-py

I'll try submitting a pull request to twentyc, and if that package updates, perhaps peeringdb-py could start a branch for Python 3 and I can submit a pull request with some of the Python 3 changes for client.py & cli.py and anything else that needs updating.

grizz commented 7 years ago

@ironick09 a PR would be great, thanks.

loopodoopo commented 7 years ago

Looks like twentyc has been updated to version 0.4.0.1 to support python3 right? Am I correct that we need:

vegu commented 7 years ago

Alongside some fixes to the code in this repo (e.g the aforementioned imports), these are the requirements that would need to be updated for py3 support

facsimile/requirements.txt twentyc.rpc >= 0.4.0 munge >= 0.4.0

peeringdb/deps/requirements-mysql.txt django-peeringdb>=0.7.0

Also tox and travis configs would need to be updated to test py3 environments

EDIT: added munge

ericrochow commented 5 years ago

I submitted a PR (#23) to add python3 compatibility, but it's failing tox. If I can get some assistance with that then hopefully this can get pulled into master.

FliesLikeABrick commented 5 years ago

Looks like this is working on the latest master commit, however: django-peeringdb is missing from requirements.txt somewhere in the dependency chain, and peeringdb's init.py attempts to load it

File "/usr/lib/python3.6/site-packages/peeringdb/init.py", line 82, in initialize_backend supportmod = import_module(modname) File "/usr/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 941, in _find_and_load_unlocked File "", line 219, in _call_with_frames_removed File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 953, in _find_and_load_unlocked ModuleNotFoundError: No module named 'django_peeringdb'

@grizz is this just a matter of adding django-peeringdb to facsimile/requirements.txt, or is there logic somewhere that should not fail while trying to load this?

This may be the last item to resolve before closing this as python3 support being done (pending a release being cut)

vegu commented 5 years ago

There was substantial refactor for django-peeringdb as well as peeringdb-py that includes python3 support - django-peeringdb changes were released a bit ago, and i assume peeringdb-py will get a pypi release soon as well.

@FliesLikeABrick the new peeringdb-py client does not have a hard dependency on django-peeringdb anymore since there is hope that other backends will be implemented through the new abstraction interface, so you'd manually install it along side peeringdb as your chosen backend.

However it does look for django-peeringdb as the default backend, which is why youre a seeing that error message. I wonder if a better error message is needed or if it's just a question of better documentation.

FliesLikeABrick commented 5 years ago

@vegu thanks for the explanation! The logic in init.py seemed something like that but I didn't spend enough time to really comprehend it. Agreed it would be good to have a message improvement that indicated that django is the default backend but it needs to be installed or peeringdb-py reconfigured for another backend.

I can spend a bit more time looking at this and propose such a change this week