Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion layers/+lang/python/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- [[#automatic-activation-of-local-pyenv-version][Automatic activation of local pyenv version]]
- [[#manage-environments-and-packages-with-pipenv][Manage environments and packages with pipenv]]
- [[#manage-environments-and-packages-with-poetry][Manage environments and packages with Poetry]]
- [[#manage-environments-and-packages-with-uv][Manage environments and packages with uv]]
- [[#key-bindings][Key bindings]]
- [[#inferior-repl-process][Inferior REPL process]]
- [[#running-python-script-in-shell][Running Python Script in shell]]
Expand All @@ -61,7 +62,7 @@ This layer adds support for the Python language.
- Code Navigation
- Documentation Lookup using [[https://github.com/proofit404/anaconda-mode][anaconda-mode]] and [[https://github.com/tsgates/pylookup][pylookup]]
- Test Runners using [[https://github.com/ionrock/pytest-el][pytest]] or [[https://github.com/syl20bnr/nose.el][nose.el]]
- Virtual Environment using [[https://github.com/jorgenschaefer/pyvenv][pyvenv]] and [[https://github.com/yyuu/pyenv][pyenv]] as well as [[https://github.com/pypa/pipenv][pipenv]] and [[https://github.com/galaunay/poetry.el][poetry]]
- Virtual Environment using [[https://github.com/jorgenschaefer/pyvenv][pyvenv]] and [[https://github.com/yyuu/pyenv][pyenv]] as well as [[https://github.com/pypa/pipenv][pipenv]], [[https://github.com/galaunay/poetry.el][poetry]], and [[https://github.com/astral-sh/uv][UV]]
- semantic mode is enabled
- PEP8 compliant formatting via [[https://github.com/google/yapf][YAPF]], [[https://github.com/ambv/black][black]], or [[https://github.com/astral-sh/ruff][ruff]]
- PEP8 checks with [[https://pypi.python.org/pypi/flake8][flake8]] or [[https://pypi.python.org/pypi/pylint/1.6.4][pylint]]
Expand Down Expand Up @@ -470,6 +471,37 @@ It provides the following key bindings:
| ~SPC m v o a~ | Activate the virtualenv associated to the current poetry project |
| ~SPC m v o t~ | Toggle the virtualenv associated to the current poetry project |

** Manage environments and packages with uv
[[https://github.com/astral-sh/uv][UV]] is a fast Python package installer and resolver written in Rust. It's designed
to be a drop-in replacement for pip and pip-tools, offering significantly faster
package installation and dependency resolution.

Spacemacs integration for UV is provided by the [[https://github.com/borgstad/uv.el][uv.el]] package.
It provides the following key bindings:

| Key binding | Description |
|-------------+------------------------------------|
| ~SPC m u v~ | Open the main UV transient menu |
| ~SPC m u a~ | Add regular dependencies |
| ~SPC m u d~ | Remove dependencies |
| ~SPC m u l~ | Lock project dependencies |
| ~SPC m u e~ | Edit pyproject.toml file |
| ~SPC m u b~ | Build the package |
| ~SPC m u p~ | Publish the package |
| ~SPC m u n~ | Create a new Python project |
| ~SPC m u i~ | Initialize a new UV project |
| ~SPC m u r~ | Run commands in the UV environment |

To enable UV support, add ~uv~ to your ~python-enable-tools~ list:

#+BEGIN_SRC elisp
(setq-default dotspacemacs-configuration-layers
'((python :variables python-enable-tools '(uv))))
#+END_SRC

*Note:* You need to install the ~uv~ command-line tool first. See the
[[https://github.com/astral-sh/uv][UV documentation]] for installation instructions.

* Key bindings
** Inferior REPL process
Start a Python or iPython inferior REPL process with ~SPC m s i~.
Expand Down
9 changes: 9 additions & 0 deletions layers/+lang/python/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ Possible values are `on-visit', `on-project-switch' or `nil'.")
(defvar python-enable-importmagic nil
"If non-nil, enable the importmagic feature.")

(defvar python-enable-tools '(pip pipenv poetry)
"List of Python package management tools to enable in Spacemacs.

Possible values:
- `pip`: Enable pip package management functionality
- `pipenv`: Enable pipenv virtual environment and package management
- `poetry`: Enable Poetry package and dependency management
- `uv`: Enable uv package and dependency management")

(defvar spacemacs--python-pyenv-modes nil
"List of major modes where to add pyenv support.")

Expand Down
26 changes: 23 additions & 3 deletions layers/+lang/python/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
:toggle (memq 'nose (flatten-list (list python-test-runner))))
org
pip-requirements
pipenv
poetry
pippel
(pipenv :toggle (memq 'pipenv python-enable-tools))
(poetry :toggle (memq 'poetry python-enable-tools))
(pippel :toggle (memq 'pip python-enable-tools))
(uv :toggle (memq 'uv python-enable-tools)
:location (recipe :fetcher github :repo "borgstad/uv.el" :files ("*.el")))
py-isort
pyenv-mode
pydoc
Expand Down Expand Up @@ -273,6 +275,24 @@
(evilified-state-evilify-map pippel-package-menu-mode-map
:mode pippel-package-menu-mode)))

(defun python/init-uv ()
(use-package uv
:defer t
:init
(spacemacs/declare-prefix-for-mode 'python-mode
"u" "UV")
(spacemacs/set-leader-keys-for-major-mode 'python-mode
"uv" 'uv
"ua" 'uv-add
"ud" 'uv-remove
"ul" 'uv-lock
"ue" 'uv-edit-pyproject-toml
"ub" 'uv-build
"up" 'uv-publish
"un" 'uv-new
"ui" 'uv-init
"ur" 'uv-run)))

(defun python/init-py-isort ()
(use-package py-isort
:defer t
Expand Down
Loading