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

Editable python package available from within Python but Pyright is raising reportMissingModuleSource #3880

Closed
simensol opened this issue Aug 30, 2022 · 7 comments
Labels
as designed Not a bug, working as intended

Comments

@simensol
Copy link

simensol commented Aug 30, 2022

I'm developing on OS X from within a VSC devcontainer built from mcr.microsoft.com/vscode/devcontainers/python:3.10. I have a local Python package installed using Pipenv and a Pipfile:

...
[packages]
mypackage = { editable = true, path = "packages/mypackage" }
...

However, I'm using Pipenv to install the packages to the devcontainer's system Python by executing:

python3.10 -m pipenv install --dev --system --verbose --python 3.10

In other words, I'm not running Python from within a virtual environment within the devcontainer. Yesterday, when I rebuilt my container, Pylance suddenly reported my local Python package as missing by raising reportMissingModuleSource.

For debugging, I also tested with Pyright 1.1.268 by executing pyright --verbose from the project's root folder witch gave me the following results:

No configuration file found.
pyproject.toml file found at /workspaces/backend.
Loading pyproject.toml file at /workspaces/backend/pyproject.toml
No include entries specified; assuming /workspaces/backend
Search paths for /workspaces/backend
  /root/.npm/_npx/2bb4a7029cea5f83/node_modules/pyright/dist/typeshed-fallback/stdlib
  /workspaces/backend
  /workspaces/backend/typings
  /root/.npm/_npx/2bb4a7029cea5f83/node_modules/pyright/dist/typeshed-fallback/stubs/...
  /usr/local/lib/python3.10
  /usr/local/lib/python3.10/lib-dynload
  /usr/local/lib/python3.10/site-packages
Searching for source files
Found 65 source files
Could not import 'importlib_metadata' in file '/usr/local/lib/python3.10/site-packages/_pytest/compat.py'
  Looking in stubPath '/workspaces/backend/typings'
  Attempting to resolve stub package using root path '/workspaces/backend/typings'
  Attempting to resolve using root path '/workspaces/backend/typings'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve stub package using root path '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
  Looking for typeshed stdlib path
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/root/.npm/_npx/2bb4a7029cea5f83/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
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/authorizations/admin.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not import 'django.contrib.postgres.forms' in file '/workspaces/backend/typings/inclusive_django_range_fields/__init__.pyi'
  Looking in stubPath '/workspaces/backend/typings'
  Attempting to resolve stub package using root path '/workspaces/backend/typings'
  Attempting to resolve using root path '/workspaces/backend/typings'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve stub package using root path '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/site-packages'
  Resolved import with file '/usr/local/lib/python3.10/site-packages/django-stubs/__init__.pyi'
  Resolved import with file '/usr/local/lib/python3.10/site-packages/django-stubs/contrib/__init__.pyi'
  Resolved import with file '/usr/local/lib/python3.10/site-packages/django-stubs/contrib/postgres/__init__.pyi'
  Looking for typeshed stdlib path
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/root/.npm/_npx/2bb4a7029cea5f83/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
Could not import 'numpy' in file '/usr/local/lib/python3.10/site-packages/_pytest/python_api.py'
  Looking in stubPath '/workspaces/backend/typings'
  Attempting to resolve stub package using root path '/workspaces/backend/typings'
  Attempting to resolve using root path '/workspaces/backend/typings'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve stub package using root path '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
  Looking for typeshed stdlib path
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/root/.npm/_npx/2bb4a7029cea5f83/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
Could not import 'numpy' in file '/usr/local/lib/python3.10/site-packages/_pytest/python_api.py'
  Looking in stubPath '/workspaces/backend/typings'
  Attempting to resolve stub package using root path '/workspaces/backend/typings'
  Attempting to resolve using root path '/workspaces/backend/typings'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve stub package using root path '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
  Looking for typeshed stdlib path
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/root/.npm/_npx/2bb4a7029cea5f83/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
Could not import 'numpy' in file '/usr/local/lib/python3.10/site-packages/_pytest/python_api.py'
  Looking in stubPath '/workspaces/backend/typings'
  Attempting to resolve stub package using root path '/workspaces/backend/typings'
  Attempting to resolve using root path '/workspaces/backend/typings'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve stub package using root path '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
  Looking for typeshed stdlib path
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/root/.npm/_npx/2bb4a7029cea5f83/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
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/authorizations/test_managers.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/authorizations/test_models.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/authorizations/test_permissions.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not import 'mongoengine' in file '/usr/local/lib/python3.10/site-packages/rest_framework-stubs/generics.pyi'
  Looking in stubPath '/workspaces/backend/typings'
  Attempting to resolve stub package using root path '/workspaces/backend/typings'
  Attempting to resolve using root path '/workspaces/backend/typings'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve stub package using root path '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
  Looking for typeshed stdlib path
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/root/.npm/_npx/2bb4a7029cea5f83/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
Could not import 'mongoengine' in file '/usr/local/lib/python3.10/site-packages/rest_framework-stubs/filters.pyi'
  Looking in stubPath '/workspaces/backend/typings'
  Attempting to resolve stub package using root path '/workspaces/backend/typings'
  Attempting to resolve using root path '/workspaces/backend/typings'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve stub package using root path '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve stub package using root path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
  Looking for typeshed stdlib path
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/root/.npm/_npx/2bb4a7029cea5f83/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
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/claims/test_api.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/claims/test_models.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/claims/test_permissions.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/creditors/admin.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/creditors/test_api.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/creditors/test_models.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/creditors/test_permissions.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/manager/admin.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/manager/test_managers.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.utils' in file '/workspaces/backend/manager/test_models.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.terminal' in file '/workspaces/backend/manager/management/commands/_create_synthetic_data.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
Could not resolve source for 'mypackage.terminal' in file '/workspaces/backend/manager/management/commands/resetdb.py'
  Looking in root directory of execution environment '/workspaces/backend'
  Attempting to resolve using root path '/workspaces/backend'
  Looking in python search path '/usr/local/lib/python3.10'
  Attempting to resolve using root path '/usr/local/lib/python3.10'
  Looking in python search path '/usr/local/lib/python3.10/lib-dynload'
  Attempting to resolve using root path '/usr/local/lib/python3.10/lib-dynload'
  Looking in python search path '/usr/local/lib/python3.10/site-packages'
  Attempting to resolve using root path '/usr/local/lib/python3.10/site-packages'
pyright 1.1.268
/workspaces/backend/authorizations/admin.py
  /workspaces/backend/authorizations/admin.py:13:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/authorizations/test_managers.py
  /workspaces/backend/authorizations/test_managers.py:8:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/authorizations/test_models.py
  /workspaces/backend/authorizations/test_models.py:11:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/authorizations/test_permissions.py
  /workspaces/backend/authorizations/test_permissions.py:11:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/claims/test_api.py
  /workspaces/backend/claims/test_api.py:12:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/claims/test_models.py
  /workspaces/backend/claims/test_models.py:17:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/claims/test_permissions.py
  /workspaces/backend/claims/test_permissions.py:6:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/creditors/admin.py
  /workspaces/backend/creditors/admin.py:4:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/creditors/test_api.py
  /workspaces/backend/creditors/test_api.py:9:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/creditors/test_models.py
  /workspaces/backend/creditors/test_models.py:10:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/creditors/test_permissions.py
  /workspaces/backend/creditors/test_permissions.py:6:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/manager/admin.py
  /workspaces/backend/manager/admin.py:10:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/manager/test_managers.py
  /workspaces/backend/manager/test_managers.py:7:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/manager/test_models.py
  /workspaces/backend/manager/test_models.py:9:6 - warning: Import "mypackage.utils" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/manager/management/commands/_create_synthetic_data.py
  /workspaces/backend/manager/management/commands/_create_synthetic_data.py:13:6 - warning: Import "mypackage.terminal" could not be resolved from source (reportMissingModuleSource)
/workspaces/backend/manager/management/commands/resetdb.py
  /workspaces/backend/manager/management/commands/resetdb.py:14:6 - warning: Import "mypackage.terminal" could not be resolved from source (reportMissingModuleSource)
0 errors, 16 warnings, 0 informations 
Completed in 7.224sec

I noted that search paths didn't include the path to mypackage. Previously, I think this have been the case. By executing python3.10 -c "import sys; print('\n'.join(sys.path))" I (think I) previously got:

/usr/local/lib/python310.zip
/usr/local/lib/python3.10
/usr/local/lib/python3.10/lib-dynload
/usr/local/lib/python3.10/site-packages
/workspaces/backend/packages/mypackage

However, if I execute the command now, I get:

/usr/local/lib/python310.zip
/usr/local/lib/python3.10
/usr/local/lib/python3.10/lib-dynload
/usr/local/lib/python3.10/site-packages

That is, the path for mypackage is not included anymore. This led me to conclude that Pyright wasn't the issue. However, if I try to import mypackage from within Python, it works:

python3.10
Python 3.10.6 (main, Aug  3 2022, 10:13:24) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mypackage
>>> print(mypackage.__file__)
/workspaces/backend/packages/mypackage/mypackage/__init__.py

This made me check if mypackage was present in one of the search paths, and it was:

cd /usr/local/lib/python3.10/site-packages
dir
__editable__.mypackage-0.0.1.pth
__editable___mypackage_0_0_1_finder.py
mypackage-0.0.1.dist-info
[...]

I'm not sure if Pyright is the problem here, but since mypackage is available from within Python, I decided to open the issue here.

EDIT: pip list also correctly lists mypackage and it's location:

Package                          Version   Editable project location
------------------------------- --------- ----------------------------------------
mypackage                          0.0.1   /workspaces/backend/packages/mypackage
...
@erictraut
Copy link
Collaborator

Yeah, this isn't a pyright issue. You'll need to debug the issue with your configuration.

Pyright discovers the search paths by running the configured python interpreter and executing a small script that dumps out sys.path. You can manually simulate this by running python3 and then typing import sys and print(sys.path).

Make sure that you've activated your virtual environment prior to running pyright.

@erictraut erictraut added the as designed Not a bug, working as intended label Aug 30, 2022
@simensol
Copy link
Author

Yes, I suspected that. But why is the package available from within python? Shouldn't pyright have access to all packages that the python interpreter has access to?

PS: As stated above, I'm not running python from within a virtual environment. All packages are installed in the system's python.

@simensol
Copy link
Author

The issue was related to editable packages and setuptools. A temporary workaround suggested in the setuptools repro, is to add the environmental variable SETUPTOOLS_ENABLE_FEATURES="legacy-editable" before installing the packages with pip or pipenv.

@simensol
Copy link
Author

simensol commented Sep 2, 2022

@erictraut Are you sure it's noting wrong with how pyright detects installed editable packages? Setuptools has made some changes recently to it's editable installation hooks within the context of PEP 660.

It shouldn't be necessary to use setuptool's legacy behavior to prevent pyright from raising reportMissingModuleSource. To use setuptool's new editable installation hooks, I have to add each editable package to pyright's extraPaths to prevent it from raising reportMissingModuleSource.

As far as I understand, setuptool's new editable installation hooks doesn't add editable packages' paths to sys.path. Although the python interpreter itself doesn't have any problems importing the editable packages installed using setuptool's new editable installation hooks, pyright raises reportMissingModuleSource (as documented in my first comment).

@erictraut
Copy link
Collaborator

The new setuptools mechanism makes use of dynamic import hooks that work at runtime but are not discoverable by static analysis tools. The entire static analysis tooling community (including the authors of all of the Python type checkers) made it clear that this would break static analysis tools, but the setuptools folks went ahead and made the change anyway. Their decision is now causing pain for the big parts of the Python development community. PEP 660 is very problematic and IMO should not have never been accepted. We will need to find some solution, but in the meantime, our best suggestion is to fall back on setuptool's legacy behavior.

@simensol
Copy link
Author

simensol commented Sep 2, 2022

I see, thanks for the explanation!

@simensol simensol changed the title Local python package available from within Python but Pyright is raising reportMissingModuleSource Editable python package available from within Python but Pyright is raising reportMissingModuleSource Sep 2, 2022
@ThiefMaster
Copy link

Unless I'm missing something, it's quite easy to analyze this particular dynamic import hook in a fully static way. While not ideal, maybe it'd be a good workaround until the Python community comes up with something better? Especially because with tools like uv you always get PEP660-style editable installs - and while they could probably support legacy, maybe it's better to go by the old paradigm of being liberal on your inputs, but strict on your outputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended
Projects
None yet
Development

No branches or pull requests

3 participants