[RFC PATCH] Revert ".dir-locals: include QEMU code in PYTHONPATH"

Alex Bennée posted 1 patch 1 week, 3 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261113004452.3027978-1-alex.bennee@linaro.org
.dir-locals.el | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
[RFC PATCH] Revert ".dir-locals: include QEMU code in PYTHONPATH"
Posted by Alex Bennée 1 week, 3 days ago
Unfortunately this relied on trusting the source tree via the
safe-local-variable-directories otherwise users keep being prompted
that ".dir-locals.el contains values that may not be safe".

An alternative is for the user to add something like this to their
local emacs config:

  (defun my-return-source-if-in-qemu-tree()
    "Return the root of source when in QEMU code."
    (when-let ((src (expand-file-name (locate-dominating-file default-directory ".git"))))
      (if (file-exists-p (concat src "/qemu-options.hx"))
          src)))

  (defun my-set-qemu-python-path()
    "Set local python environment for QEMU."
    (when-let ((root (my-return-source-if-in-qemu-tree)))
      (setq-local process-environment (copy-sequence process-environment))
      (setenv "PYTHONPATH" (concat (expand-file-name "python" root) ":"
                                   (expand-file-name "tests/functional" root)))))

  (use-package python
    :hook ((python-mode python-ts-mode) . my-set-qemu-python-path))

This reverts commit 3112269be3ac92343a5f0e5d9eae919edd176a35.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 .dir-locals.el | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/.dir-locals.el b/.dir-locals.el
index 51871619422..3ac0cfc6f0d 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -1,8 +1,2 @@
 ((c-mode . ((c-file-style . "stroustrup")
-	    (indent-tabs-mode . nil)))
- (python-mode .
-              ((eval . (when-let* ((root (locate-dominating-file default-directory ".dir-locals.el")))
-                         (setq-local process-environment (copy-sequence process-environment))
-                         (setenv "PYTHONPATH"
-                                 (concat (expand-file-name "python" root) ":"
-                                         (expand-file-name "tests/functional" root))))))))
+	    (indent-tabs-mode . nil))))
-- 
2.47.3


Re: [RFC PATCH] Revert ".dir-locals: include QEMU code in PYTHONPATH"
Posted by Peter Maydell 1 week, 2 days ago
On Fri, 13 Nov 2026 at 00:45, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> Unfortunately this relied on trusting the source tree via the
> safe-local-variable-directories otherwise users keep being prompted
> that ".dir-locals.el contains values that may not be safe".
>
> An alternative is for the user to add something like this to their
> local emacs config:
>
>   (defun my-return-source-if-in-qemu-tree()
>     "Return the root of source when in QEMU code."
>     (when-let ((src (expand-file-name (locate-dominating-file default-directory ".git"))))
>       (if (file-exists-p (concat src "/qemu-options.hx"))
>           src)))
>
>   (defun my-set-qemu-python-path()
>     "Set local python environment for QEMU."
>     (when-let ((root (my-return-source-if-in-qemu-tree)))
>       (setq-local process-environment (copy-sequence process-environment))
>       (setenv "PYTHONPATH" (concat (expand-file-name "python" root) ":"
>                                    (expand-file-name "tests/functional" root)))))
>
>   (use-package python
>     :hook ((python-mode python-ts-mode) . my-set-qemu-python-path))
>
> This reverts commit 3112269be3ac92343a5f0e5d9eae919edd176a35.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Re: [RFC PATCH] Revert ".dir-locals: include QEMU code in PYTHONPATH"
Posted by Alex Bennée 1 week, 2 days ago
Are you happy to take via your tree or do you want a PR from me?

Alex Bennée
Emulation and Virtualisation Tech Lead @ Linaro

On Fri, 13 Nov 2026, 02:06 Peter Maydell, <peter.maydell@linaro.org> wrote:

> On Fri, 13 Nov 2026 at 00:45, Alex Bennée <alex.bennee@linaro.org> wrote:
> >
> > Unfortunately this relied on trusting the source tree via the
> > safe-local-variable-directories otherwise users keep being prompted
> > that ".dir-locals.el contains values that may not be safe".
> >
> > An alternative is for the user to add something like this to their
> > local emacs config:
> >
> >   (defun my-return-source-if-in-qemu-tree()
> >     "Return the root of source when in QEMU code."
> >     (when-let ((src (expand-file-name (locate-dominating-file
> default-directory ".git"))))
> >       (if (file-exists-p (concat src "/qemu-options.hx"))
> >           src)))
> >
> >   (defun my-set-qemu-python-path()
> >     "Set local python environment for QEMU."
> >     (when-let ((root (my-return-source-if-in-qemu-tree)))
> >       (setq-local process-environment (copy-sequence
> process-environment))
> >       (setenv "PYTHONPATH" (concat (expand-file-name "python" root) ":"
> >                                    (expand-file-name "tests/functional"
> root)))))
> >
> >   (use-package python
> >     :hook ((python-mode python-ts-mode) . my-set-qemu-python-path))
> >
> > This reverts commit 3112269be3ac92343a5f0e5d9eae919edd176a35.
> >
> > Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> > ---
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>
> thanks
> -- PMM
>
Re: [RFC PATCH] Revert ".dir-locals: include QEMU code in PYTHONPATH"
Posted by Peter Maydell 1 week, 2 days ago
On Fri, 13 Nov 2026 at 12:59, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> Are you happy to take via your tree or do you want a PR from me?

I'll put it into the pullreq I'm putting together; thanks.

-- PMM