Closed OrkoHunter closed 9 years ago
I'm creating a topic over the cython-users
mailing list. Hope something good comes out of it.
Is your travis-test branch completely updated? E.g. with master, setup, travis-ci all merged in? I just tried python setup.py build
and I complains:
error: Namespace package problem: networkx.addons.metis is a namespace package, but its __init__.py does not call declare_namespace()! Please fix it.
If it is not completely updated, can you push it up so that others can easily debug/test.
@chebee7i Thanks for looking into it. Please give me a moment.
Pushed the changes. It's building for me. Can you please check now?
Builds fine, but I cannot install via: pip install -e .
. That is rather unfortunate. Am I doing anything wrong?
Does your error log contains these lines?
/usr/bin/ld: cannot find -lmetis
/usr/bin/ld: cannot find -lgklib
/usr/bin/ld: cannot find -lgklib
/usr/bin/ld: cannot find -lmetis
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Can you try deleting networkx/addons/metis/__init__.py
if it's there? And also change the line in setup.py
packages = ['networkx.addons.metis', 'networkx.addons', 'networkx'],
to
packages = ['networkx.addons', 'networkx'],
The reason pip install -e .
does not work is because it doesn't install it as a namespace package. If I install using pip install .
, then it is fine. There is, however, another issue: There are circular imports. _metis.so
imports types.py
. But types.py
needs to import _metis
. Can you make any of those imports function level imports or create a third file which has the common stuff only?
Should I still try the change you just suggested? I don't think it is needed.
The circular imports cause problems in the case of
from _metis import *
Doing absolute module import and using it as module.name
resolves the problem of circular import. We discussed it here.
I'm not doing absolute imports, I'm running the code in the branch.
The circular import issue is still legitimate. Both _metis.pyx
and types.py
require that the other be available when they are imported. This will cause a circular import every time.
The simplest solution is to move
class MetisError(Exception):
"""An error type generated from METIS"""
def __init__(self, rstatus):
super(MetisError, self).__init__(rstatus)
into its own file exceptions.py
. Then _metis.pyx
only needs to import that. types.py
will still import _metis.pyx
, but the circle is broken.
Did your installed networkx
core package contains networkx.addons.__init__.py
with
__import__('pkg_resources').declare_namespace(__name__)
in it? If I understand correctly, networkx-metis
won't work without modifying the networkx
core package.
The idea of exceptions.py
sounds reasonable if the problem of circular import is still there.
I used exceptions.py
and it fixed the import issue.
My networkx.addons.__init__.py
in the core NetworkX does not have the line you mentioned and it works just fine.
I sent you a PR...not sure if the travis-test branch is the correct place for that. Feel free to gut the changes and place elsewhere. But I am able to build without issues after that change. I am also using your "addons" branch for NetworkX (which has a blank networkx.addons.__init__.py
), even though I think you are correct that it is supposed to have that line you mentioned.
It's so astonishing for me that the actual problem (at this stage) was still the circular import which I thought was resolved. Thanks @chebee7i.
Glad to hear. FYI, using absolute imports cannot, in principle, resolve circular imports since a circular import has to do with access at parse time. Whether you use a relative or absolute import only changes how you access it, but it does not change whether you need access to it in the first place. To resolve it, you need to not access it at the top-level, or find some other way to break the loop.
With #18, can networkx/addons/__init__.py
be changed back into an empty file then?
With #18, can networkx/addons/init.py be changed back into an empty file then?
Things started working after #18. networkx/addons/__init__.py
was not empty any time. I don't think keeping it empty will help.
Now,
In [1]: import networkx as nx
In [2]: nx
Out[2]: <module 'networkx' from '/usr/local/lib/python2.7/dist-packages/networkx-2.0.dev_20150616095129-py2.7.egg/networkx/__init__.pyc'>
In [3]: import networkx.addons
In [4]: networkx.addons
Out[4]: <module 'networkx.addons' from '/usr/local/lib/python2.7/dist-packages/networkx_metis-1.0-py2.7-linux-x86_64.egg/networkx/addons/__init__.pyc'>
After I emptied the networkx/addons/__init__.py
file
In [1]: import networkx as nx
In [2]: nx
Out[2]: <module 'networkx' from '/usr/local/lib/python2.7/dist-packages/networkx-2.0.dev_20150616095129-py2.7.egg/networkx/__init__.pyc'>
In [3]: import networkx.addons
In [4]: networkx.addons
Out[4]: <module 'networkx.addons' from '/usr/local/lib/python2.7/dist-packages/networkx-2.0.dev_20150616095129-py2.7.egg/networkx/addons/__init__.py'>
In [5]: import networkx.addons.metis
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-44df29cab2f4> in <module>()
----> 1 import networkx.addons.metis
ImportError: No module named metis
We can see in both Out[4]
, the indentity of networkx.addons
depends upon the content of networkx/addons/__init__.py
.
Fair enough. Let's get #18 done to unblock this.
_/\_
It's strange that pylint
gives positive result on my computer. Comments @ysitu ? You've tried it, right?
Latest Build https://travis-ci.org/OrkoHunter/networkx-metis/builds/68863016
You should be able to get rid of many no-member
errors by whitelisting networkx.addons.metis._metis
for importing by pylint.
If setting up pylint is much too tricky, how about trying out landscape.io?
Let me try it.
I would say we go with landscape.io. It also uses pylint, but on a moderate level. Can you set up the hook there?
I am on an airplane right now.
Yeah you must be going. @chebee7i Ping.
Anything that requires admin level privileges will require action from @hagberg, @dschult, or @jtorrents .
Let's add @chebee7i as owner - I can't do it right now @dschult, @jtorrents?
Done! @chebee7i is in the owner group now. I'm not sure how to set up the travis hook (still have to set the readthedocs for my fork). So I'll let @chebee7i do it.
Done for both metis and lemon. @OrkoHunter I need your readthedocs username as well.
My username for readthedocs is same as GitHub orkohunter
. However, my fork of docs is here
http://orkohunter-networkx-metis.readthedocs.org/en/doc/
It is case-sensitive...that is why I couldn't add you. :)
Oh.. My bad then. :)
Triggered first build with python 2.7, 3.2+, pypy and pypy3. Let's wait for the results.
Here it is, ironically it fails for Python 2.7 and passes for Python 3.2+, pypy and pypy3. The problem lies with installation. Right now, it is
python setup.py install
python setup.py test
But if we skip the installation and rather only build and test
python setup.py build
python setup.py test
it passes for all.
Well it passed for build
and test
as I mentioned earlier.
With python setup.py test
you are not testing the installed code.
To test the installed code, do we need to run a python script which would do some imports and run some tests within it?
cd
into some unrelated directory and run nosetests
?
nosetests
searches recursively for all the tests within a directory. Won't making a new unrelated directory will run 0 tests? And running nosetests
from the top level will also be same as python setup.py test
, and both are generating the same OS error. I'm still surprised the variation of running the test between Python 2 and 3.
You can supply a module name to nosetests
?
Yes, like nosetests only_this_test.py
.
Look at what we do in networkx.
pypy needs special installation http://pypy.readthedocs.org/en/latest/faq.html#module-xyz-does-not-work-with-pypy-importerror
Green tick feels. Well,
install_requires
will automatically do the job.Note, to guarantee that the (all) tests are using the installed networkx rather than the repository one, you can move directories...but also, each test file must have from __future__ import absolute_import
.
Fixes #12 .
NOTES
pip install networkx
, I'm installing this branch from my fork of networkx.nosetests
is checking the entirenetworkx
+networkx+metis
library.master
setup
andtravis-ci
all merged in onetravis-test
over https://travis-ci.org/OrkoHunter/networkx-metisBut it's not ready yet. Namespace packaging is done, but there seems to be a little problem while installing.
setup.py
is installing a strange file named_metis.py
in the same location as_metis.so
with the following contentThis file is causing trouble and interfering while importing
networkx.addons.metis._metis
. Renaming the.so
file doesn't help either, the new file is given the same name except for having.py
extension.Related : http://askubuntu.com/questions/442357/environment-setup-for-importing-a-userdefined-module/442363#comment917656_442363