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

[BUG] location of data_files breaks type checking when using a virtual environment #232

Closed
ITProKyle opened this issue May 16, 2022 · 1 comment · Fixed by #325
Closed

Comments

@ITProKyle
Copy link

NOTE: This has only been tested with pyright as the type checker and a virtual environment created by poetry. It could be isolated to this combination of tools or it may affect other.

When type checking my project with pygls installed, pyright is unable to import dependencies. Example from running npx pyright --venv-path ./ --verbose

Could not import 'pydantic' in file '/path/to/project/project/utils/__init__.py'
  Looking in stubPath '/path/to/project/typings'
  Attempting to resolve stub package using root path '/path/to/project/typings'
  Attempting to resolve using root path '/path/to/project/typings'
  Looking in root directory of execution environment '/path/to/project'
  Attempting to resolve stub package using root path '/path/to/project'
  Attempting to resolve using root path '/path/to/project'
  Looking in python search path '/path/to/project/.venv/lib/site-packages'
  Attempting to resolve stub package using root path '/path/to/project/.venv/lib/site-packages'
  Attempting to resolve using root path '/path/to/project/.venv/lib/site-packages'
  Looking for typeshed stdlib path
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/path/to/project/node_modules/pyright/dist/typeshed-fallback/stdlib'
  Typeshed path not found
  Looking for typeshed third-party path
  Looking for typeshed stubs path
  Typeshed path not found

Notable in this output is the search path .venv/lib/site-packages which only contains data files for pygls. The correct path for dependencies within this virtual environment is .venv/lib/python3.10/site-packages.

image

I believe the existence of .venv/lib/site-packages causes the correct path to not be used. Removal of pygls as a dependency resolves this issue as .venv/lib/site-packages is no longer created.

Here is the section of code causing .venv/lib/site-packages to be created:

pygls/setup.cfg

Lines 53 to 56 in 75c9b15

[options.data_files] =
lib/site-packages/pygls =
ThirdPartyNotices.txt
./pygls/py.typed


I am using the following packages/tools:

  • multiple versions of python used to test this
    • python3.10 (installed via homebrew)
    • python3.9 (installed via pyenv)
    • python3.8 (installed via pyenv)
  • poetry==1.1.13 used to manage dependencies and create a virtual environment
  • pygls==0.11.3 (installed as a dependency of esbonio==0.11.2)
  • [email protected]
@tombh
Copy link
Collaborator

tombh commented Dec 5, 2022

Apologies for such a late reply. I've been considering moving Pygls over to using Poetry. I suspect that would fix this issue?

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue May 21, 2023
## [1.0.2] - May 15th, 2023
### Changed
- Update typeguard to 3.x ([#327])

### Fixed
- Data files are no longer placed inside the wrong `site-packages` folder when installing `pygls` ([#232])
[#232]: openlawlibrary/pygls#232
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants