;;; PythonCubes --- The Python cubes for FG42 -*- lexical-binding: t; -*- ;; ;; Copyright (c) 2010-2021 Sameer Rahmani & Contributors ;; ;; Author: Sameer Rahmani ;; URL: https://gitlab.com/FG42/FG42 ;; Version: 3.0.0 ;; ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;; ;;; Commentary: ;;; Code: (require 'fpkg) (require 'fg42/cube) (require 'fg42/utils) (defun fg42/py-workon-project-venv () "Call pyenv-workon with the current projectile project name. This will return the full path of the associated virtual environment found in $WORKON_HOME, or nil if the environment does not exist." (require 'pyenv) (let ((pname (projectile-project-name))) (pyvenv-workon pname) (if (file-directory-p pyvenv-virtual-env) pyvenv-virtual-env (pyvenv-deactivate)))) (defun fg42/py-auto-lsp () "Turn on lsp mode in a Python project with some automated logic. Try to automatically determine which pyenv virtual environment to activate based on the project name, using `dd/py-workon-project-venv'. If successful, call `lsp'. If we cannot determine the virtualenv automatically, first call the interactive `pyvenv-workon' function before `lsp'" (interactive) (let ((pvenv (fg42/py-workon-project-venv))) (if pvenv (lsp) (progn (call-interactively #'pyvenv-workon) (lsp))))) (defcube fg42/python-cube "Python support cube." (:title "Python cube" :flag python) (fpkg/use pyvenv :defer t :config (setenv "WORKON_HOME" "~/.pyenv/versions")) (when-flag lsp (with-eval-after-load "lsp" (lsp-register-custom-settings '(("pyls.plugins.pyls_mypy.enabled" t t) ("pyls.plugins.flake8.enabled" t t) ("pyls.plugins.pyls_mypy.live_mode" nil t) ("pyls.plugins.pyls_black.enabled" t t) ("pyls.plugins.pyls_isort.enabled" t t))) (add-hook 'python-mode #'fg42/py-auto-lsp)))) (provide 'cubes/python) ;;; python.el ends here