Skip to content

Commit

Permalink
Fix issue with dir-config-get-dir and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescherti committed Aug 17, 2024
1 parent 499a754 commit 18e3707
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ Assuming that the `dir-config-dir` package has been configured to allow loading
Adding the following code to the `~/src/my_python_project/.dir-config.el` file can modify the `PYTHONPATH` environment variable for Python buffers within its directory or one of its subdirectories (e.g., `~/src/my_python_project/my_python_project/file.py`). Modifying `PYTHONPATH` ensures that processes executed by tools like Flycheck or Flymake have access to the Python project's modules:
``` emacs-lisp
;;; .dir-config.el --- Directory config -*- no-byte-compile: t; lexical-binding: t; -*-
(let ((python_path_env (getenv "PYTHONPATH"))
(let ((python-path (getenv "PYTHONPATH"))
(dir (dir-config-get-dir)))
;; This ensures that the processes that are executed by Flycheck or
;; Flake8, can access the environment variables PYTHONPATH.
(when dir
(setq-local process-environment
(cons (concat "PYTHONPATH="
(dir-config-get-dir)
(if python_path_env (concat ":" python_path_env) ""))
process-environment))))
;; Ensure that processes executed by Flycheck or Flake8 can access the
;; PYTHONPATH environment variable.
(when (and dir (or (file-exists-p (expand-file-name "setup.py"))
(file-exists-p (expand-file-name "pyproject.toml"))))
(setq-local process-environment (copy-sequence process-environment))
(setenv "PYTHONPATH" (concat dir (when python-path (concat ":" python-path))))))
```

It is recommended to always begin your `.dir-config.el` files with the following header:
Expand Down
4 changes: 2 additions & 2 deletions dir-config.el
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ otherwise."
"Return the directory of the currently loaded dir config file.
Return `nil` if the dir config file has not been loaded."
(when (bound-and-true-p dir-config--file)
(file-name-nondirectory dir-config--file)))
(file-name-directory dir-config--file)))

(defun dir-config-get-file ()
"Return the file of the currently loaded dir config file.
Expand Down Expand Up @@ -173,7 +173,7 @@ Only loads settings if the directory is allowed."
(when dir-config-debug
(message "[dir-settings] [DEBUG] Skipping load as already loaded: %s"
dir-config--file))
(unless (bound-and-true-p dir-config-disable)
(unless (bound-and-true-p dir-config-disabled)
(setq-local dir-config--loaded nil)
(setq-local dir-config--allowed-p nil)
(setq-local dir-config--file nil)
Expand Down

0 comments on commit 18e3707

Please sign in to comment.