nebari-dev / jhub-apps

Application creator and general launcher for JupyterHub
https://jhub-apps.nebari.dev/
BSD 3-Clause "New" or "Revised" License
27 stars 12 forks source link

[ENH] - Improved working directory support #520

Open mcg1969 opened 1 week ago

mcg1969 commented 1 week ago

Feature description

From the docs:

Also, be aware that jhub-apps may be launching your app from a different directory than you used during development. Therefore, its important to always define absolute paths in your apps. For example, if you use pathlib to define a path, you'll need to call .resolve() in order to make it absolute.

This should not be so, in my view. It is reasonable for application developers to assume that the working directory of their application is relative to the notebook or script being run—in fact, most commonly, the working directory is the location of said notebook or script. This allows them to use relative paths to load datasets or other assets.

Breaking this assumption is going to saddle application developers with the requirement to write additional code throughout their application that resolves relative paths. Indeed, it's not actually clear to me how a notebook is supposed to even determine where it lives. At least with a script I have the __file__ magic variable, but I am unaware of an equivalent for notebooks. And of course, the minute an application is shared with others, that code might need to be changed.

My preference is that the default working directory is the os.path.dirname of the script or notebook. If this could be made configurable, that would be good, but honestly it's difficult for me to see the value in doing anything different.

Value and/or benefit

See above

Anything else?

No response