From 686d102ee7372b6c5b0f8dd08ca09527c0c4a4ed Mon Sep 17 00:00:00 2001 From: Edmund Miller Date: Mon, 4 Jun 2018 18:42:15 -0500 Subject: [PATCH 1/4] Add conda --- modules/lang/python/+conda.el | 18 ++++++++++++++ modules/lang/python/autoload/conda.el | 36 +++++++++++++++++++++++++++ modules/lang/python/packages.el | 2 ++ 3 files changed, 56 insertions(+) create mode 100644 modules/lang/python/+conda.el create mode 100644 modules/lang/python/autoload/conda.el diff --git a/modules/lang/python/+conda.el b/modules/lang/python/+conda.el new file mode 100644 index 000000000..91eae8690 --- /dev/null +++ b/modules/lang/python/+conda.el @@ -0,0 +1,18 @@ +;;; lang/python/+conda.el -*- lexical-binding: t; -*- +;;;###if (featurep! +conda) + +(def-package! conda + :when (featurep! +conda) + :after (python) + :init + (defvar +python-conda-home '("~/.anaconda3" "/usr/bin/anaconda3" "~/.anaconda") ++ "A list of host pattern and corresponding anaconda home.") + :config + (advice-add 'anaconda-mode-bootstrap :override #'*anaconda-mode-bootstrap) + (conda-env-autoactivate-mode -1) + ;; (add-hook 'python-mode-hook #'conda-env-activate-for-buffer) + (conda-env-initialize-interactive-shells) + (conda-env-initialize-eshell) + ;; Version management with conda + (add-hook 'conda-postactivate-hook #'+python|add-version-to-modeline) + (add-hook 'conda-postdeactivate-hook #'+python|add-version-to-modeline)) diff --git a/modules/lang/python/autoload/conda.el b/modules/lang/python/autoload/conda.el new file mode 100644 index 000000000..84d53ceab --- /dev/null +++ b/modules/lang/python/autoload/conda.el @@ -0,0 +1,36 @@ +;;; lang/python/autoload/conda.el -*- lexical-binding: t; -*- +;;;###if (featurep! +conda) + +;;;###autoload +(defun +python/set-conda-home () + (interactive) + (ivy-read "Set conda home:" +python-conda-home + :history +python/set-conda-home--history + :action (lambda (cand) (setq conda-anaconda-home cand)))) + +;;;###autoload +(defun +python|add-version-to-modeline () + "Add version string to the major mode in the modeline." + (setq mode-name + (if conda-env-current-name + (format "Py:conda:%s" conda-env-current-name) + "Python"))) +;;;###autoload +(defun *anaconda-mode-bootstrap (&optional callback) + "Run `anaconda-mode' server. +CALLBACK function will be called when `anaconda-mode-port' will +be bound." + (setq anaconda-mode-process + (start-pythonic :process anaconda-mode-process-name + :buffer anaconda-mode-process-buffer + :cwd (anaconda-mode-server-directory) + :filter (lambda (process output) (anaconda-mode-bootstrap-filter process output)) + :sentinel 'anaconda-mode-bootstrap-sentinel + :query-on-exit nil + :args (list "-c" + anaconda-mode-server-command + (if (pythonic-remote-p) + "0.0.0.0" "127.0.0.1") + (or (pythonic-file-name pythonic-environment) "")))) + (process-put anaconda-mode-process 'server-directory (anaconda-mode-server-directory))) + diff --git a/modules/lang/python/packages.el b/modules/lang/python/packages.el index c7877f223..0b67053d2 100644 --- a/modules/lang/python/packages.el +++ b/modules/lang/python/packages.el @@ -8,3 +8,5 @@ (when (package! anaconda-mode) (when (featurep! :completion company) (package! company-anaconda))) +(when (featurep! +conda) + (package! conda)) From fada449bd4e3def83fff928e3f41d35edd48446e Mon Sep 17 00:00:00 2001 From: Edmund Miller Date: Tue, 5 Jun 2018 18:02:46 -0500 Subject: [PATCH 2/4] Get rid of a stray + --- modules/lang/python/+conda.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lang/python/+conda.el b/modules/lang/python/+conda.el index 91eae8690..c94d4d6e9 100644 --- a/modules/lang/python/+conda.el +++ b/modules/lang/python/+conda.el @@ -6,7 +6,7 @@ :after (python) :init (defvar +python-conda-home '("~/.anaconda3" "/usr/bin/anaconda3" "~/.anaconda") -+ "A list of host pattern and corresponding anaconda home.") + "A list of host pattern and corresponding anaconda home.") :config (advice-add 'anaconda-mode-bootstrap :override #'*anaconda-mode-bootstrap) (conda-env-autoactivate-mode -1) From 732c2979c45840c6927c9b60c71f89dfde930820 Mon Sep 17 00:00:00 2001 From: fuxialexander Date: Thu, 7 Jun 2018 01:06:02 +0800 Subject: [PATCH 3/4] Naming convention and add docs; Avoid conflicting pyenv. --- modules/lang/python/+conda.el | 6 +++--- modules/lang/python/autoload/conda.el | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/modules/lang/python/+conda.el b/modules/lang/python/+conda.el index c94d4d6e9..2ff74999c 100644 --- a/modules/lang/python/+conda.el +++ b/modules/lang/python/+conda.el @@ -8,11 +8,11 @@ (defvar +python-conda-home '("~/.anaconda3" "/usr/bin/anaconda3" "~/.anaconda") "A list of host pattern and corresponding anaconda home.") :config - (advice-add 'anaconda-mode-bootstrap :override #'*anaconda-mode-bootstrap) + (advice-add 'anaconda-mode-bootstrap :override #'+python*anaconda-mode-bootstrap) (conda-env-autoactivate-mode -1) ;; (add-hook 'python-mode-hook #'conda-env-activate-for-buffer) (conda-env-initialize-interactive-shells) (conda-env-initialize-eshell) ;; Version management with conda - (add-hook 'conda-postactivate-hook #'+python|add-version-to-modeline) - (add-hook 'conda-postdeactivate-hook #'+python|add-version-to-modeline)) + (add-hook 'conda-postactivate-hook #'+python|add-conda-env-to-modeline) + (add-hook 'conda-postdeactivate-hook #'+python|add-conda-env-to-modeline)) diff --git a/modules/lang/python/autoload/conda.el b/modules/lang/python/autoload/conda.el index 84d53ceab..62778c27d 100644 --- a/modules/lang/python/autoload/conda.el +++ b/modules/lang/python/autoload/conda.el @@ -3,21 +3,28 @@ ;;;###autoload (defun +python/set-conda-home () - (interactive) - (ivy-read "Set conda home:" +python-conda-home - :history +python/set-conda-home--history - :action (lambda (cand) (setq conda-anaconda-home cand)))) + "Set the CONDA HOME. +Usually it's `~/.anaconda3' on local machine, but you can also set it to a +remote directory using TRAMP syntax such as `/ssh:host:/usr/bin/anaconda3'. In +that way you can use the remote conda environment as well as the corresponding +remote python executable and packages." + (interactive) + (ivy-read "Set conda home:" +python-conda-home + :history +python/set-conda-home--history + :action (lambda (cand) (setq conda-anaconda-home cand)))) ;;;###autoload -(defun +python|add-version-to-modeline () - "Add version string to the major mode in the modeline." +(defun +python|add-conda-env-to-modeline () + "Add conda environment string to the major mode in the modeline." (setq mode-name (if conda-env-current-name (format "Py:conda:%s" conda-env-current-name) "Python"))) ;;;###autoload -(defun *anaconda-mode-bootstrap (&optional callback) - "Run `anaconda-mode' server. +(defun +python*anaconda-mode-bootstrap (&optional callback) + "Advice to set up the anaconda-mode even in remote environment. +Original doc: +Run `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process From 1d6d11e803906f1b2170a844608de3a823588486 Mon Sep 17 00:00:00 2001 From: fuxialexander Date: Thu, 7 Jun 2018 01:12:03 +0800 Subject: [PATCH 4/4] add meta doc --- modules/lang/python/+conda.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/lang/python/+conda.el b/modules/lang/python/+conda.el index 2ff74999c..78f373b8a 100644 --- a/modules/lang/python/+conda.el +++ b/modules/lang/python/+conda.el @@ -1,6 +1,9 @@ ;;; lang/python/+conda.el -*- lexical-binding: t; -*- ;;;###if (featurep! +conda) +;; This file add conda support to doom-emacs. To get started, try `M-x' +;; `+python/set-conda-home' and then `M-x' `conda-env-activate'. + (def-package! conda :when (featurep! +conda) :after (python)