On 08/08/14 13:15, Claudiu Popa wrote:
On Thu, Aug 7, 2014 at 9:57 PM, Mark E. Hamilton <mham...@sandia.gov> wrote:
Hi,

I'm having trouble figuring out how pylint finds python files to process. If
I find() all the .py files in my project and pass them on the command line
pylint processes them correctly (after I set up PYTHONPATH, of course.)

However, if I just pass my project directory to pylint it fails with:

F:  1, 0: error while code parsing: Unable to load file '.../__init__.py'
([Errno 2] No such file or directory: '.../__init__.py') (parse-error)

If I create an empty __init__.py file it works, but only finds and processes
some of the files. This seems to imply that I need to created __init__.py
files in my entire tree. Is that the case?



Yes, that's the case, you need __init__.py files in order to tell
pylint that those are packages. Pylint doesn't support (yet) Python
3's implicit namespace packages (PEP 420).


FWIW, we're using these versions:

ceerws3111a 1123% pylint --version
No config file found, using default configuration
pylint 1.2.1,
astroid 1.1.1, common 0.61.0
Python 2.7.4 (default, Aug 26 2013, 10:48:13)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]

IAE, perhaps this is just a misunderstanding we have about python. All of our python scripts work, and we've never had __init__.py files in every subdirectory. What you say would imply that even directories which contain no python files have to have a __init__.py file. For instance, if I have this:

    % find .
    .
    ./test_dir1
    ./test_dir1/subdir1
    ./test_dir1/subdir1/test1.py


it seems that I would have to create __init__.py files in '.', test_dir1, and subdir1, even though '.' and test_dir1 don't contain any python files.

However, to test this I ran pylint this way:

    pylint ${PWD}

I get the 'Unable to load' error I reported above. This

    touch __init__.py
    pylint ${PWD}

only processes the __init__.py file, as expected from what you said, and reports a missing-dosctring.

However, when I do this pylint throws traceback.

    touch test_dir1/__init__.py
    pylint ${PWD}
No config file found, using default configuration
Traceback (most recent call last):
File "/projects/sierra/linux_rh6/install/Python/2.7/bin/pylint", line 9, in <module>
    load_entry_point('pylint==1.2.1', 'console_scripts', 'pylint')()
File "/projects/sierra/linux_rh6/install/Python/2.7/lib/python2.7/site-packages/pylint-1.2.1-py2.7.egg/pylint/__init__.py", line 21, in run_pylint
    Run(sys.argv[1:])
File "/projects/sierra/linux_rh6/install/Python/2.7/lib/python2.7/site-packages/pylint-1.2.1-py2.7.egg/pylint/lint.py", line 1051, in __init__
    linter.check(args)
File "/projects/sierra/linux_rh6/install/Python/2.7/lib/python2.7/site-packages/pylint-1.2.1-py2.7.egg/pylint/lint.py", line 608, in check
    for descr in self.expand_files(files_or_modules):
File "/projects/sierra/linux_rh6/install/Python/2.7/lib/python2.7/site-packages/pylint-1.2.1-py2.7.egg/pylint/lint.py", line 638, in expand_files
    result, errors = expand_modules(modules, self.config.black_list)
File "/projects/sierra/linux_rh6/install/Python/2.7/lib/python2.7/site-packages/pylint-1.2.1-py2.7.egg/pylint/utils.py", line 648, in expand_modules
    submodname = '.'.join(modpath_from_file(subfilepath))
File "/projects/sierra/linux_rh6/install/Python/2.7/lib/python2.7/site-packages/logilab_common-0.61.0-py2.7.egg/logilab/common/modutils.py", line 250, in modpath_from_file
    filename, ', \n'.join(sys.path)))
ImportError: Unable to find module for /ascldap/users/mhamilt/project/test_dir1/__init__.py in /home/mhamilt,
/projects/sierra/linux_rh6/install/Python/2.7.4/bin,
...

Creating __init__.py in subdir1 doesn't resolve this traceback, nor does creating a python file in test_dir1. However, setting PYTHONPATH to this

    export PYTHONPATH=${PWD}/test_dir1
    pylint ${PWD}

does resolve the traceback, and pylint processes the two __init__.py files. Finally, doing this

    touch test_dir1/subdir1/__init__.py
    % find .
    .
    ./test_dir1
    ./test_dir1/__init__.py
    ./test_dir1/subdir1
    ./test_dir1/subdir1/test1.py
    ./test_dir1/subdir1/__init__.py
    ./test_dir2
    ./test_dir2/subdir2
    ./test_dir2/subdir2/test2.py
    ./__init__.py
    pylint ${PWD}

works, processes all three __init__.py files and the test1.py file. If I unset PYTHONPATH the traceback returns.

I don't understand:

1. Why pylint is throwing a traceback
2. Why setting PYTHONPATH to the directory in the middle is necessary.
3. Why creating all those __init__files is necessary.


--
----------------
Mark E. Hamilton
Engineering Sciences Center
Senior Member of Technical Staff
Sandia National Laboratories
505-844-7666
_______________________________________________
code-quality mailing list
code-quality@python.org
https://mail.python.org/mailman/listinfo/code-quality

Reply via email to