Last active
February 15, 2024 14:05
-
-
Save Trapez/58d1526f7c06584af99e08709069f54d to your computer and use it in GitHub Desktop.
Spacemacs python configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spacemacs python | |
Configure python layer. | |
(python :variables | |
python-lsp-backend 'lsp | |
python-lsp-server 'pyright | |
python-fill-column 99 | |
python-formatter 'black | |
python-format-on-save t | |
python-test-runner 'pytest | |
python-sort-imports-on-save t | |
python-pipenv-activate t) | |
Create virtualenv with pipenv. | |
ptvsd is the dap debugger, optional. | |
Using a specific version of black since pipenv doesn't like prerelease versions. | |
Having the virtualenv inside the project folder. | |
export PIPENV_VENV_IN_PROJECT=1 | |
mkdir project && cd project && pipenv install --dev epc importmagic isort ipython flake8 pylint autoflake pytest "black==21.7b0" ptvsd | |
If the virtualenv is not inside the project folder there are two options. | |
1. Sym. link to the full virtualenv path. | |
ln -s /home/trap/.local/share/virtualenvs/project-lioCfIOB/ /home/trap/work/project/.venv | |
2. Have a file called .venv containing the full path to the virtualenv. | |
echo "/home/trap/.local/share/virtualenvs/project-lioCfIOB/" > /home/trap/work/project/.venv | |
Optionally, configure flycheck-checker. | |
Setting flake8 as the first checker, then pylint only if flake8 reports no errors. Turn off lsp-diagnostics since it overwrites flycheck-checker with lsp as the checker. | |
.dir-locals.el inside project folder. | |
;;; Directory Local Variables | |
;;; For more information see (info "(emacs) Directory Variables") | |
((python-mode . ((flycheck-checker . python-flake8) | |
(eval . (flycheck-add-next-checker 'python-flake8 '(warning . python-pylint))) | |
(lsp-diagnostics-disabled-modes . (python-mode))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment