1

My projects are generally structured like this:

projectname/
    __init__.py
    python/
        mymodule.py
    other_stuff/
    more_stuff/

where __init__.py contains the following code

import os
mypath = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
__path__ = [mypath, mypath+"/python"]

This "skips" the python directory when importing to allow python code in the form from projectname import mymodule rather than from projectname.python import mymodule.

This appears to break pylint however, being unable to import any modules in the project despite $PYTHONPATH being set correctly. Creating a softlink projectname -> python in the projectname fixes things but isn't a suitable solution.

Any suggestions on how to fix this without altering the directory structure?

Chiggs
  • 2,824
  • 21
  • 31

1 Answers1

3

I think you're kind of stuck. Pylint doesn't process your __init__.py file so unless you can find another way of getting that information into pylint, I don't think it's going to work. Good luck.

Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
rhinoinrepose
  • 2,110
  • 2
  • 19
  • 26
  • Thanks for the answer - I believe you are correct and there is no nice way to fix this. In the end I just worked around it in a Makefile rule. – Chiggs Mar 24 '11 at 17:19
  • 1
    Can you elaborate how you worked around this issue? I'm running into the same problem. Thanks. – Srikanth Apr 01 '16 at 15:26
  • @Chiggs if you found a solution I encourage you to [share your knowledge, Q&A-style](http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/) to help [others who are trying to solve similar issues](http://stackoverflow.com/q/36359210/5827215) – Tadhg McDonald-Jensen Apr 01 '16 at 15:35
  • @Srikanth I used the soft-link hack described in the question. It was a bit dirty, but in the makefile rule for pylint I created all the softlinks and then removed them again afterwards. – Chiggs Apr 02 '16 at 16:43