Youcompleteme: [Python] parsing python submodules with absolute package paths

Created on 28 Nov 2017  路  4Comments  路  Source: ycm-core/YouCompleteMe

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside
the brackets) _before_ filing your issue:

  • [x] I have read and understood YCM's [CONTRIBUTING][cont] document.
  • [x] I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
  • [x] I have read and understood YCM's [README][readme], especially the
    [Frequently Asked Questions][faq] section.
  • [x] I have searched YCM's issue tracker to find issues similar to the one I'm
    about to report and couldn't find an answer to my problem. ([Example Google
    search.][search])
  • [x] If filing a bug report, I have included the output of vim --version.
  • [x] If filing a bug report, I have included the output of :YcmDebugInfo.
  • [x] If filing a bug report, I have attached the contents of the logfiles using
    the :YcmToggleLogs command.
  • [x] If filing a bug report, I have included which OS (including specific OS
    version) I am using.
  • [x] If filing a bug report, I have included a minimal test case that reproduces
    my issue, including what I expected to happen and what actually happened.
  • [x] If filing a installation failure report, I have included the entire output
    of install.py (or cmake/make/ninja) including its invocation
  • [x] I understand this is an open-source project staffed by volunteers and
    that any help I receive is a selfless, heartfelt _gift_ of their free time. I
    know I am not entitled to anything and will be polite and courteous.
  • [x] I understand my issue may be closed if it becomes obvious I didn't
    actually perform all of these steps.

Thank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.

Issue Details

I don't understand one thing. When I have unit tests in my project in directory tests and I refer to my module by relative path eg:

from ...MyModule import MyClass

I can easily use YCM for jumping for references from my unit tests.

But when I run my tests from the parent directory this way:

python -m tests.mymodule

I should be using absolute paths so I include my module in my unit tests this way:

from MyModule import MyClass

However, I can't see this is supported by YCM because after this I cannot jump to the definition of MyClass from my unittest.

Am I missing something here? I'm really sorry if I missed something in the documentation.

All 4 comments

That's because when running the tests with python -m tests.mymodule, you are adding the current directory (your project directory) to the Python path but Jedi (the semantic engine used by YCM for Python) is not aware of that. A solution is to add that path to the PYTHONPATH environment variable inside Vim and restart YCM:

:let $PYTHONPATH="/path/to/project/directory"
:YcmRestartServer

Thanks, that helps.
Is there a way to automate this in ~/.vimrc file when running?

Ok. This is what I was looking for:

let $PYTHONPATH .= getcwd()

Looks like you solved it. Closing :)

Was this page helpful?
0 / 5 - 0 ratings