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

Add site user base directory to config and data paths if site.ENABLE_USER_SITE is true #242

Merged
merged 11 commits into from
Oct 13, 2021

Conversation

jasongrout
Copy link
Member

This allows someone to install Jupyter components in the Python user directory (for example, with pip install —user) and Jupyter will see them. It seems like a natural extension of our user-level directories.

Fixes #221

@minrk - I'm curious what you think of this change.

…USER_SITE is true

Fixes jupyter#221

This allows someone to install Jupyter components in the Python user directory (for example, with pip install —user) and Jupyter will see them.
@jasongrout jasongrout marked this pull request as draft October 6, 2021 06:09
@jasongrout
Copy link
Member Author

Setting as draft since we should add better tests and documentation (for example, how to disable this directory by setting the PYTHONNOUSERSITE variable or calling python with -s, etc.).

@minrk
Copy link
Member

minrk commented Oct 6, 2021

@jasongrout I just had an occasion where I almost made this PR myself, so 👍 from me.

@jasongrout jasongrout added this to the 4.9 milestone Oct 7, 2021
@jasongrout
Copy link
Member Author

Thanks for your review, Min! I added tests, docs, and a note in the --debug printout.

@jasongrout
Copy link
Member Author

@minrk - if my polishing additions look good to you, can you merge? Thanks!

@vidartf
Copy link
Contributor

vidartf commented Oct 12, 2021

@jasongrout I see there was a comment about duplicates in data? Is that expected?

@vidartf
Copy link
Contributor

vidartf commented Oct 12, 2021

AFAICT, the duplicate comes from this logic that is only applied to data dirs:

if sys.platform == 'darwin':
return os.path.join(home, 'Library', 'Jupyter')
elif os.name == 'nt':
appdata = os.environ.get('APPDATA', None)
if appdata:
return str(Path(appdata, 'jupyter').resolve())
else:
return pjoin(jupyter_config_dir(), 'data')
else:
# Linux, non-OS X Unix, AIX, etc.
xdg = env.get("XDG_DATA_HOME", None)
if not xdg:
xdg = pjoin(home, '.local', 'share')

Does this logic overlap partially/fully with that of site.getuserbase() ?

@jasongrout
Copy link
Member Author

It appears that the code path is if %APPDATA% is defined to be the home .local directory, then we see that duplicate? I'm not sure if it is coincidence or not that the user base directory appears to also be that same directory.

We can at least check for a duplicate and not add the directory if there would be a duplicate. That would at least avoid the issue of having to look twice in the same directory.

It appears that sometimes on Windows the jupyter_data_dir is the same as the directory derived from getuserbase, so we check for the duplicate before adding a new directory.

See jupyter#221 (comment) for a situation with a duplicate directory.
@jasongrout
Copy link
Member Author

We can at least check for a duplicate and not add the directory if there would be a duplicate. That would at least avoid the issue of having to look twice in the same directory.

Done in 7a8e44c

@minrk minrk merged commit 29000fe into jupyter:master Oct 13, 2021
@minrk
Copy link
Member

minrk commented Oct 13, 2021

Thanks!

@jasongrout
Copy link
Member Author

Thanks everyone!

I'll make an RC for 4.9 with this PR, targeting a release for next week.

@jasongrout jasongrout mentioned this pull request Oct 13, 2021
@jasongrout
Copy link
Member Author

I just released 4.9.0 to pypi.

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

Successfully merging this pull request may close these issues.

Should ~/.local/etc/jupyter be part of the default config path?
3 participants