question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Goto definition stop working after diving into python internals with virtualenvwrapper

See original GitHub issue

Hello,

I use this extension in a setup where I have pyenv to control python versions and on top of it virtualvenvwrapper to keep my venvs organized in a common folder and it works much like the anaconda scenario but with a WORKON_HOME envvar to tell were the virtualenvs are (~/.virtualenvs in my case), and a VIRTUAL_ENV envvar that once activated tells the location of the activated venv.

I noticed that sometimes while diving into python internals definitions the goto definition stops working and keeps showing the following message:

[coc.nvim] definition not found

The only way I can get them back working is by closing vim or nvim and opening it again. It was hard to find a pattern but today I found a consistent way of reproducing it, you just need to create a folder to your code then a setup.py file with the following content:

from setuptools import setup

setup()

The next steps to reproduce it are:

  • Open the file
  • Jump into setup() definition
  • Jump into _install_setup_requires(attrs) that is in the same file to see everything works
  • Then jump into setup from the line bellow _install_setup_requires that has this content return distutils.core.setup(**attrs)
  • At this point you will notice that you leave virtualenv space to reach pyenv distutils core code
  • Navigate back to your setup.py code without closing the editor
  • Jump into setup() definition
  • Jump into _install_setup_requires(attrs) and this time it’s not working anymore

Checking the outputs I got this:

What’s the output of :CocCommand pyright.version

[coc.nvim] coc-pyright 1.1.243 with Pyright 1.1.244

What’s the output of :CocCommand workspace.showOutput Pyright

Workspace: /home/humrochagf/Projects/example
Using python from /home/humrochagf/.virtualenvs/test/bin/python

[Info  - 5:16:10 PM] Pyright language server 1.1.244 starting
[Info  - 5:16:10 PM] Server root directory: /home/humrochagf/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info  - 5:16:10 PM] No configuration file found.
[Info  - 5:16:10 PM] No pyproject.toml file found.
[Info  - 5:16:10 PM] Setting pythonPath for service "example": "/home/humrochagf/.virtualenvs/test/bin/python"
[Warn  - 5:16:10 PM] stubPath /home/humrochagf/Projects/example/typings is not a valid directory.
[Info  - 5:16:10 PM] Assuming Python version 3.10
[Info  - 5:16:10 PM] Assuming Python platform Linux
[Info  - 5:16:10 PM] Searching for source files
[Info  - 5:16:10 PM] Found 1 source file
[Info  - 5:16:15 PM] No configuration file found.
[Info  - 5:16:15 PM] No pyproject.toml file found.
[Info  - 5:16:15 PM] Setting pythonPath for service ".pyenv": "/home/humrochagf/.virtualenvs/test/bin/python"
[Warn  - 5:16:15 PM] stubPath /home/humrochagf/.pyenv/typings is not a valid directory.
[Info  - 5:16:15 PM] Assuming Python version 3.10
[Info  - 5:16:15 PM] Assuming Python platform Linux
[Info  - 5:16:15 PM] Searching for source files
[Info  - 5:16:16 PM] Found 7370 source files
[Info  - 5:17:29 PM] No pyproject.toml file found.
[Info  - 5:17:29 PM] Setting pythonPath for service "<default>": "/home/humrochagf/.virtualenvs/test/bin/python"
[Warn  - 5:17:29 PM] stubPath typings is not a valid directory.
[Info  - 5:17:29 PM] Assuming Python version 3.10
[Info  - 5:17:29 PM] Assuming Python platform Linux
[Info  - 5:17:29 PM] Searching for source files
[Info  - 5:17:29 PM] No source files found.

I Tried to compare with the same setup of having pyenv but instead of using virtualenvwrapper creating a venv inside the code folder and in that case, everything works properly.

And checking the logs I noticed that I don’t get the Setting pythonPath for service "<default>" log chunk.

This is my venv test for comparison:

Workspace: /home/humrochagf/Projects/example
Using python from /home/humrochagf/Projects/example/.venv/bin/python

[Info  - 5:45:21 PM] Pyright language server 1.1.244 starting
[Info  - 5:45:21 PM] Server root directory: /home/humrochagf/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info  - 5:45:21 PM] No configuration file found.
[Info  - 5:45:21 PM] No pyproject.toml file found.
[Info  - 5:45:21 PM] Setting pythonPath for service "example": "/home/humrochagf/Projects/example/.venv/bin/python"
[Warn  - 5:45:21 PM] stubPath /home/humrochagf/Projects/example/typings is not a valid directory.
[Info  - 5:45:21 PM] Assuming Python version 3.10
[Info  - 5:45:21 PM] Assuming Python platform Linux
[Info  - 5:45:21 PM] Searching for source files
[Info  - 5:45:21 PM] Found 1 source file
[Info  - 5:45:36 PM] No configuration file found.
[Info  - 5:45:36 PM] No pyproject.toml file found.
[Info  - 5:45:36 PM] Setting pythonPath for service ".pyenv": "/home/humrochagf/Projects/example/.venv/bin/python"
[Warn  - 5:45:36 PM] stubPath /home/humrochagf/.pyenv/typings is not a valid directory.
[Info  - 5:45:36 PM] Assuming Python version 3.10
[Info  - 5:45:36 PM] Assuming Python platform Linux
[Info  - 5:45:36 PM] Searching for source files
[Info  - 5:45:37 PM] Found 7370 source files

Another info that may be pertinent is that the Setting pythonPath for service "<default>" log chunk happens at the second time I jump from my code into the setup() call.

Thanks for taking the time of reading my issue and also thanks a lot for this awesome extension 😃

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fannheywardcommented, May 28, 2022

First of all, very clear issue steps 👍 .

I’m using project-level venv in my projects, as your 2nd test, didn’t encounter the problem.

I’d like to debug the issue with pyenv/virtualvenvwrapper, can you clear me how do you setup pyenv to keep all venvs in a common folder? Sorry I didn’t use pyenv ever.

0reactions
humrochagfcommented, Jun 20, 2022

Oh no worries, when I have some spare time I’ll also try to investigate more to see what can be done 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · fannheyward/coc-pyright - GitHub
Goto definition stop working after diving into python internals with virtualenvwrapper ... coc-pyright could not find pyrightconfig.json.
Read more >
Python Virtual Environments: A Primer
In this tutorial, you'll learn how to work with Python's venv module to create and manage separate virtual environments for your Python ......
Read more >
elpy-goto-definition and virtualenv - python - Stack Overflow
Basically I have two different virtualenvs, in one of them elpy-goto-definition works as expected. If I change to the other environment using ...
Read more >
Dive Into Python 3
Python 3 will never implicitly convert between strings and bytes, so if you're not sure which one you have at any given moment,...
Read more >
Python VS Common Lisp, workflow and ecosystem
After 8 years working and doing side projects in Python and JavaScript (mostly web dev, Django/Flask/AngularJS/Vuejs), I am not satisfied ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found