Peter Maydell <[email protected]> writes:

> On Fri, 23 Oct 2026 at 19:06, Alex Bennée <[email protected]> wrote:
>>
>> When editing python code the linters tools have a hard time with our
>> imports as they can't be found. To ease this we can expand a
>> PYTHONPATH in .dir-locals so at least Emacs users can have less
>> warnings in their editor.
>>
>> I still get complaints from python-mypy about missing library stubs
>> that mean it can't do proper type analysis though.
>>
>> Reviewed-by: Daniel P. Berrangé <[email protected]>
>> Message-ID: <[email protected]>
>> Signed-off-by: Alex Bennée <[email protected]>
>>
>> diff --git a/.dir-locals.el b/.dir-locals.el
>> index 3ac0cfc6f0d..51871619422 100644
>> --- a/.dir-locals.el
>> +++ b/.dir-locals.el
>> @@ -1,2 +1,8 @@
>>  ((c-mode . ((c-file-style . "stroustrup")
>> -           (indent-tabs-mode . nil))))
>> +           (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))))))))
>
> With this change, emacs now complains and prompts for input every
> time I open a Python file inside the QEMU source tree:
>
> ===begin===
> The local variables list in /home/pm215/qemu/
> or .dir-locals.el contains values that may not be safe (*).
>
> Do you want to apply it?  You can type
> y  -- to apply the local variables list.
> n  -- to ignore the local variables list.
> !  -- to apply the local variables list, and permanently mark these
>       values (*) as safe (in the future, they will be set automatically.)
> i  -- to ignore the local variables list, and permanently mark these
>       values (*) as ignored
>
>   * 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))))
> ===endit===
>
> The commit messages says "so Emacs users can have less warnings"
> but from my POV this is "more warnings" (and previously I didn't
> notice any warnings at all).

Same here.

What exactly was the problem this patch tried to solve?

> I think emacs is correct to warn about files and configs that
> try to automatically update PYTHONPATH, so I would favour reverting
> this commit.


Reply via email to