README: add vscode and emacs ruff instructions

This commit is contained in:
Aleix Conchillo Flaqué
2024-09-23 09:29:02 -07:00
parent eeb8338dce
commit a4420dc88b
2 changed files with 13 additions and 15 deletions

View File

@@ -170,22 +170,24 @@ pytest --doctest-modules --ignore-glob="*to_be_updated*" --ignore-glob=*pipeline
## Setting up your editor ## Setting up your editor
This project uses strict [PEP 8](https://peps.python.org/pep-0008/) formatting. This project uses strict [PEP 8](https://peps.python.org/pep-0008/) formatting via [Ruff](https://github.com/astral-sh/ruff).
### Emacs ### Emacs
You can use [use-package](https://github.com/jwiegley/use-package) to install [py-autopep8](https://codeberg.org/ideasman42/emacs-py-autopep8) package and configure `autopep8` arguments: You can use [use-package](https://github.com/jwiegley/use-package) to install [emacs-lazy-ruff](https://github.com/christophermadsen/emacs-lazy-ruff) package and configure `ruff` arguments:
```elisp ```elisp
(use-package py-autopep8 (use-package lazy-ruff
:ensure t :ensure t
:defer t :hook ((python-mode . lazy-ruff-mode))
:hook ((python-mode . py-autopep8-mode))
:config :config
(setq py-autopep8-options '("-a" "-a", "--max-line-length=100"))) (setq lazy-ruff-format-command "ruff format --config line-length=100")
(setq lazy-ruff-only-format-block t)
(setq lazy-ruff-only-format-region t)
(setq lazy-ruff-only-format-buffer t))
``` ```
`autopep8` was installed in the `venv` environment described before, so you should be able to use [pyvenv-auto](https://github.com/ryotaro612/pyvenv-auto) to automatically load that environment inside Emacs. `ruff` was installed in the `venv` environment described before, so you should be able to use [pyvenv-auto](https://github.com/ryotaro612/pyvenv-auto) to automatically load that environment inside Emacs.
```elisp ```elisp
(use-package pyvenv-auto (use-package pyvenv-auto
@@ -198,18 +200,14 @@ You can use [use-package](https://github.com/jwiegley/use-package) to install [p
### Visual Studio Code ### Visual Studio Code
Install the Install the
[autopep8](https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8) extension. Then edit the user settings (_Ctrl-Shift-P_ `Open User Settings (JSON)`) and set it as the default Python formatter, enable formatting on save and configure `autopep8` arguments: [Ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) extension. Then edit the user settings (_Ctrl-Shift-P_ `Open User Settings (JSON)`) and set it as the default Python formatter, enable formatting on save and configure `ruff` arguments:
```json ```json
"[python]": { "[python]": {
"editor.defaultFormatter": "ms-python.autopep8", "editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true "editor.formatOnSave": true
}, },
"autopep8.args": [ "ruff.format.args": ["--config", "line-length=100"]
"-a",
"-a",
"--max-line-length=100"
],
``` ```
## Getting help ## Getting help

View File

@@ -3,6 +3,6 @@ grpcio-tools~=1.62.2
pip-tools~=7.4.1 pip-tools~=7.4.1
pyright~=1.1.376 pyright~=1.1.376
pytest~=8.3.2 pytest~=8.3.2
ruff~=0.6.6 ruff~=0.6.7
setuptools~=72.2.0 setuptools~=72.2.0
setuptools_scm~=8.1.0 setuptools_scm~=8.1.0