Skip to content

Replace appdirs with platformdirs #96

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

manselmi
Copy link

@manselmi manselmi commented Apr 28, 2025

Summary

Replace the appdirs dependency with platformdirs, an actively-maintained fork.

Also, declare platformdirs as a dependency in pyproject.toml.

Details

Today I used pystow for the first time, and encountered a ModuleNotFoundError after setting the environment variable PYSTOW_USE_APPDIRS to true:

% env -- PYSTOW_USE_APPDIRS=true python -c 'import pystow'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import pystow
  File "/Users/manselmi/virtualenv/pystow-py313/lib/python3.13/site-packages/pystow/__init__.py", line 101, in <module>
    ensure_readme()
    ~~~~~~~~~~~~~^^
  File "/Users/manselmi/virtualenv/pystow-py313/lib/python3.13/site-packages/pystow/utils.py", line 1070, in ensure_readme
    readme_path = get_home(ensure_exists=True).joinpath("README.md")
                  ~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/Users/manselmi/virtualenv/pystow-py313/lib/python3.13/site-packages/pystow/utils.py", line 1029, in get_home
    from appdirs import user_data_dir
ModuleNotFoundError: No module named 'appdirs'

I hadn't noticed the warning in docs/source/installation.rst about needing to manually install appdirs, as I had looked only at the top-level README, which didn't contain a similar warning. The desire to avoid manual installation of appdirs motivated me to submit a PR to declare it as a dependency in pyproject.toml.

However, given that appdirs is deprecated and platformsdirs is a suggested replacement, I figured I should take this opportunity to replace appdirs with platformdirs.

Now, the user may set the environment variable PYSTOW_USE_PLATFORMDIRS (or
PYSTOW_USE_APPDIRS for backwards compatibility) to opt-in to the platform-specific user data directory.

[appdirs is
deprecated](https://github.com/ActiveState/appdirs/blob/8734277956c1df3b85385e6b308e954910533884/README.rst?plain=1#L4),
so replace appdirs with the actively-maintained fork
[platformdirs](https://github.com/tox-dev/platformdirs).

Additionally, declare platformdirs as a dependency in `pyproject.toml` to avoid a
`ModuleNotFoundError` when setting `PYSTOW_USE_PLATFORMDIRS`.
In `constants.py`, note that `PYSTOW_USE_APPDIRS` is retained for backwards
@manselmi
Copy link
Author

Edited summary to include demonstration of import pystow failing when PYSTOW_USE_APPDIRS is true

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.

1 participant