Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teaching hy-shell to set PYTHONPATH #109

Open
igoralmeida opened this issue Nov 15, 2022 · 0 comments
Open

Teaching hy-shell to set PYTHONPATH #109

igoralmeida opened this issue Nov 15, 2022 · 0 comments

Comments

@igoralmeida
Copy link

Hy all :)

Thanks for the nice piece of software. Looking around hy-shell.el, I could not find a way to pass PYTHONPATH to the inferior process --- without a global setenv I guess, which I'd like to avoid since I have other REPLs running. Can you confirm if that's the case? I may simply be missing the correct configuration or required workflow.

If so, here's how I got it to work (this is on top of df81486 and hy 0.25.0):

diff --git a/hy-shell.el b/hy-shell.el
index 22927f2..104d643 100644
--- a/hy-shell.el
+++ b/hy-shell.el
@@ -51,6 +51,9 @@
 (defvar hy-shell--redirect-timeout 0.5
   "Seconds (float) to allow redirection commands to complete before quitting.")
 
+(defvar hy-shell-extra-pythonpaths nil
+  "Extra pythonpaths, a la `python-shell-extra-pythonpaths'.")
+
 ;;;; Managed
 
 (defconst hy-shell--name "Hy"
@@ -136,7 +139,12 @@
             (split-string-and-unquote (hy-shell--format-startup-command)))
            (name
             (if (hy-shell--internal?) hy-shell--name-internal hy-shell--name)))
-      (apply #'make-comint-in-buffer name nil program nil switches)
+
+      (let ((process-environment (cl-copy-list process-environment)))
+        (when hy-shell-extra-pythonpaths
+          (setenv "PYTHONPATH" (let ((python-shell-extra-pythonpaths hy-shell-extra-pythonpaths))
+                                 (python-shell-calculate-pythonpath))))
+        (apply #'make-comint-in-buffer name nil program nil switches))
 
       (unless (derived-mode-p 'inferior-hy-mode)
         (inferior-hy-mode))

Basically I abuse python-shell-calculate-pythonpath and override process-environment before starting the process. That way I can have a list of paths in hy-shell-extra-pythonpaths, set by dir-locals for example.

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant