jolly-midnight-72759
10/08/2020, 12:58 AMos.environ[PYTHONPATH] = ":".join(sys.path)
before running the notebook via jupyter_core.command.main()
. Is this still appropriate to do in v2 or is there a better way.
This was needed so the spawned kernel could inherit the path of the targets.jolly-midnight-72759
10/08/2020, 1:00 AMsys.argv = ['', 'notebook', '--notebook-dir=', '/path/to/repo']
. Is there a way to get the repo root in my script or do I need to figure that out myself?hundreds-father-404
10/08/2020, 1:02 AMPEX_EXTRA_SYS_PATH
to the source roots being used, like src/python
. Pex uses this to extend PYTHONPATH
See https://github.com/pantsbuild/pants/blob/ff02ef0ddd284bc5f4d9d4a724c3d8ecbe066854/src/python/pants/backend/python/goals/repl.py#L44-L48 for how that’s done with the normal Python replhundreds-father-404
10/08/2020, 1:03 AMIs there a way to get the repo root in my scriptIf you’re using the
repl
goal hook, you use <http://repl.in|repl.in>_chroot()
for this. It’ll ensure that the correct paths are being used. You can mostly copy and paste that file I linked tojolly-midnight-72759
10/08/2020, 1:06 AMdist/
directory. That way it is easier for the eng to work with the file after they are done with the notebook.jolly-midnight-72759
10/08/2020, 1:09 AMasync def jupyter_binary(...):
pex = await Get(...)
code.hundreds-father-404
10/08/2020, 1:17 AMIf I am using the “Pex: Install binaries through pip” way of getting my jupyter binaryThe
PEX_EXTRA_SYS_PATH
is only needed when you run the process, not when building the Pex. It gets used at runtime, and isn’t necessary when building the Pexjolly-midnight-72759
10/08/2020, 1:18 AMhundreds-father-404
10/08/2020, 1:18 AMthen the Notebook file will get saved in a hidden directoryOh, hm, interesting. How does saving the notebook file work? Jupyter will write the file for you? Can you specify where that file gets written?
jolly-midnight-72759
10/08/2020, 1:20 AMjupyter notebook
from. You can add the --notebook-dir=/path/somewhere
option to set the root to where ever you wish. Once started, the Jupyter Notebook app can't read or write above that directory. The kernel has access to all the paths that were set when it was spawned (I believe).jolly-midnight-72759
10/08/2020, 1:21 AMPYTHONPATH
but the browser code can't save or open anywhere but notebook-dir
.hundreds-father-404
10/08/2020, 1:22 AMInteractiveProcess
running in the build root, with it writing to arbitrary file paths in the build root? Pants has no restrictions on that, right? This is why we solely allow a @goal_rule
to run an InteractiveProcess
, which acts ~like a lockjolly-midnight-72759
10/08/2020, 1:22 AMhundreds-breakfast-49010
10/08/2020, 1:23 AMhundreds-breakfast-49010
10/08/2020, 1:23 AMjolly-midnight-72759
10/08/2020, 1:23 AMjolly-midnight-72759
10/08/2020, 1:24 AMInteractiveProcess
sounds like what I want. And Repl
uses that under the hood.hundreds-father-404
10/08/2020, 1:28 AMhundreds-father-404
10/08/2020, 1:29 AM./pants --loop
will allow you to restart the notebook upon changesjolly-midnight-72759
10/08/2020, 1:30 AMjolly-midnight-72759
10/08/2020, 1:31 AM