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

Use platformdirs for path locations #292

Merged
merged 36 commits into from Sep 27, 2022
Merged

Conversation

blink1073
Copy link
Member

Fixes #234

@blink1073
Copy link
Member Author

I don't think we can make this change, I'm running into ActiveState/appdirs#167.

  File "C:\hostedtoolcache\windows\Python\3.10.7\x64\lib\site-packages\appdirs.py", line 134, in site_data_dir

    path = os.path.normpath(_get_win_folder("CSIDL_COMMON_APPDATA"))

  File "C:\hostedtoolcache\windows\Python\3.10.7\x64\lib\site-packages\appdirs.py", line 481, in _get_win_folder_with_pywin32

    dir = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0)

pywintypes.com_error: (-2147024893, 'The system cannot find the path specified.', None, None)

@blink1073
Copy link
Member Author

Looks like platformdirs is a drop-in replacement and is maintained.

@blink1073 blink1073 changed the title Use appdirs for path locations Use platformdirs for path locations Sep 26, 2022
@jasongrout
Copy link
Member

Looks like platformdirs is a drop-in replacement and is maintained.

And maintained by Bernat, at that. 👍

@jasongrout
Copy link
Member

How should we manage the transition? I can imagine this will be a big pain to people that have configs in our hardcoded places. At the very least, it seems like we should have a deprecation period for the old directories. Probably even better is to have an opt-in to the new behavior on this next major version (with deprecation of old directories), and an opt-out in the major version after that, then final removal of old directories in the major version after that?

@blink1073
Copy link
Member Author

Probably even better is to have an opt-in to the new behavior on this next major version (with deprecation of old directories), and an opt-out in the major version after that, then final removal of old directories in the major version after that?

Yeah, that sounds reasonable.

@jasongrout
Copy link
Member

To elaborate more, here's a proposal: we have a JUPYTER_PLATFORM_DIRS environment variable (or a better name?)? If JUPYTER_PLATFORM_DIRS is truthy, we apply this new logic, and if it is falsey we apply the old logic.

  • In version 5, if JUPYTER_PLATFORM_DIRS is not defined, we assume it is falsey. We also introduce a deprecation warning when using the old logic. (However, there is a question about how we might make sure users get the deprecation warning. We might use logic similar to what we introduced in ipywidgets to bubble the deprecation from Calculate correct stack level for deprecation warnings to show them to the user jupyter-widgets/ipywidgets#3569)
  • In version 6, we flip the default so that if JUPYTER_PLATFORM_DIRS is not defined, we assume it is truthy
  • In version 7, we remove the environment variable checks and old logic.

blink1073 and others added 3 commits September 26, 2022 21:01
…iable.

We also consolidate where we check the variable so that it is simple to change the default.
@jasongrout
Copy link
Member

@blink1073 - I pushed a commit consolidating the environment checking to a single function that also uses our envset utility function.

@jasongrout
Copy link
Member

@blink1073 - this all looks good to me now. If it looks good to you, I think we can merge. Thanks!

@blink1073 blink1073 merged commit 51be5af into jupyter:main Sep 27, 2022
@blink1073 blink1073 deleted the use-appdirs branch September 27, 2022 20:17
@blink1073
Copy link
Member Author

Great! I'll cut a 5.0 rc tomorrow

@dlqqq
Copy link

dlqqq commented Oct 10, 2022

This change is causing CI failures in my branches. Is the deprecation warning intended to raise an exception?

Build log: https://github.com/jupyter-server/jupyter_server_fileid/actions/runs/3222840389/jobs/5272324591

@dlqqq
Copy link

dlqqq commented Oct 10, 2022

I was able to resolve the failures by explicitly setting JUPYTER_PLATFORM_DIRS=1 in my CI environment. jupyter-server/jupyter_server_fileid@941ab67

@kevin-bates
Copy link
Member

Hi @dlqqq - your pyproject.toml treats warnings encountered in pytest as errors.

Using jupyter-server as an example, this particular DeprecationWarning can be tolerated by adding it to the filters.
(At least that's my understanding of things.)

@dlqqq
Copy link

dlqqq commented Oct 11, 2022

@kevin-bates Ah, you're right. So, warnings.warn() only fails in Pytest and not at runtime? Seems very odd, and I can't find this behavior documented anywhere.

@kevin-bates
Copy link
Member

Yeah, I had to dig a bit, but found this and remember @blink1073 mentioning something about taking a stronger stance regarding warnings in one of his updates.

If you remove the error entry from the filterwarnings entry, pytest will succeed as well (and display the deprecation warning following the tests).

@blink1073
Copy link
Member Author

Yep, that's right, see for example how jupyter_server handles warnings in tests.

@blink1073 blink1073 added this to the 5.0 milestone Nov 7, 2022
JoepVanlier added a commit to lumicks/pylake that referenced this pull request Nov 9, 2022
Adds environment variable to acknowledge that we want to use `platformdirs` to determine which paths to use. See jupyter/jupyter_core#292 for more information.
JoepVanlier added a commit to lumicks/pylake that referenced this pull request Nov 9, 2022
Adds environment variable to acknowledge that we want to use `platformdirs` to determine which paths to use. See jupyter/jupyter_core#292 for more information.
JoepVanlier added a commit to lumicks/pylake that referenced this pull request Nov 9, 2022
Adds environment variable to acknowledge that we want to use `platformdirs` to determine which paths to use. See jupyter/jupyter_core#292 for more information.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Please consider using appdirs
4 participants