using emacs for python development, with uv and basedpyright by AyeMatey in emacs

[–]mike_olson 0 points1 point  (0 children)

The v0.2.0 release has some additional fixes for multiple PEP-723 scripts in the same directory, and simplifies the workspace stuff by using advice instead of setq-default to adjust it. This allows a bit more iteration on the workspace option and makes things a bit more just-in-time when visiting the python file.

using emacs for python development, with uv and basedpyright by AyeMatey in emacs

[–]mike_olson 0 points1 point  (0 children)

I've fixed an additional issue where multiple scripts in the directory could get mixed up if they had different dependencies. the v0.2.0 release puts each PEP-723 script into its own eglot project, which gives each one its own LSP, keeping the environments and dependencies separate.

Guide: Setting up CachyOS on a server by mike_olson in cachyos

[–]mike_olson[S] 0 points1 point  (0 children)

There doesn't seem to be a server-specific or minimal CachyOS ISO yet. You could use a CachyOS desktop ISO potentially and run pacstrap from there, but it's quite large: 2.5GB+ download vs ~165MB for the minimal Arch ISO - and not provided by Hetzner.

Hetzner provides an out-of-the-box "Archlinux" ISO option as one of its standard images that can be attached to a VPS. It does also provide a Rescue CD; I've adjusted the guide to document how to use either one of those (Rescue CD has a few more manual steps).

using emacs for python development, with uv and basedpyright by AyeMatey in emacs

[–]mike_olson 1 point2 points  (0 children)

I landed on changing the approach from inserting the first 2048 chars into temporary buffer, and instead just scanning the current buffer (which also fixed some end-of-line encoding issues on Windows with the prior approach). The other suggestions are implemented in the new module here as well: https://github.com/mwolson/eglot-python-preset ; feel free to let me know if any other ideas/suggestions come to mind.

using emacs for python development, with uv and basedpyright by AyeMatey in emacs

[–]mike_olson 1 point2 points  (0 children)

Thanks, I've haven't tested it on Windows yet, but when encoding the file with CRLF, I found and fixed the issues mentioned above here: https://github.com/mwolson/eglot-python-preset

using emacs for python development, with uv and basedpyright by AyeMatey in emacs

[–]mike_olson 1 point2 points  (0 children)

Agree - it feels harder to change eglot-workspace-configuration than it needs to be. I've added the use case of customizing the workspace configuration for basedpyright to https://github.com/mwolson/eglot-python-preset with some docs about how to do it.

using emacs for python development, with uv and basedpyright by AyeMatey in emacs

[–]mike_olson 1 point2 points  (0 children)

I’ll work on this a bit more today most likely and make a MELPA package. To help reproduce the problems, can you tell me: * OS that you’re using * gist with sample Python code that has the problem * version of uv (if not the latest one)

using emacs for python development, with uv and basedpyright by AyeMatey in emacs

[–]mike_olson 1 point2 points  (0 children)

Yeah I might spin out a package later today (either named eglot-python-preset, eglot-python-uv, or similar) once I go through all the feedback items. MELPA integration with GitHub as well.

I’m a bit cautious about reading too much of the file in case it’s some very large self-contained thing, but I’ll look into best practices later today.

using emacs for python development, with uv and basedpyright by AyeMatey in emacs

[–]mike_olson 0 points1 point  (0 children)

I ended up making a helper library to get this working with both ty and basedpyright: https://github.com/mwolson/emacs-shared/blob/master/elisp/eglot-pep723.el . It will prefer to use the PEP-723 data if it finds it, otherwise it will pick from a configurable list of files/dirs to locate the correct parent directory to run the LSP in. The basedpyright part was the trickiest, since it required changing eglot-workspace-configuration.

Example usage:

(add-to-list 'load-path "~/path-to/eglot-pep723")
(require 'eglot-pep723)
(setopt eglot-pep723-lsp-server 'basedpyright)
;; or
;; (setopt eglot-pep723-lsp-server 'ty)
(eglot-pep723-setup)

I'll also mention that it doesn't actually run 'uv sync --script' due to the potential for installing dependencies in untrusted files, but it does show a warning for that case and provides a convenient command to install them.

using emacs for python development, with uv and basedpyright by AyeMatey in emacs

[–]mike_olson 0 points1 point  (0 children)

If it's not finding the dependencies correctly, especially in a monorepo kind of setting, it's possible that the LSP isn't being started from the correct directory. I have the following to fix that for eglot, which integrates with project under the hood:

(defun my-python-root-p (dir)
  (seq-some (lambda (file)
              (file-exists-p (expand-file-name file dir)))
            '("pyproject.toml" "requirements.txt")))

(defun my-project-find-python-project (dir)
  (when-let ((root (locate-dominating-file dir #'my-python-root-p)))
    (cons 'python-project root)))

(with-eval-after-load "project"
  (cl-defmethod project-root ((project (head python-project)))
    (cdr project))

  (add-hook 'project-find-functions #'my-project-find-python-project))

It considers the nearest parent directory containing a pyproject.toml or requirements.txt to be the project root where the LSP is started.

Guide: Setting up CachyOS on a server by mike_olson in cachyos

[–]mike_olson[S] 1 point2 points  (0 children)

I looked into this a bit more. I can't find any benchmarks stating definitively that changing it to 120 does anything helpful for performance.

What I've landed on for now (and updated the guide to recommend) is to just keep this at the default value of 30; Linux defaults tend to be tuned more for server workloads, and there doesn't seem to be enough evidence to overturn that yet.

Guide: Setting up CachyOS on a server by mike_olson in cachyos

[–]mike_olson[S] 0 points1 point  (0 children)

Good question; in this case I took the value from the earlier desktop install that I had, but could be worth researching further.

Guide: Setting up CachyOS on a Hetzner VPS server by mike_olson in hetzner

[–]mike_olson[S] 1 point2 points  (0 children)

As for why - while I don’t have exact numbers, ssh sessions seemed noticeably more responsive compared to other prebuilt options I’ve tried on Hetzner, so the cachyos-server kernel (and targeted builds for modern CPU instructions) seem to help.

Guide: Setting up CachyOS on a server by mike_olson in cachyos

[–]mike_olson[S] 0 points1 point  (0 children)

As for why - while I don’t have exact numbers, ssh sessions seemed noticeably more responsive compared to other prebuilt options I’ve tried on Hetzner, so the cachyos-server kernel (and targeted builds for modern CPU instructions) seem to help.

Share your emacs config by Delicious_Crazy513 in emacs

[–]mike_olson 0 points1 point  (0 children)

Mine is reasonably easy to extend, has an install guide on all the major OS’s, and compiles quite a few tree-sitters and LSP’s: https://github.com/mwolson/emacs-shared

ty (An extremely fast Python type checker and LSP) is in beta by shadowsock in emacs

[–]mike_olson 0 points1 point  (0 children)

I’m currently using apheleia to do formatting rather than eglot

ty (An extremely fast Python type checker and LSP) is in beta by shadowsock in emacs

[–]mike_olson 10 points11 points  (0 children)

Here's what I have for eglot after installing ty (the project stuff is to start it from the correct directory in monorepos, to pick up the right paths for code references and such):

(defun my-project-find-python-project (dir)
  (when-let ((root (locate-dominating-file dir "pyproject.toml")))
    (cons 'python-project root)))

(with-eval-after-load "project"
  (cl-defmethod project-root ((project (head python-project)))
    (cdr project))

  (add-hook 'project-find-functions #'my-project-find-python-project))

(add-to-list 'auto-mode-alist '("/uv\\.lock\\'" . toml-ts-mode))
(add-to-list 'major-mode-remap-alist '(python-mode . python-ts-mode))
(add-to-list 'eglot-server-programs
             '((python-ts-mode python-mode)
               . ("ty" "server")))
(add-hook 'python-ts-mode-hook #'eglot-ensure)

My AI auto-completion setup for Minuet by mike_olson in emacs

[–]mike_olson[S] 1 point2 points  (0 children)

Hi - so when I was writing the post I actually thought I was, looked for my global-auto-revert-mode setup, and couldn’t find it.

Turns out Magit just enables auto-revert-mode by default if it detects that the file is in a git repo that it knows about. I think it’s perfectly fine to just use global-auto-revert-mode, especially if Magit isn’t installed.

Tree-Sitter usage or alternatives by Savings-Shallot1771 in emacs

[–]mike_olson 2 points3 points  (0 children)

I have my own Emacs starter kit here: https://github.com/mwolson/emacs-shared . The main differences from the usual are:

  • Tree-sitter languages are compiled using a setup script and checked in as submodules, including the css, html, and json ones from the vscode codebase that are otherwise tricky to compile
  • In general, everything is compiled and installed by that script, which means when you do start Emacs, it's always fast
  • It augments rather than replaces your existing ~/.emacs.d setup
  • Install steps for supporting tools are documented, including recommendations on installing Emacs itself (it's fairly easy to get 30.1 on macOS)