cytoscape / py2cytoscape

Python utilities for Cytoscape and Cytoscape.js
https://py2cytoscape.readthedocs.io
MIT License
178 stars 45 forks source link

Clarification on documentation / API for cyrest client #54

Closed krassowski closed 6 years ago

krassowski commented 6 years ago

Hi there, I tried to list commands from py2cytoscape as shown in docs:

>>> from py2cytoscape import cyrest
>>> cytoscape=cyrest.cyclient()
>>> cytoscape.commands.list()

but I am getting ImportError: cannot import name 'cyrest' as py2cytoscape is essentially empty. I tried with both: the latest version installed using pip3 and using latest version from develop branch. I can run:

from py2cytoscape.data.cyrest_client import CyRestClient
cy = CyRestClient()

as shown in Readme. Could you help me understand why are there two different ways to initialize the REST API client? And why the REST client (in the second example) resides in the data submodule?

krassowski commented 6 years ago

In the develop branch I got:

from py2cytoscape import cyrest
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-5-fd8dd043a7d4> in <module>()
----> 1 from py2cytoscape import cyrest

/usr/local/lib/python3.6/dist-packages/py2cytoscape/cyrest/__init__.py in <module>()
      5 
      6 """
----> 7 from cyrest import *

ModuleNotFoundError: No module named 'cyrest'

It seems that a relative import (from .cyrest import *) should be used there to make the package work in Python3.

krassowski commented 6 years ago

Also contrary to the declaration in docs ("py2cytoscape supports both Python 2.7 and 3.5."), if I do change the import to a relative one, I cannot use the cyrest anyway, as there are some Python2 print statements in the code:

In [1]: from py2cytoscape import cyrest
Traceback (most recent call last):

  File "/home/krassowski/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2910, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-1-fd8dd043a7d4>", line 1, in <module>
    from py2cytoscape import cyrest

  File "/usr/local/lib/python3.6/dist-packages/py2cytoscape/cyrest/__init__.py", line 7, in <module>
    from .cyrest import *

  File "/usr/local/lib/python3.6/dist-packages/py2cytoscape/cyrest/cyrest.py", line 1, in <module>
    from .base import *

  File "/usr/local/lib/python3.6/dist-packages/py2cytoscape/cyrest/base.py", line 41
    print "response status 200"
                              ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(print "response status 200")?
jorgeboucas commented 6 years ago

Hi @krassowski,

thanks for the feedback.

It's working fine for me on python 2.7:

>>> from py2cytoscape import cyrest
>>> cyclient=cyrest.cyclient()
>>> cyclient.commands.list()

Available namespaces:
  command
  cybrowser
  diffusion
  edge
  group
  idmapper
  layout
  network
  node
  session
  string
  table
  view
  vizmap

For the moment please use the latest pip version if you wish to use python 3.5.

The new cyrest module in the development branch is currently under development, not ready for python 3 and not yet ready for end users.

Do you also have problems with python 2.7 ?

Thanks!

jorgeboucas commented 6 years ago

for documentation on the current pip version you can use the examples folder

jorgeboucas commented 6 years ago

I've fixed the from .cyrest import * issue - the remaining imports were already python3 . compatible and should need no fix