Python Development in Emacs

创建虚拟环境#

cd /path/to/project
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

安装LSP服务端#

Pyright is a full-featured, standards-based static type checker for Python. It is designed for high performance and can be used with large Python source bases.

npm install -g pyright

项目配置#

安装完Pyright后,在pyproject.toml中增加配置:

[tool.pyright]
venvPath = "."
venv = ".venv"

[tool.black]
line-length = 120

python-mode配置#

在Emacs中使用Eglot作为LSP客户端,在.dir-locals.el中增加配置:

((python-base-mode . ((python-indent-offset . 4)
                      (python-indent-guess-indent-offset-verbose . nil)
                      (python-shell-interpreter . "python")
                      (python-shell-virtualenv-root . "/path/to/project/.venv/"))))

Related

Clangd Configuration With Eglot

Eglot是Emacs内置的LSP客户端。Eglot内置已支持大量的LSP服务端。以C++语言为例,Eglot支持clangd和ccls两种服务端模式。

Matplotlib: Work with threads

Matplotlib is not thread-safe: in fact, there are known race conditions that affect certain artists.

Emacs tree-sitter

tree-sitter是一个解析器生成工具和增量解析库。它可以为源文件构建语法树,当源文件修改时可以高效的更新语法树。