hallowed-student-25079
11/01/2021, 8:11 AM./pants roots
as every root in my setup corresponds to one top level module in the python module hierarchy. I guess this process can be easily automated and I assume there is no better solution here (and it’s not that bad with this setup, actually it’s better than what we had with poetry).
• For multiple lock files, we can work around this for now and looking at the docs it seems there will be support for this soon, which is great 🎉!
• Most headaches come from my tries to debug and run code from within VSCode. The setup with editable install works great with poetry as it easily allows to launch binaries / cli scripts from within VSCode with a debugger attached. As the files executed are the ones edited, there are no problems with source mapping and breakpoints set in VSCode are respected when running. For this VSCode uses debugpy (https://github.com/microsoft/debugpy). Executables are specified in a launch.json
file (https://code.visualstudio.com/docs/python/debugging) and then it is possible to run them from the UI.
◦ I managed to debug a running pex file where I attach to a remote debugger manually started in the code. This is cool, but still a bit inconvenient as breakpoints are not working and it requires more boilerplate work.
◦ I also manage to run a pex file with the debugpy launcher, but then it ignores exceptions and does not enter the debugger (it seems some subprocess / fork is not covered by the debugger).
◦ Even with that I would need to do source mapping as the pex venv is located elsewhere and has some (possibly outdated) copies.
◦ One idea I had was a plugin that creates a venv where all source roots are installed editable. But not sure if there is an easier solution?curved-television-6568
11/01/2021, 8:32 AMhallowed-student-25079
11/01/2021, 8:36 AMhappy-kitchen-89482
11/02/2021, 1:07 AMrun
goal, or when running tests under test
goal ?hallowed-student-25079
11/02/2021, 7:31 AMpython_sources
targets in source roots (so top level modules) and creates a minimal setup.py (without requirements) in the directory, additionally the setup.py gets an entry point and requirements if there is a new python_dev_module
target. My idea is now to also generate a script that can install a module at the top of the dependency chain (in our case that’s usually some kind of service with a an entrypoint) and also all the other modules that have no requirements into a venv.
This way I can debug with vscode without any additional source mapping. This has the downside that the setup feels a bit hacky and is not exactly the same as with the run goal, as well as that I have to execute another command outside of pants (as I cannot execute the generated script from a goal rule). On the other hand, this is only needed whenever a top level module is added and the debug workflow is very much as vscode expect it to be setup.happy-kitchen-89482
11/02/2021, 2:32 PMhallowed-student-25079
11/02/2021, 3:00 PMhappy-kitchen-89482
11/02/2021, 3:26 PMhallowed-student-25079
11/02/2021, 3:35 PM.env
file - that one could probably be auto generated from the source roots and that would be easier (only entrypoints would not exist, but I think that’s not a problem). I will try this, thanks for the idea! Then depending on where my entrypoint module for debugging lies I only need to take care of having a venv with the right 3rd party dependencies. I guess for that one I could re-use the venv of a pex file right?curved-television-6568
11/02/2021, 3:50 PMhappy-kitchen-89482
11/02/2021, 5:44 PMhallowed-student-25079
11/03/2021, 8:42 AMpex_binary
and had the execution mode set to venv
. The binary has an entrypoint set and depends on a library (all dependencies inferred). This works when running ./pants run //:root_bin
but when I do ./pants package //:root_bin
and then ./dist/root_bin.pex
I get a ModuleNotFoundError
and looking into the pex venv, I can see a directory for that module not found in the site-packages
but no files in there. Interestingly the module some of the sources that are missing are depending on is also there (but empty too). Once I switch execution mode back to zipapp
everything works fine. This is on 2.8.0rc1.curved-television-6568
11/03/2021, 9:21 AMPANTS_SHA=bb9f1991d5379747d435b3a997af715182bcaeab ./pants ...
to try it out… (using the latest git sha for main there…)hallowed-student-25079
11/03/2021, 9:31 AMcurved-television-6568
11/03/2021, 9:33 AMhappy-kitchen-89482
11/03/2021, 12:54 PM