Python Development Shell
This repository contains multiple Python scripts and packages. A dedicated Python development environment is provided via devenv to simplify development of these components, by providing all necessary dependencies for proper LSP support.
Entering the Python Shell
To access the Python development environment with all required dependencies:
direnv allow
devenv shell python
Or with devenv directly:
devenv shell --file devenv.nix --shell python
Included Packages
The Python shell inherits from the default development environment and adds:
Python Runtime & Tools
- python312 - Python 3.12 interpreter
- pip - Package installer
- virtualenv - Virtual environment management
- pytest - Testing framework
- black - Code formatter
- ruff - Fast Python linter
- mypy - Static type checker
Python Libraries
Libraries are organized by the components they support:
Image Compression
pillow- Image processingrich- Terminal formatting & progress barspython-magic- File type detection
Memory/Knowledge Systems
pyyaml- YAML parsingcryptography- Encryption utilitiesanyio- Async I/O framework
I/O Guardian & Networking
websockets- WebSocket protocolpystemd- Systemd D-Bus interface
Utilities
requests- HTTP library (for Lidarr plugin updates)
Development Workflow
Testing Scripts
Run pytest on project Python files:
pytest pkgs/scripts/test_image_compressor.py -v
Code Quality
Format Python code:
nix fmt -- pkgs/scripts/compressor.py
Check types with mypy:
mypy pkgs/scripts/
Running Scripts Directly
Scripts can be executed directly in the shell:
python3 pkgs/scripts/compressor.py --help
python3 docs/preprocessor/gen-options-md.py --help
Adding New Python Dependencies
To add a new Python library:
- Identify the
python312Packages.attribute in nixpkgs - Add it to the
packageslist in/persist/nix-config/flake/dev/devenv.nixunderdevenv.shells.python - Run
nix fmt flake/dev/devenv.nixto format - Test with
nix flake check - Update this documentation
Example:
# In devenv.nix, add to packages list:
python312Packages.your-new-package
Troubleshooting
ModuleNotFoundError
If you see ModuleNotFoundError: No module named 'xxx', the package may not be in the python shell. Verify it’s included in the packages list in flake/dev/devenv.nix.
Python Version Mismatch
Some packages require Python 3.12. If you need a different version:
- Modify
python312reference inflake/dev/devenv.nix - Update corresponding
python312Packagesreferences - Run
nix flake checkto validate
Permissions Errors with pystemd
The pystemd package requires D-Bus access. Ensure you’re running within a proper devenv session, not in a sandboxed environment.