Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update get_path() to return a path relative to root_dir #21

Merged
merged 1 commit into from
Oct 20, 2022

Conversation

dlqqq
Copy link
Collaborator

@dlqqq dlqqq commented Oct 20, 2022

get_path() now returns a path relative to its configured root_dir trait, which should be set to the server root. Developers using jupyter_server_fileid (e.g. scheduling, RTC) have found that relative paths are being used far more in the Jupyter ecosystem than absolute ones, and thus get_path() should default to returning a relative path instead.

To revert back to the old behavior, this can be done manually via:

path = file_id_manager.get_path(id)
os.path.join(file_id_manager.root_dir, path) 

If there is a demonstrated use-case for absolute paths, I'd be happy to add an argument absolute: bool to get_path() that allows for users to be returned an absolute path. However, at the present moment, there are no known usecases for it.

@dlqqq
Copy link
Collaborator Author

dlqqq commented Oct 20, 2022

cc @davidbrochart

@dlqqq dlqqq added the enhancement New feature or request label Oct 20, 2022
@codecov-commenter
Copy link

Codecov Report

Base: 78.49% // Head: 78.18% // Decreases project coverage by -0.30% ⚠️

Coverage data is based on head (562c72f) compared to base (ef5ff9d).
Patch coverage: 70.27% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #21      +/-   ##
==========================================
- Coverage   78.49%   78.18%   -0.31%     
==========================================
  Files           5        5              
  Lines         372      408      +36     
  Branches       52       62      +10     
==========================================
+ Hits          292      319      +27     
- Misses         65       66       +1     
- Partials       15       23       +8     
Impacted Files Coverage Δ
jupyter_server_fileid/manager.py 88.47% <33.33%> (+0.14%) ⬆️
jupyter_server_fileid/pytest_plugin.py 87.65% <73.52%> (-10.27%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dlqqq dlqqq merged commit a4a6683 into jupyter-server:main Oct 20, 2022
return None

# finally, convert the path to a relative one.
path = os.path.relpath(path, self.root_dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to expand the user (to convert ~ into e.g. /home/david)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! The paths stored in the Files table are completely normalized and absolute, meaning they should never contain ~/, ./, or ../. If you are noticing that the returned paths contain any of those substrings, please file a bug report.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @davidbrochart is referring to the value in self.root_dir...

>>> import os
>>> os.path.relpath("/Users/kbates/notebooks/experiments", "~/notebooks")
'../../../../../../../../../notebooks/experiments'
>>> os.path.relpath("/Users/kbates/notebooks", os.path.expanduser("~/notebooks"))
'.'

However, the currently configurable root_dir is validated to ensure its value is absolute. I use currently because this attribute should probably derive from the associated ContentsManager per #24 and not be user-configurable. In that case, the FileID service will likely want to perform the expansion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants