yeet
This commit is contained in:
130
.config/emacs/modules/lang/python/README.org
Normal file
130
.config/emacs/modules/lang/python/README.org
Normal file
@@ -0,0 +1,130 @@
|
||||
#+TITLE: lang/python
|
||||
#+DATE: Oct, 2019
|
||||
#+SINCE: v2.0.9
|
||||
#+STARTUP: inlineimages
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#language-server-protocol-support][Language Server Protocol Support]]
|
||||
- [[#features][Features]]
|
||||
- [[#keybindings][Keybindings]]
|
||||
- [[#configuration][Configuration]]
|
||||
|
||||
* Description
|
||||
Adds Python support to Doom Emacs.
|
||||
|
||||
+ Syntax checking (~flycheck~)
|
||||
+ Snippets
|
||||
+ Run tests (~nose~, ~pytest~)
|
||||
+ Auto-format (~black~), requires ~:editor format~
|
||||
+ LSP integration (mspyls, pyls, or pyright)
|
||||
|
||||
** Module Flags
|
||||
+ ~+lsp~ Language Server Protocol support
|
||||
+ ~+pyright~ Use the pyright LSP server instead of mspyls or pyls (requires
|
||||
~+lsp~).
|
||||
+ ~+pyenv~ Python virtual environment support via [[https://github.com/pyenv/pyenv][pyenv]]
|
||||
+ ~+conda~ Python virtual environment support via [[https://conda.io/en/latest/][Conda]]
|
||||
+ ~+poetry~ Python packaging, dependency management, and virtual environment
|
||||
support via [[https://python-poetry.org/][Poetry]]
|
||||
+ ~+cython~ Cython files support via [[https://github.com/cython/cython/blob/master/Tools/cython-mode.el][cython-mode]]
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/pythonic-emacs/anaconda-mode][anaconda-mode]]*
|
||||
+ [[https://github.com/Wilfred/pyimport][pyimport]]*
|
||||
+ [[https://github.com/paetzke/py-isort.el][py-isort]]*
|
||||
+ [[https://github.com/emacsattic/nose/][nose]]*
|
||||
+ [[https://github.com/wbolster/emacs-python-pytest][python-pytest]]*
|
||||
+ [[https://github.com/Wilfred/pip-requirements.el][pip-requirements]]*
|
||||
+ [[https://github.com/pwalsh/pipenv.el][pipenv]]*
|
||||
+ if ~+conda~
|
||||
+ [[https://github.com/necaris/conda.el][conda]]*
|
||||
+ if ~+pyenv~
|
||||
+ [[https://github.com/pythonic-emacs/pyenv-mode][pyenv]]*
|
||||
+ if ~+poetry~
|
||||
+ [[https://github.com/galaunay/poetry.el][poetry]]*
|
||||
+ if ~+lsp~ and ~:tools lsp~
|
||||
+ [[https://github.com/emacs-lsp/lsp-mode][lsp]]
|
||||
+ if ~+pyright~
|
||||
+ [[https://github.com/emacs-lsp/lsp-pyright][lsp-pyright]]
|
||||
+ else
|
||||
+ [[https://github.com/emacs-lsp/lsp-python-ms][lsp-python-ms]]
|
||||
+ if ~+cython~
|
||||
+ [[https://github.com/cython/cython/blob/master/Tools/cython-mode.el][cython-mode]]
|
||||
+ if ~:checkers syntax~: [[https://github.com/lbolla/emacs-flycheck-cython/tree/master][flycheck-cython]]
|
||||
|
||||
* Prerequisites
|
||||
This module has no hard prerequisites, but a few soft ones:
|
||||
|
||||
+ For this module's supported test runners:
|
||||
+ ~pip install pytest~
|
||||
+ ~pip install nose~
|
||||
+ The ~:editor format~ module uses [[https://github.com/psf/black][Black]] for python files :: ~pip install black~
|
||||
+ ~pyimport~ requires Python's module ~pyflakes~ :: ~pip install pyflakes~
|
||||
+ ~py-isort~ requires [[https://github.com/timothycrosley/isort][isort]] to be installed :: ~pip install isort~
|
||||
+ Python virtual environments install instructions at:
|
||||
+ [[https://github.com/pyenv/pyenv][pyenv]]
|
||||
+ [[https://conda.io/en/latest/][Conda]]
|
||||
+ [[https://python-poetry.org/][Poetry]]
|
||||
+ [[https://pipenv.readthedocs.io/en/latest/][pipenv]]
|
||||
+ ~cython~ requires [[https://cython.org/][Cython]]
|
||||
|
||||
** Language Server Protocol Support
|
||||
For LSP support the =:tools lsp= module must be enabled, along with this
|
||||
module's =+lsp= flag. By default, it supports =mspyls= and =pyls=, in that
|
||||
order. With the =+pyright= flag, it will try Pyright first.
|
||||
|
||||
Each of these servers must be installed on your system via your OS package
|
||||
manager or manually:
|
||||
|
||||
+ [[https://pypi.org/project/python-language-server/][*pyls*]] can be installed with ~pip install python-language-server[all]~.
|
||||
+ *mspyls* can be installed by typing =M-x lsp-install-server RET mspyls=.
|
||||
+ *pyright* can be installed with ~pip install pyright~ or ~npm i -g pyright~.
|
||||
|
||||
* Features
|
||||
This module supports LSP. It requires installation of [[https://pypi.org/project/python-language-server/][Python Language
|
||||
Server]], [[https://github.com/Microsoft/python-language-server][Microsoft Language Server]], or [[https://github.com/microsoft/pyright][pyright]], see [[Language Server Protocol Support][LSP Support]].
|
||||
|
||||
To enable support for auto-formatting with black enable ~:editor format~ in
|
||||
~init.el~ file.
|
||||
|
||||
** Keybindings
|
||||
|
||||
| Binding | Description |
|
||||
|---------------------+----------------------------------|
|
||||
| ~<localleader> c c~ | ~Compile Cython buffer~ |
|
||||
| ~<localleader> i i~ | ~Insert mising imports~ |
|
||||
| ~<localleader> i r~ | ~Remove unused imports~ |
|
||||
| ~<localleader> i s~ | ~Sort imports~ |
|
||||
| ~<localleader> i o~ | ~Optimize imports~ |
|
||||
| ~<localleader> t r~ | ~nosetests-again~ |
|
||||
| ~<localleader> t a~ | ~nosetests-all~ |
|
||||
| ~<localleader> t s~ | ~nosetests-one~ |
|
||||
| ~<localleader> t v~ | ~nosetests-module~ |
|
||||
| ~<localleader> t A~ | ~nosetests-pdb-all~ |
|
||||
| ~<localleader> t O~ | ~nosetests-pdb-one~ |
|
||||
| ~<localleader> t V~ | ~nosetests-pdb-module~ |
|
||||
| ~<localleader> t f~ | ~python-pytest-file~ |
|
||||
| ~<localleader> t k~ | ~python-pytest-file-dwim~ |
|
||||
| ~<localleader> t t~ | ~python-pytest-function~ |
|
||||
| ~<localleader> t m~ | ~python-pytest-function-dwim~ |
|
||||
| ~<localleader> t r~ | ~python-pytest-repeat~ |
|
||||
| ~<localleader> t p~ | ~python-pytest-popup~ |
|
||||
| ~<localleader> g d~ | ~anaconda-mode-find-definitions~ |
|
||||
| ~<localleader> g h~ | ~anaconda-mode-show-doc~ |
|
||||
| ~<localleader> g a~ | ~anaconda-mode-find-assignments~ |
|
||||
| ~<localleader> g f~ | ~anaconda-mode-find-file~ |
|
||||
| ~<localleader> g u~ | ~anaconda-mode-find-references~ |
|
||||
|
||||
* Configuration
|
||||
This module has the following variables to set extra arguments to [[https://ipython.org/][ipython]] and
|
||||
[[https://jupyter.org/][jupyter]] shells:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
;; ~/.doom.d/config.el
|
||||
(setq +python-ipython-repl-args '("-i" "--simple-prompt" "--no-color-info"))
|
||||
(setq +python-jupyter-repl-args '("--simple-prompt"))
|
||||
#+END_SRC
|
||||
17
.config/emacs/modules/lang/python/autoload/conda.el
Normal file
17
.config/emacs/modules/lang/python/autoload/conda.el
Normal file
@@ -0,0 +1,17 @@
|
||||
;;; lang/python/autoload/conda.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +conda)
|
||||
|
||||
;;;###autoload
|
||||
(defun +python/set-conda-home ()
|
||||
"Set `conda-anaconda-home' (ANACONDA_HOME).
|
||||
|
||||
Usually it's `~/.anaconda3' on local machine, but it can be set to a remote
|
||||
directory using TRAMP syntax, e.g. `/ssh:host:/usr/bin/anaconda3'. This way, you
|
||||
can use a remote conda environment, including the corresponding remote python
|
||||
executable and packages."
|
||||
(interactive)
|
||||
(require 'conda)
|
||||
(when-let (home (read-directory-name "Set conda home: " "~" nil nil conda-anaconda-home))
|
||||
(setq conda-anaconda-home home)
|
||||
(message "Successfully changed conda home to: %s" (abbreviate-file-name home))))
|
||||
|
||||
30
.config/emacs/modules/lang/python/autoload/pyenv.el
Normal file
30
.config/emacs/modules/lang/python/autoload/pyenv.el
Normal file
@@ -0,0 +1,30 @@
|
||||
;;; lang/python/autoload/pyenv.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +pyenv)
|
||||
|
||||
;;;###autoload
|
||||
(defvar +pyenv--version nil)
|
||||
|
||||
;;;###autoload
|
||||
(defun +python-pyenv-mode-set-auto-h ()
|
||||
"Set pyenv-mode version from buffer-local variable."
|
||||
(when (eq major-mode 'python-mode)
|
||||
(when (not (local-variable-p '+pyenv--version))
|
||||
(make-local-variable '+pyenv--version)
|
||||
(setq +pyenv--version (+python-pyenv-read-version-from-file)))
|
||||
(if +pyenv--version
|
||||
(pyenv-mode-set +pyenv--version)
|
||||
(pyenv-mode-unset))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +python-pyenv-read-version-from-file ()
|
||||
"Read pyenv version from .python-version file."
|
||||
(when-let (root-path (projectile-locate-dominating-file default-directory ".python-version"))
|
||||
(let* ((file-path (expand-file-name ".python-version" root-path))
|
||||
(version
|
||||
(with-temp-buffer
|
||||
(insert-file-contents-literally file-path)
|
||||
(string-trim (buffer-string)))))
|
||||
(if (member version (pyenv-mode-versions))
|
||||
version ;; return.
|
||||
(message "pyenv: version `%s' is not installed (set by `%s')."
|
||||
version file-path)))))
|
||||
73
.config/emacs/modules/lang/python/autoload/python.el
Normal file
73
.config/emacs/modules/lang/python/autoload/python.el
Normal file
@@ -0,0 +1,73 @@
|
||||
;;; lang/python/autoload/python.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +python-executable-find (exe)
|
||||
"Resolve the path to the EXE executable.
|
||||
Tries to be aware of your active conda/pipenv/virtualenv environment, before
|
||||
falling back on searching your PATH."
|
||||
(if (file-name-absolute-p exe)
|
||||
(and (file-executable-p exe)
|
||||
exe)
|
||||
(let ((exe-root (format "bin/%s" exe)))
|
||||
(cond ((when python-shell-virtualenv-root
|
||||
(let ((bin (expand-file-name exe-root python-shell-virtualenv-root)))
|
||||
(if (file-exists-p bin) bin))))
|
||||
((when (require 'conda nil t)
|
||||
(let ((bin (expand-file-name (concat conda-env-current-name "/" exe-root)
|
||||
(conda-env-default-location))))
|
||||
(if (file-executable-p bin) bin))))
|
||||
((when-let (bin (projectile-locate-dominating-file default-directory "bin/python"))
|
||||
(setq-local doom-modeline-python-executable (expand-file-name "bin/python" bin))))
|
||||
((executable-find exe))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +python/open-repl ()
|
||||
"Open the Python REPL."
|
||||
(interactive)
|
||||
(require 'python)
|
||||
(unless python-shell-interpreter
|
||||
(user-error "`python-shell-interpreter' isn't set"))
|
||||
(pop-to-buffer
|
||||
(process-buffer
|
||||
(if-let* ((pipenv (+python-executable-find "pipenv"))
|
||||
(pipenv-project (pipenv-project-p)))
|
||||
(let ((default-directory pipenv-project)
|
||||
(python-shell-interpreter-args
|
||||
(format "run %s %s"
|
||||
python-shell-interpreter
|
||||
python-shell-interpreter-args))
|
||||
(python-shell-interpreter pipenv))
|
||||
(run-python nil nil t))
|
||||
(run-python nil nil t)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +python/open-ipython-repl ()
|
||||
"Open an IPython REPL."
|
||||
(interactive)
|
||||
(require 'python)
|
||||
(let ((python-shell-interpreter
|
||||
(or (+python-executable-find (car +python-ipython-command))
|
||||
"ipython"))
|
||||
(python-shell-interpreter-args
|
||||
(string-join (cdr +python-ipython-command) " ")))
|
||||
(+python/open-repl)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +python/open-jupyter-repl ()
|
||||
"Open a Jupyter console."
|
||||
(interactive)
|
||||
(require 'python)
|
||||
(add-to-list 'python-shell-completion-native-disabled-interpreters "jupyter")
|
||||
(let ((python-shell-interpreter
|
||||
(or (+python-executable-find (car +python-jupyter-command))
|
||||
"jupyter"))
|
||||
(python-shell-interpreter-args
|
||||
(string-join (cdr +python-jupyter-command) " ")))
|
||||
(+python/open-repl)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +python/optimize-imports ()
|
||||
"organize imports"
|
||||
(interactive)
|
||||
(pyimport-remove-unused)
|
||||
(py-isort-buffer))
|
||||
339
.config/emacs/modules/lang/python/config.el
Normal file
339
.config/emacs/modules/lang/python/config.el
Normal file
@@ -0,0 +1,339 @@
|
||||
;;; lang/python/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +python-ipython-command '("ipython" "-i" "--simple-prompt" "--no-color-info")
|
||||
"Command to initialize the ipython REPL for `+python/open-ipython-repl'.")
|
||||
|
||||
(defvar +python-jupyter-command '("jupyter" "console" "--simple-prompt")
|
||||
"Command to initialize the jupyter REPL for `+python/open-jupyter-repl'.")
|
||||
|
||||
(after! projectile
|
||||
(pushnew! projectile-project-root-files "setup.py" "requirements.txt"))
|
||||
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(use-package! python
|
||||
:mode ("[./]flake8\\'" . conf-mode)
|
||||
:mode ("/Pipfile\\'" . conf-mode)
|
||||
:init
|
||||
(setq python-environment-directory doom-cache-dir
|
||||
python-indent-guess-indent-offset-verbose nil)
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(add-hook 'python-mode-local-vars-hook #'lsp!)
|
||||
;; Use "mspyls" in eglot if in PATH
|
||||
(when (executable-find "Microsoft.Python.LanguageServer")
|
||||
(set-eglot-client! 'python-mode '("Microsoft.Python.LanguageServer"))))
|
||||
:config
|
||||
(set-repl-handler! 'python-mode #'+python/open-repl
|
||||
:persist t
|
||||
:send-region #'python-shell-send-region
|
||||
:send-buffer #'python-shell-send-buffer)
|
||||
(set-docsets! '(python-mode inferior-python-mode) "Python 3" "NumPy" "SciPy" "Pandas")
|
||||
|
||||
(set-ligatures! 'python-mode
|
||||
;; Functional
|
||||
:def "def"
|
||||
:lambda "lambda"
|
||||
;; Types
|
||||
:null "None"
|
||||
:true "True" :false "False"
|
||||
:int "int" :str "str"
|
||||
:float "float"
|
||||
:bool "bool"
|
||||
:tuple "tuple"
|
||||
;; Flow
|
||||
:not "not"
|
||||
:in "in" :not-in "not in"
|
||||
:and "and" :or "or"
|
||||
:for "for"
|
||||
:return "return" :yield "yield")
|
||||
|
||||
;; Stop the spam!
|
||||
(setq python-indent-guess-indent-offset-verbose nil)
|
||||
|
||||
;; Default to Python 3. Prefer the versioned Python binaries since some
|
||||
;; systems stupidly make the unversioned one point at Python 2.
|
||||
(when (and (executable-find "python3")
|
||||
(string= python-shell-interpreter "python"))
|
||||
(setq python-shell-interpreter "python3"))
|
||||
|
||||
(add-hook! 'python-mode-hook
|
||||
(defun +python-use-correct-flycheck-executables-h ()
|
||||
"Use the correct Python executables for Flycheck."
|
||||
(let ((executable python-shell-interpreter))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(save-match-data
|
||||
(when (or (looking-at "#!/usr/bin/env \\(python[^ \n]+\\)")
|
||||
(looking-at "#!\\([^ \n]+/python[^ \n]+\\)"))
|
||||
(setq executable (substring-no-properties (match-string 1))))))
|
||||
;; Try to compile using the appropriate version of Python for
|
||||
;; the file.
|
||||
(setq-local flycheck-python-pycompile-executable executable)
|
||||
;; We might be running inside a virtualenv, in which case the
|
||||
;; modules won't be available. But calling the executables
|
||||
;; directly will work.
|
||||
(setq-local flycheck-python-pylint-executable "pylint")
|
||||
(setq-local flycheck-python-flake8-executable "flake8"))))
|
||||
|
||||
(define-key python-mode-map (kbd "DEL") nil) ; interferes with smartparens
|
||||
(sp-local-pair 'python-mode "'" nil
|
||||
:unless '(sp-point-before-word-p
|
||||
sp-point-after-word-p
|
||||
sp-point-before-same-p))
|
||||
|
||||
;; Affects pyenv and conda
|
||||
(when (featurep! :ui modeline)
|
||||
(advice-add #'pythonic-activate :after-while #'+modeline-update-env-in-all-windows-h)
|
||||
(advice-add #'pythonic-deactivate :after #'+modeline-clear-env-in-all-windows-h))
|
||||
|
||||
(setq-hook! 'python-mode-hook tab-width python-indent-offset))
|
||||
|
||||
|
||||
(use-package! anaconda-mode
|
||||
:defer t
|
||||
:init
|
||||
(setq anaconda-mode-installation-directory (concat doom-etc-dir "anaconda/")
|
||||
anaconda-mode-eldoc-as-single-line t)
|
||||
|
||||
(add-hook! 'python-mode-local-vars-hook :append
|
||||
(defun +python-init-anaconda-mode-maybe-h ()
|
||||
"Enable `anaconda-mode' if `lsp-mode' is absent and
|
||||
`python-shell-interpreter' is present."
|
||||
(unless (or (bound-and-true-p lsp-mode)
|
||||
(bound-and-true-p eglot--managed-mode)
|
||||
(bound-and-true-p lsp--buffer-deferred)
|
||||
(not (executable-find python-shell-interpreter t)))
|
||||
(anaconda-mode +1))))
|
||||
:config
|
||||
(set-company-backend! 'anaconda-mode '(company-anaconda))
|
||||
(set-lookup-handlers! 'anaconda-mode
|
||||
:definition #'anaconda-mode-find-definitions
|
||||
:references #'anaconda-mode-find-references
|
||||
:documentation #'anaconda-mode-show-doc)
|
||||
(set-popup-rule! "^\\*anaconda-mode" :select nil)
|
||||
|
||||
(add-hook 'anaconda-mode-hook #'anaconda-eldoc-mode)
|
||||
|
||||
(defun +python-auto-kill-anaconda-processes-h ()
|
||||
"Kill anaconda processes if this buffer is the last python buffer."
|
||||
(when (and (eq major-mode 'python-mode)
|
||||
(not (delq (current-buffer)
|
||||
(doom-buffers-in-mode 'python-mode (buffer-list)))))
|
||||
(anaconda-mode-stop)))
|
||||
(add-hook! 'python-mode-hook
|
||||
(add-hook 'kill-buffer-hook #'+python-auto-kill-anaconda-processes-h
|
||||
nil 'local))
|
||||
|
||||
(when (featurep 'evil)
|
||||
(add-hook 'anaconda-mode-hook #'evil-normalize-keymaps))
|
||||
(map! :localleader
|
||||
:map anaconda-mode-map
|
||||
:prefix "g"
|
||||
"d" #'anaconda-mode-find-definitions
|
||||
"h" #'anaconda-mode-show-doc
|
||||
"a" #'anaconda-mode-find-assignments
|
||||
"f" #'anaconda-mode-find-file
|
||||
"u" #'anaconda-mode-find-references))
|
||||
|
||||
|
||||
(use-package! pyimport
|
||||
:defer t
|
||||
:init
|
||||
(map! :after python
|
||||
:map python-mode-map
|
||||
:localleader
|
||||
(:prefix ("i" . "imports")
|
||||
:desc "Insert missing imports" "i" #'pyimport-insert-missing
|
||||
:desc "Remove unused imports" "r" #'pyimport-remove-unused
|
||||
:desc "Optimize imports" "o" #'+python/optimize-imports)))
|
||||
|
||||
|
||||
(use-package! py-isort
|
||||
:defer t
|
||||
:init
|
||||
(map! :after python
|
||||
:map python-mode-map
|
||||
:localleader
|
||||
(:prefix ("i" . "imports")
|
||||
:desc "Sort imports" "s" #'py-isort-buffer
|
||||
:desc "Sort region" "r" #'py-isort-region)))
|
||||
|
||||
(use-package! nose
|
||||
:commands nose-mode
|
||||
:preface (defvar nose-mode-map (make-sparse-keymap))
|
||||
:minor ("/test_.+\\.py$" . nose-mode)
|
||||
:config
|
||||
(set-popup-rule! "^\\*nosetests" :size 0.4 :select nil)
|
||||
(set-yas-minor-mode! 'nose-mode)
|
||||
(when (featurep 'evil)
|
||||
(add-hook 'nose-mode-hook #'evil-normalize-keymaps))
|
||||
|
||||
(map! :localleader
|
||||
:map nose-mode-map
|
||||
:prefix "t"
|
||||
"r" #'nosetests-again
|
||||
"a" #'nosetests-all
|
||||
"s" #'nosetests-one
|
||||
"v" #'nosetests-module
|
||||
"A" #'nosetests-pdb-all
|
||||
"O" #'nosetests-pdb-one
|
||||
"V" #'nosetests-pdb-module))
|
||||
|
||||
|
||||
(use-package! python-pytest
|
||||
:commands python-pytest-dispatch
|
||||
:init
|
||||
(map! :after python
|
||||
:localleader
|
||||
:map python-mode-map
|
||||
:prefix ("t" . "test")
|
||||
"a" #'python-pytest
|
||||
"f" #'python-pytest-file-dwim
|
||||
"F" #'python-pytest-file
|
||||
"t" #'python-pytest-function-dwim
|
||||
"T" #'python-pytest-function
|
||||
"r" #'python-pytest-repeat
|
||||
"p" #'python-pytest-dispatch))
|
||||
|
||||
|
||||
;;
|
||||
;;; Environment management
|
||||
|
||||
(use-package! pipenv
|
||||
:commands pipenv-project-p
|
||||
:hook (python-mode . pipenv-mode)
|
||||
:init (setq pipenv-with-projectile nil)
|
||||
:config
|
||||
(set-eval-handler! 'python-mode
|
||||
'((:command . (lambda () python-shell-interpreter))
|
||||
(:exec (lambda ()
|
||||
(if-let* ((bin (executable-find "pipenv" t))
|
||||
(_ (pipenv-project-p)))
|
||||
(format "PIPENV_MAX_DEPTH=9999 %s run %%c %%o %%s %%a" bin)
|
||||
"%c %o %s %a")))
|
||||
(:description . "Run Python script")))
|
||||
(map! :map python-mode-map
|
||||
:localleader
|
||||
:prefix "e"
|
||||
:desc "activate" "a" #'pipenv-activate
|
||||
:desc "deactivate" "d" #'pipenv-deactivate
|
||||
:desc "install" "i" #'pipenv-install
|
||||
:desc "lock" "l" #'pipenv-lock
|
||||
:desc "open module" "o" #'pipenv-open
|
||||
:desc "run" "r" #'pipenv-run
|
||||
:desc "shell" "s" #'pipenv-shell
|
||||
:desc "uninstall" "u" #'pipenv-uninstall))
|
||||
|
||||
|
||||
(use-package! pyvenv
|
||||
:after python
|
||||
:init
|
||||
(when (featurep! :ui modeline)
|
||||
(add-hook 'pyvenv-post-activate-hooks #'+modeline-update-env-in-all-windows-h)
|
||||
(add-hook 'pyvenv-pre-deactivate-hooks #'+modeline-clear-env-in-all-windows-h))
|
||||
:config
|
||||
(add-hook 'python-mode-local-vars-hook #'pyvenv-track-virtualenv)
|
||||
(add-to-list 'global-mode-string
|
||||
'(pyvenv-virtual-env-name (" venv:" pyvenv-virtual-env-name " "))
|
||||
'append))
|
||||
|
||||
|
||||
|
||||
(use-package! pyenv-mode
|
||||
:when (featurep! +pyenv)
|
||||
:after python
|
||||
:config
|
||||
(when (executable-find "pyenv")
|
||||
(pyenv-mode +1)
|
||||
(add-to-list 'exec-path (expand-file-name "shims" (or (getenv "PYENV_ROOT") "~/.pyenv"))))
|
||||
(add-hook 'python-mode-local-vars-hook #'+python-pyenv-mode-set-auto-h)
|
||||
(add-hook 'doom-switch-buffer-hook #'+python-pyenv-mode-set-auto-h))
|
||||
|
||||
|
||||
(use-package! conda
|
||||
:when (featurep! +conda)
|
||||
:after python
|
||||
:config
|
||||
;; The location of your anaconda home will be guessed from a list of common
|
||||
;; possibilities, starting with `conda-anaconda-home''s default value (which
|
||||
;; will consult a ANACONDA_HOME envvar, if it exists).
|
||||
;;
|
||||
;; If none of these work for you, `conda-anaconda-home' must be set
|
||||
;; explicitly. Afterwards, run M-x `conda-env-activate' to switch between
|
||||
;; environments
|
||||
(or (cl-loop for dir in (list conda-anaconda-home
|
||||
"~/.anaconda"
|
||||
"~/.miniconda"
|
||||
"~/.miniconda3"
|
||||
"~/.miniforge3"
|
||||
"~/anaconda3"
|
||||
"~/miniconda3"
|
||||
"~/miniforge3"
|
||||
"~/opt/miniconda3"
|
||||
"/usr/bin/anaconda3"
|
||||
"/usr/local/anaconda3"
|
||||
"/usr/local/miniconda3"
|
||||
"/usr/local/Caskroom/miniconda/base")
|
||||
if (file-directory-p dir)
|
||||
return (setq conda-anaconda-home (expand-file-name dir)
|
||||
conda-env-home-directory (expand-file-name dir)))
|
||||
(message "Cannot find Anaconda installation"))
|
||||
|
||||
;; integration with term/eshell
|
||||
(conda-env-initialize-interactive-shells)
|
||||
(after! eshell (conda-env-initialize-eshell))
|
||||
|
||||
(add-to-list 'global-mode-string
|
||||
'(conda-env-current-name (" conda:" conda-env-current-name " "))
|
||||
'append))
|
||||
|
||||
|
||||
(use-package! poetry
|
||||
:when (featurep! +poetry)
|
||||
:after python
|
||||
:init
|
||||
(setq poetry-tracking-strategy 'switch-buffer)
|
||||
(add-hook 'python-mode-hook #'poetry-tracking-mode))
|
||||
|
||||
|
||||
(use-package! cython-mode
|
||||
:when (featurep! +cython)
|
||||
:mode "\\.p\\(yx\\|x[di]\\)\\'"
|
||||
:config
|
||||
(setq cython-default-compile-format "cython -a %s")
|
||||
(map! :map cython-mode-map
|
||||
:localleader
|
||||
:prefix "c"
|
||||
:desc "Cython compile buffer" "c" #'cython-compile))
|
||||
|
||||
|
||||
(use-package! flycheck-cython
|
||||
:when (featurep! +cython)
|
||||
:when (featurep! :checkers syntax)
|
||||
:after cython-mode)
|
||||
|
||||
|
||||
;;
|
||||
;;; LSP
|
||||
|
||||
(eval-when! (and (featurep! +lsp)
|
||||
(not (featurep! :tools lsp +eglot)))
|
||||
|
||||
(use-package! lsp-python-ms
|
||||
:unless (featurep! +pyright)
|
||||
:after lsp-mode
|
||||
:preface
|
||||
(after! python
|
||||
(setq lsp-python-ms-python-executable-cmd python-shell-interpreter)))
|
||||
|
||||
(use-package! lsp-pyright
|
||||
:when (featurep! +pyright)
|
||||
:after lsp-mode))
|
||||
|
||||
(eval-when! (and (featurep! +pyright)
|
||||
(featurep! :tools lsp +eglot))
|
||||
(after! eglot
|
||||
(add-to-list 'eglot-server-programs '(python-mode . ("pyright-langserver" "--stdio")))))
|
||||
53
.config/emacs/modules/lang/python/doctor.el
Normal file
53
.config/emacs/modules/lang/python/doctor.el
Normal file
@@ -0,0 +1,53 @@
|
||||
;;; lang/python/doctor.el -*- lexical-binding: t; -*-
|
||||
|
||||
(assert! (or (not (featurep! +lsp))
|
||||
(featurep! :tools lsp))
|
||||
"This module requires (:tools lsp)")
|
||||
|
||||
(if (not (or (executable-find "python")
|
||||
(executable-find "python3")))
|
||||
(error! "Couldn't find python in your PATH")
|
||||
(unless (featurep! +lsp)
|
||||
(unless (or (zerop (shell-command "python -c 'import setuptools'"))
|
||||
(zerop (shell-command "python3 -c 'import setuptools'")))
|
||||
(warn! "setuptools wasn't detected, which anaconda-mode requires"))))
|
||||
|
||||
(when (featurep! +pyenv)
|
||||
(if (not (executable-find "pyenv"))
|
||||
(warn! "Couldn't find pyenv in your PATH")
|
||||
(unless (split-string (shell-command-to-string "pyenv versions --bare") "\n" t)
|
||||
(warn! "No versions of python are available via pyenv, did you forget to install one?"))))
|
||||
|
||||
(when (featurep! +conda)
|
||||
(unless (executable-find "conda")
|
||||
(warn! "Couldn't find conda in your PATH")))
|
||||
|
||||
(when (featurep! +poetry)
|
||||
(if (not (executable-find "poetry"))
|
||||
(warn! "Couldn't find poetry in your PATH")))
|
||||
|
||||
(when (featurep! +cython)
|
||||
(unless (executable-find "cython")
|
||||
(warn! "Couldn't find cython. cython-mode will not work.")))
|
||||
|
||||
(when (featurep! +ipython)
|
||||
(unless (executable-find "ipython")
|
||||
(warn! "Couldn't find ipython in your PATH")))
|
||||
|
||||
(unless (executable-find "pytest")
|
||||
(warn! "Couldn't find pytest. Running tests through pytest will not work."))
|
||||
|
||||
(unless (executable-find "nosetests")
|
||||
(warn! "Couldn't find nosetests. Running tests through nose will not work."))
|
||||
|
||||
(unless (executable-find "pipenv")
|
||||
(warn! "Couldn't find pipenv. pipenv support will not work."))
|
||||
|
||||
(unless (executable-find "isort")
|
||||
(warn! "Couldn't find isort. Import sorting will not work."))
|
||||
|
||||
(when (featurep! :editor format)
|
||||
(unless (executable-find "pyflakes")
|
||||
(warn! "Couldn't find pyflakes. Import management will not work."))
|
||||
(unless (executable-find "black")
|
||||
(warn! "Couldn't find black. Code formatting will not work.")))
|
||||
39
.config/emacs/modules/lang/python/packages.el
Normal file
39
.config/emacs/modules/lang/python/packages.el
Normal file
@@ -0,0 +1,39 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/python/packages.el
|
||||
|
||||
;; Major modes
|
||||
(package! pip-requirements :pin "216cd1690f80cc965d4ae47b8753fc185f778ff6")
|
||||
(when (featurep! +cython)
|
||||
(package! cython-mode :pin "5b325c98609a11e89c2d14f52afba25744a79379")
|
||||
(when (featurep! :checkers syntax)
|
||||
(package! flycheck-cython :pin "ecc4454d35ab5317ab66a04406f36f0c1dbc0b76")))
|
||||
|
||||
;; LSP
|
||||
(when (featurep! +lsp)
|
||||
(unless (featurep! :tools lsp +eglot)
|
||||
(if (featurep! +pyright)
|
||||
(package! lsp-pyright :pin "d428dbcf1802fbe147271c8dc74b073bd9cd7403")
|
||||
(package! lsp-python-ms :pin "abf4d89ecf2fa0871130df5fce6065b7cf0a2721"))))
|
||||
|
||||
;; Programming environment
|
||||
(package! anaconda-mode :pin "cbea0fb3182321d34ff93981c5a59f8dd72d82a5")
|
||||
(when (featurep! :completion company)
|
||||
(package! company-anaconda :pin "da1566db41a68809ef7f91ebf2de28118067c89b"))
|
||||
|
||||
;; Environment management
|
||||
(package! pipenv :pin "8f50c68d415307a2cbc65cc4df20df18e1776e9b")
|
||||
(package! pyvenv :pin "31ea715f2164dd611e7fc77b26390ef3ca93509b")
|
||||
(when (featurep! +pyenv)
|
||||
(package! pyenv-mode :pin "b818901b8eac0e260ced66a6a5acabdbf6f5ba99"))
|
||||
(when (featurep! +conda)
|
||||
(package! conda :pin "7a34e06931515d46f9e22154762e06e66cfbc81c"))
|
||||
(when (featurep! +poetry)
|
||||
(package! poetry :pin "5b9ef569d629d79820e73b5380e54e443ba90616"))
|
||||
|
||||
;; Testing frameworks
|
||||
(package! nose :pin "f8528297519eba911696c4e68fa88892de9a7b72")
|
||||
(package! python-pytest :pin "b603c5c7f21d351364deeb78e503d3a54d08a152")
|
||||
|
||||
;; Import managements
|
||||
(package! pyimport :pin "a6f63cf7ed93f0c0f7c207e6595813966f8852b9")
|
||||
(package! py-isort :pin "e67306f459c47c53a65604e4eea88a3914596560")
|
||||
Reference in New Issue
Block a user