A Neovim plugin that seamlessly integrates Pyright LSP with Docker containers, solving the path mismatch problem between host and container environments. Perfect for Python development in containerized environments.
- ๐ Seamless Path Translation: Automatically translates file paths between host and container environments
- ๐ฏ Smart Interpreter Selection: Choose between local virtual environments or Docker containers
- ๐ Auto-discovery: Automatically finds Poetry, Pipenv, venv, and other virtual environments
- ๐พ Intelligent Caching: Caches discovery results for better performance
- ๐ฅ Health Monitoring: Built-in health check system with periodic monitoring
- ๐ง Auto-configuration: Can automatically select the best interpreter based on your setup
- ๐ฆ Zero Container Setup: Automatically installs Pyright in containers when needed
- ๐ Debug Support: Comprehensive logging for troubleshooting
- Neovim >= 0.10
- nvim-lspconfig
- Python 3.7+ (on host and in container)
- Docker and Docker Compose (for container support)
- Optional: plenary.nvim for enhanced path handling
Using lazy.nvim
{
"yourusername/neovim-docker-python-interpreter.nvim",
dependencies = {
"neovim/nvim-lspconfig",
"nvim-lua/plenary.nvim", -- optional but recommended
},
config = function()
require("docker_python_interpreter").setup({
-- your configuration here
})
end,
}Using packer.nvim
use {
"yourusername/neovim-docker-python-interpreter.nvim",
requires = {
"neovim/nvim-lspconfig",
"nvim-lua/plenary.nvim", -- optional
},
config = function()
require("docker_python_interpreter").setup({
-- your configuration here
})
end,
}require("docker_python_interpreter").setup({
-- Docker configuration
docker = {
service = "web", -- Your docker-compose service name
workdir = "/srv/app", -- Working directory inside container
compose_cmd = {"docker", "compose"}, -- Command to run docker compose
auto_install_pyright = true, -- Auto-install Pyright in container
health_check_interval = 300, -- Health check interval in seconds (0 to disable)
path_map = {
container_root = "/srv/app", -- Root path in container
host_root = nil, -- Root path on host (nil = auto-detect)
},
},
-- Pyright LSP settings
pyright_settings = {
python = {
analysis = {
autoSearchPaths = true,
diagnosticMode = "workspace",
typeCheckingMode = "basic",
},
},
},
-- Plugin behavior
auto_select = false, -- Auto-select interpreter if only one available
prefer_docker = false, -- Prefer Docker over local when both available
cache_ttl = 60, -- Cache discovery results for N seconds
-- Optional: Custom on_attach function for LSP
on_attach = function(client, bufnr)
-- Your custom LSP keybindings/settings
end,
})require("docker_python_interpreter").setup({
docker = {
service = "django",
workdir = "/code",
path_map = {
container_root = "/code",
host_root = vim.fn.getcwd(),
},
},
pyright_settings = {
python = {
analysis = {
extraPaths = { "/code/apps" },
autoSearchPaths = true,
useLibraryCodeForTypes = true,
},
},
},
auto_select = true,
prefer_docker = true,
})require("docker_python_interpreter").setup({
docker = {
service = "api",
workdir = "/app",
compose_cmd = {"docker-compose"}, -- If using older docker-compose
},
auto_select = true,
prefer_docker = false, -- Prefer local Poetry environment
})| Command | Description |
|---|---|
:SelectPythonInterpreter |
Open interpreter selection menu |
:PythonInterpreterInfo |
Show current interpreter information and health status |
:PythonInterpreterHealth |
Check and display health status |
:RestartPyright |
Restart Pyright with current interpreter |
- Open your Python project in Neovim
- Run
:SelectPythonInterpreterto choose your interpreter - Select from options:
- Docker container (if available and running)
- Local virtual environments (auto-discovered)
- System Python
- Manual path entry
- Start coding! Pyright will now work correctly with your chosen environment
When auto_select is enabled, the plugin uses this priority:
- If
prefer_dockeris true and Docker is available โ Use Docker - If only one local venv exists and Docker is unavailable โ Use that venv
- If no local venv exists but Docker is available โ Use Docker
- Otherwise โ Manual selection required
When using Pyright in a Docker container, file paths don't match:
- Host:
/home/user/myproject/main.py - Container:
/srv/app/main.py
This breaks LSP features like go-to-definition, diagnostics, and auto-imports.
The plugin creates a Python shim that acts as a transparent proxy between Neovim and Pyright:
Neovim โโ [Path Translation Shim] โโ Pyright (in Docker)
The shim:
- Intercepts all JSON-RPC messages
- Rewrites file paths in both directions
- Maintains full LSP protocol compatibility
- Handles all edge cases (URIs, workspace folders, etc.)
# Set environment variable before starting Neovim
export DEBUG_DOCKER_PYTHON=1
nvimCheck the shim log:
tail -f /tmp/pyright_shim.logSolution: Start your Docker container first:
docker compose up -dSolution: Either:
- Enable
auto_install_pyright = truein config - Manually install in container:
docker compose exec web pip install pyright
Solution: Create a virtual environment:
python -m venv .venv
# or
poetry install
# or
pipenv installSolution: Check your path mapping configuration:
docker = {
path_map = {
container_root = "/actual/container/path", -- Must match your Docker mount
host_root = vim.fn.getcwd(), -- Must be your project root
},
}Run :PythonInterpreterHealth to see detailed status:
Health: healthy
{
details = {},
status = "healthy",
timestamp = 1234567890
}
Possible statuses:
healthy: Everything workingdegraded: Working with minor issuesunhealthy: Critical problemsunconfigured: No interpreter selected
.
โโโ lua/
โ โโโ docker_python_interpreter.lua # Main plugin code
โโโ .nvim/
โ โโโ docker_pyright_shim.py # Auto-generated path translation shim
โโโ README.md
โโโ LICENSE
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Clone your fork
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a PR
# If tests are available
make testMIT License - see LICENSE file for details
- Original concept inspired by the need for better Docker integration in Neovim
- Thanks to the Neovim and nvim-lspconfig maintainers
- The Python LSP community for Pyright
- Support for multiple containers simultaneously
- Integration with devcontainers
- Support for other Python LSP servers (pylsp, jedi-language-server)
- Automatic interpreter switching based on project
- GUI picker using Telescope
- Support for remote Docker hosts
- Integration with DAP (Debug Adapter Protocol)
- Issues: GitHub Issues
- Discussions: GitHub Discussions
If you find this plugin useful, please consider giving it a star on GitHub!
Made with โค๏ธ for the Neovim community