I have a .dir-locals.el file in my project in which I am configuring my project for debugging using dap-debug in Emacs with debugpy.
I have this variant of the .dir-locals.el file that works just fine:
((nil . ((eval . (progn
(setq-local my-local-root (projectile-project-root))
(setq-local my-local-path (expand-file-name "linux-application/my_app" my-local-root))
(message "Project root is: %s" my-local-root)
(message "Concatenated path: %s" my-local-path)))
(dap-debug-template-configurations
. (("Docker Pytest Debug"
:type "python"
:request "attach"
:hostName "localhost"
:port 5678
:name "Docker Pytest Debug"
:pathMappings ((
( :localRoot . "/home/my_user/projects/our-gateway/linux-application/my_app")
( :remoteRoot . "/usr/src/app/linux-application/my_app")
))))))))
Now, to make things a bit more general, I would like to replace:
( :localRoot . "/home/my_user/projects/our-gateway/linux-application/my_app")
With something like this:
( :localRoot . my-local-path)
but this does not work. When doing the change the debugger do not find the source code.
This makes me believe the path “my-local-path” is not the same as the string in my working variant. When I look at the print of the variable “my-local-path” in Emacs messages buffer it looks like it is the same though. I have also checked that they both are strings. The file .dir-local.el is in the folder /home/my_user/projects/our-gateway.
I have also tried to do the concatenation with “concat”, but that generates the same issue.
1
Thanks tripleee, you were correct. Here is my working file:
((nil . ((eval . (progn
(setq-local my-local-root (projectile-project-root))
(setq-local my-local-path (expand-file-name "linux-application/my_app" my-local-root))
(message "Project root is: %s" my-local-root)
(message "Concatenated path: %s" my-local-path)
(setq dap-debug-template-configurations
`(("Docker Pytest Debug"
:type "python"
:request "attach"
:hostName "localhost"
:port 5678
:name "Docker Pytest Debug"
:pathMappings (((:localRoot . ,my-local-path)
(:remoteRoot . "/usr/src/app/linux-application/my_app")))))))))))
So, the error was: “dap-debug-template-configurations is outside the eval so of course it doesn’t have access to the local variables you declared within it”.
Some comments on the piece of code (I am not that good at elisp, so pleas correct me if I am wrong):
- “Docker Pytest Debug” is the name of the template you will see when you start the debugging in Emacs with M x dap-debug.
- “attach” tells Emacs that it should attach to a remote debug session.
- “port” is the port at which the debugger is listening for Emacs.
- “LocalRoot” is the folder where the source code is located on the host running Emacs.
- “remoteRoot” is the source code folder within the Docker container where, in my case, debugpy is running.
4