On Thu, Mar 12, 2015 at 3:51 PM, Dani Hodovic <danih...@gmail.com> wrote:

> I have a very large project with deeply nested hierarchies. To find the
> root directory I use a source root walker and append the root directory to
> sys.path. This way, I can easily import things in the project relative to
> the root directory.
> The problem is that pylint doesn't detect this, even though I have a
> method which appends the path imported in the files where the path is used.
> So all my imports are marked as F0401
> <http://pylint-messages.wikidot.com/messages:f0401>: Unable to import.
>
> Is there any way to avoid this error message by getting pylint to
> understand sys.path?
>
> The __init__.py that is imported in files that need imports relative to
> the root directory:
>
> import os
> import sys
>
>
> def find_repo_rootdir():
>     def __check_parent(topdir):
>         for _, _, files in os.walk(topdir):
>             if '.THIS_IS_ROOT' in files:
>                 return topdir
>             else:
>                 next_ = topdir.rsplit("/", 1)
>                 if len(next_) == 2:
>                     return __check_parent(next_[0])
>                 else:
>                     return None
>     return __check_parent(os.path.abspath(os.path.dirname(__file__)))
>
> repo_root = find_repo_rootdir()
> if repo_root is not None and repo_root not in sys.path:
>     sys.path.append(repo_root)
>
>
> _______________________________________________
> code-quality mailing list
> code-quality@python.org
> https://mail.python.org/mailman/listinfo/code-quality
>
>
Hi Dani,

Please subscribe to the list so the rest of your posts will not need to be
moderated.

Thanks,
Ian
_______________________________________________
code-quality mailing list
code-quality@python.org
https://mail.python.org/mailman/listinfo/code-quality

Reply via email to