Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module if source file is a symbolic link #1470

Closed
suhlatwork opened this issue May 8, 2017 · 6 comments · Fixed by #5529
Closed

Cannot find module if source file is a symbolic link #1470

suhlatwork opened this issue May 8, 2017 · 6 comments · Fixed by #5529
Labels

Comments

@suhlatwork
Copy link

Somewhere between versions 1.5.5 and 1.7.1 the behaviour concerning modules using symbolic links to install files in the module directory has changed. Running pylint on such a module gives the following error:

$ pylint pyMyTool
No config file found, using default configuration
Traceback (most recent call last):
  File "/XXX/.local/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/XXX/.local/lib/python2.7/site-packages/pylint/__init__.py", line 13, in run_pylint
    Run(sys.argv[1:])
  File "/XXX/.local/lib/python2.7/site-packages/pylint/lint.py", line 1300, in __init__
    linter.check(args)
  File "/XXX/.local/lib/python2.7/site-packages/pylint/lint.py", line 726, in check
    self._do_check(files_or_modules)
  File "/XXX/.local/lib/python2.7/site-packages/pylint/lint.py", line 837, in _do_check
    for descr in self.expand_files(files_or_modules):
  File "/XXX/.local/lib/python2.7/site-packages/pylint/lint.py", line 869, in expand_files
    self.config.black_list_re)
  File "/XXX/.local/lib/python2.7/site-packages/pylint/utils.py", line 894, in expand_modules
    modpath = _modpath_from_file(subfilepath, is_namespace)
  File "/XXX/.local/lib/python2.7/site-packages/pylint/utils.py", line 833, in _modpath_from_file
    return modutils.modpath_from_file_with_callback(filename, is_package_cb=_is_package_cb)
  File "/XXX/.local/lib/python2.7/site-packages/astroid/modutils.py", line 310, in modpath_from_file_with_callback
    filename, ', \n'.join(sys.path)))
ImportError: Unable to find module for /tmp/yyy/py/git/pyBinding/module/_func.py in /tmp/yyy/py,
.,
/XXX/.local/bin,
/tmp/yyy/py/install/pyLib,
/opt/rh/devtoolset-3/root/usr/lib64/python2.6/site-packages,
/opt/rh/devtoolset-3/root/usr/lib/python2.6/site-packages,
/opt/rh/python27/root/usr/lib64/python27.zip,
/opt/rh/python27/root/usr/lib64/python2.7,
/opt/rh/python27/root/usr/lib64/python2.7/plat-linux2,
/opt/rh/python27/root/usr/lib64/python2.7/lib-tk,
/opt/rh/python27/root/usr/lib64/python2.7/lib-old,
/opt/rh/python27/root/usr/lib64/python2.7/lib-dynload,
/XXX/.local/lib/python2.7/site-packages,
/opt/rh/python27/root/usr/lib64/python2.7/site-packages,
/opt/rh/python27/root/usr/lib/python2.7/site-packages,
/XXX/.local/lib/python2.7/site-packages/astroid/brain

Steps to reproduce

Consider the following directory structure:

/tmp/yyy/py/install/pyLib/pyMyTool/
    __init__.py ->../../../git/pyBinding/module/__init__.py (symbolic link)
    _func.py -> ../../../git/pyBinding/module/_func.py (symbolic link)
/tmp/yyy/py/git/pyBinding/module/
    __init__.py
    _func.py

with __init__.py containing:

from _func import func

and _func.py containing:

def func():
    return 1

The directory /tmp/yyy/py/install/pyLib is included in the environment variable PYTHONPATH. Importing the module pyMyTool in Python works and has the expected result:

$ python
Python 2.7.5 (default, Jun  5 2014, 14:38:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyMyTool
>>> pyMyTool.func()
1
>>>

Current behavior

Running pylint pyMyTool prints the aforementioned error message.

Expected behavior

Running pylint pyMyTool should run its tests.

pylint --version output

$ pylint --version
No config file found, using default configuration
pylint 1.7.1,
astroid 1.5.2
Python 2.7.5 (default, Jun  5 2014, 14:38:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]

Please let me know in case you need additional information.

suhlatwork added a commit to suhlatwork/ROOTPWA that referenced this issue Jun 13, 2017
Fix pylint errors for version 1.7.1:
* Do not use `len(SEQUENCE)` as condition value
* Unnecessary "else" after "return"

Version 1.7.1 cannot yet be made the default for Travis, as this version
cannot handle the way we install out Python module using symbolic links
(pylint-dev/pylint#1470).
suhlatwork added a commit to suhlatwork/ROOTPWA that referenced this issue Jun 13, 2017
Fix pylint errors for version 1.7.1:
* Do not use `len(SEQUENCE)` as condition value
* Unnecessary "else" after "return"

Version 1.7.1 cannot yet be made the default for Travis, as this version
cannot handle the way we install out Python module using symbolic links
(pylint-dev/pylint#1470).
suhlatwork added a commit to suhlatwork/ROOTPWA that referenced this issue Jun 16, 2017
Fix pylint errors for version 1.7.1:
* Do not use `len(SEQUENCE)` as condition value
* Unnecessary "else" after "return"

Version 1.7.1 cannot yet be made the default for Travis, as this version
cannot handle the way we install out Python module using symbolic links
(pylint-dev/pylint#1470).
bgrube pushed a commit to ROOTPWA-Maintainers/ROOTPWA that referenced this issue Jul 13, 2017
Fix pylint errors for version 1.7.1:
* Do not use `len(SEQUENCE)` as condition value
* Unnecessary "else" after "return"

Version 1.7.1 cannot yet be made the default for Travis, as this version
cannot handle the way we install out Python module using symbolic links
(pylint-dev/pylint#1470).
@christianmlong
Copy link

I think this is related to the change made in pylint-dev/astroid@cda9dc4

I'm getting the same problem when one of my python modules is actually a symlink, on macOS High Sierra, Python 2.7.14

I changed modutils.py line 290 back to what it was before cda9dc4, and that fixed the problem of Pylint not being able to find the symlink.

diff --git a/astroid/modutils.py b/astroid/modutils.py
index 83d0ba7..6e23da8 100644
--- a/astroid/modutils.py
+++ b/astroid/modutils.py
@@ -287,7 +287,7 @@ def check_modpath_has_init(path, mod_path):

 def modpath_from_file_with_callback(filename, extrapath=None, is_package_cb=None):
     filename = _path_from_filename(filename)
-    filename = os.path.realpath(os.path.expanduser(filename))
+    filename = os.path.abspath(filename)
     base = os.path.splitext(filename)[0]

     if extrapath is not None:

@ColCarroll
Copy link

ColCarroll commented Jan 25, 2018

Any fix for this in the meantime? (in particular, should I check with astroid if we can help fix there?)

suhlatwork pushed a commit to ROOTPWA-Maintainers/ROOTPWA that referenced this issue Feb 8, 2018
Increase the minimal required version as older versions have a problem
with newer numpy versions.
Additionally, the new pylint version has a problem with symlinks
(pylint-dev/pylint#1470).
Therefore, run the pylint test directly on the source code and not on
the build folder.
@Pluckerpluck
Copy link

This is still a bug right?

@PCManticore
Copy link
Contributor

@Pluckerpluck I presume so, the issue hasn't been closed or worked on lately.

@wandering007
Copy link

@Pluckerpluck I am also faced with this issue for pylint 2.3.1.

@jadchaar
Copy link

jadchaar commented May 4, 2020

This seems to be an issue with the latest version of pylint:

pylint 2.5.0
astroid 2.4.0
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)]

Symlinks and pylint worked fine for our team on pylint 2.4.x

Pierre-Sassoulas added a commit that referenced this issue Dec 19, 2021
Closes #1470
Closes #3499
Closes #4302
Closes #4798
Closes #5081
Pierre-Sassoulas added a commit that referenced this issue Dec 19, 2021
Pierre-Sassoulas added a commit that referenced this issue Dec 31, 2021
Closes #1470
Closes #3499
Closes #4302
Closes #4798
Closes #5081
Pierre-Sassoulas added a commit that referenced this issue Dec 31, 2021
Pierre-Sassoulas added a commit that referenced this issue Dec 31, 2021
Closes #1470
Closes #3499
Closes #4302
Closes #4798
Closes #5081
Pierre-Sassoulas added a commit that referenced this issue Dec 31, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jan 2, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants