I'm trying to find a way to access the path of the notebook file (.ipynb) that I'm currently editing, in a way that would work either in ArcGIS Pro or in an external IDE like Jupyter or VS-code. What I've done in the past, with ArcGIS Pro 2.8 (and possibly 2.9), is to use os.getcwd()to provide the folder that the current file being edited is in. This works in an external IDE but doesn't work in ArcGIS Pro anymore.
In Pro, something like the following will work, at least with the default workspace location, to provide the project folder:
os.path.dirname(arcpy.env.workspace)
... and that os.path.dirname() method will of course also work if we know the path for the notebook file itself. However the same method will not work when editing the file with an external IDE like VS-code or Jupyter, since there's no knowledge of the default workspace for the project, and indeed there's no knowledge of the ArcGIS Pro project at all: our file is just sitting in a folder.
I purposefully standardize on editing these notebook files in the project folder (a slightly modified logic would work if I used a 'source' or 'notebooks' folder within the project folder just to keep things organized), to keep things simple for students; they can do things differently if they need to down the road as they get more comfortable. But currently, in ArcGIS Pro 3, os.getcwd() just returns
'C:\\WINDOWS\\system32'
which is clearly not the project folder, and not where the .ipynb file I'm editing is located. There are what would seem to be obvious advantages in being able to edit a notebook either in ArcGIS Pro or an external IDE, and go back and forth, but I haven't figured out how to do this in ArcGIS Pro 3.
And here's a typical situation I want to work in both places, to set the workspace to a geodatabase "pen.gdb" in my project folder, thus providing code that is portable within the project folder, and an easy way to create other resources (e.g. geodatabases, folders) within that project folder.
import arcpy, os
projdir = os.getcwd()
arcpy.env.workspace = projdir + "\\pen.gdb"
It all boils down to a simple question: Where is what I'm editing?
Environment: [ArcGIS Pro 3.0.3, installed on my computer for all users, not just my user profile; Windows 10]