I have made a Python library whose tree directory structure looks like
lorentz_enrichment
├── __init__.py
│ └── lorentz_enricher.cpython-312.pyc
├── configs
│ ├── __init__.py
│ │ ├── logger.cpython-312.pyc
│ │ ├── s3.cpython-312.pyc
│ │ ├── settings.cpython-312.pyc
│ │ └── tqdm_handler.cpython-312.pyc
│ ├── logger.py
│ ├── s3.py
│ ├── settings.py
│ └── tqdm_handler.py
├── db
│ ├── __init__.py
...
├── lorentz_enricher.py
├── main.py
...
├── py.typed
...
32 directories, 157 files
This is what my __init__.py contains:
import logging
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .configs.settings import LorentzEnricherSettingsProvider
from .db.mongo.claim_rules_repository import ClaimRulesRepository
from .db.mongo.lorentz_claims_repository import LorentzClaimsRepository
from .db.mongo.mongo_base_repository import MongoBaseRepository
from .db.mongo.queue_messages_repository import QueueMessagesRepository
...
from .configs.settings import LorentzEnricherSettingsProvider
from .db.mongo.claim_rules_repository import ClaimRulesRepository
from .db.mongo.lorentz_claims_repository import LorentzClaimsRepository
from .db.mongo.mongo_base_repository import MongoBaseRepository
from .db.mongo.queue_messages_repository import QueueMessagesRepository
...
logging.getLogger(__name__).addHandler(logging.NullHandler())
__all__ = [
'LorentzEnricher',
'LorentzEnricherSettingsProvider',
...
]
def __dir__() -> list[str]:
return list(__all__)
Everything under TYPE_CHECKING is imported outside too.
And this is my pyproject.toml:
[tool.poetry]
name = "lorentz-enrichment"
version = "0.27.0-b5"
description = "Tools to enrich Lorentz claims with meteorological data"
authors = ["asant <***@***.eu>"]
readme = "README.md"
packages = [{ include = "lorentz_enrichment" }]
[tool.poetry.dependencies]
python = "^3.12"
...
[tool.poetry.group.dev.dependencies]
black = "24.10.0"
ruff = "0.11.11"
...
[tool.mypy]
exclude = [".venv"]
ignore_missing_imports = true
enable_error_code = "possibly-undefined"
disable_error_code = ["import-untyped", "override"]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
In my microservice the imports like from lorentz_enrichment import LorentzEnricher works correctly, however when in my code I type some classes like LorentzEnricher() without importing it first, VS Code won't suggest the import like it does for pydantic BaseModel for example.
What am I missing here?
1 Answer 1
You'll need to add your package's path to VS Code's "python.autoComplete.extraPaths" setting. And for good measure you may also want to add it to "python.analysis.extraPaths".
Open your settings.json file and add the following:
"python.autoComplete.extraPaths": [
"<path to your module>"
],
"python.analysis.extraPaths": [
"<path to your module>"
]
Mind your commas and make sure your JSON is properly formatted, and you should be good to go!
4 Comments
<install path>/lorentz_enrichment/. I suspect that it's ending up somewhere VS Code "can't see" out of the box. FWIW, if the install ends up somewhere typical, e.g. site-packages, it should pick up automatically - but sometimes VS Code is finicky.Explore related questions
See similar questions with these tags.