Skip to content

Support platformdirs as drop-in replacement for appdirs#1598

Open
robjarawan wants to merge 1 commit into
developmentfrom
fix/1493-platformdirs
Open

Support platformdirs as drop-in replacement for appdirs#1598
robjarawan wants to merge 1 commit into
developmentfrom
fix/1493-platformdirs

Conversation

@robjarawan

@robjarawan robjarawan commented Mar 20, 2026

Copy link
Copy Markdown
Contributor
Summary
  • Feature detection now supports Alternate_modules — if the primary module isn't found, alternates are tried before disabling the feature. The appdirs feature lists platformdirs as an alternate.
  • At import time, platformdirs is preferred over appdirs since appdirs is unmaintained and unavailable on RHEL9. Both provide the same API for the three functions we use (site_config_dir, user_config_dir, user_cache_dir).
  • Packaging changes (debian/control, RPM spec, pyproject.toml) are left out of this PR since those depend on target platform decisions — figured I'd leave that to whoever knows the packaging side best:D.

Closes #1493

Test plan
  • Verify sr3 features shows appdirs as present when only platformdirs is installed
  • Verify sr3 features shows appdirs as present when only appdirs is installed
  • Verify fallback to hardcoded Linux paths when neither is installed
  • Verify config/cache directories resolve correctly on each platform

@robjarawan robjarawan self-assigned this Mar 20, 2026
@github-actions

github-actions Bot commented Mar 20, 2026

Copy link
Copy Markdown

Test Results

321 tests   320 ✅  1m 43s ⏱️
  1 suites    1 💤
  1 files      0 ❌

Results for commit 2360ca4.

♻️ This comment has been updated with latest results.

@reidsunderland

Copy link
Copy Markdown
Member

The alternate features thing is interesting, I like how it's an easy automatic substitution.

But thinking ahead towards the eventual removal of appdirs, I'm not sure that the extra code is necessary, and it might cause confusion for users. With the proposed change, when platformdirs is installed, sr3 features will show that appdirs is installed, which is misleading.

Adding platformdirs as a whole separate feature and importing like this might be a little simpler:

if features['platformdirs']['present']:
    import platformdirs as appdirs
elif features['appdirs']['present']:
    import appdirs

It's just a design/opinion thing. @andreleblanc11 or @petersilva do you have any preference?

Hopefully I don't get hit with the wrath of AI for this :D

@robjarawan

robjarawan commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

So I reworked this to use your approach - platformdirs is its own feature entry now instead of the Alternate_modules thing. That way sr3 features actually shows which package you have installed instead of being misleading. platformdirs gets preferred when both are present. Pushed in the latest commit.

@reidsunderland

Copy link
Copy Markdown
Member

I don't see any new code on this branch, did you use a different branch or maybe forgot to push the change?

@robjarawan

Copy link
Copy Markdown
Contributor Author

Woops, I had it stashed locally and forgot to push — just pushed the fix. platformdirs and appdirs are now separate feature entries instead of using the Alternate_modules fallback. Should be good now!

@robjarawan robjarawan force-pushed the fix/1493-platformdirs branch from e8a5d25 to 2360ca4 Compare May 18, 2026 02:26
@robjarawan

Copy link
Copy Markdown
Contributor Author

Pushed a refresh for this branch.

This is now rebased onto current development, so the merge conflict should be gone.

@reidsunderland the code that was missing before is definitely in this branch now:

  • platformdirs is its own feature entry in sarracenia/featuredetection.py
  • appdirs and platformdirs are reported independently by feature detection
  • sarracenia/__init__.py prefers platformdirs when present, falls back to appdirs, then falls back to the hardcoded Linux paths
  • the old Alternate_modules fallback is not used

I also added focused tests so this is explicit:

  • test_platformdirs_is_a_separate_feature
  • test_platformdirs_preferred_over_appdirs
  • test_appdirs_used_when_platformdirs_missing

Tests:

  • python3 -m pytest tests/sarracenia/featuredetection_test.py tests/sarracenia/platformdirs_import_test.py -v - 3 passed
  • pycodestyle --max-line-length=119 tests/sarracenia/featuredetection_test.py tests/sarracenia/platformdirs_import_test.py - passed
  • git diff --check - passed

@reidsunderland

Copy link
Copy Markdown
Member

This looks good, thanks for the updates.

I should have noted this before, but the packaging stuff should also be updated to prefer platformdirs where available.

There's a lot of places to adjust and I'm not completely sure how to set up alternatives for each. In Debian we can use:

python3-platformdirs | python3-appdirs

But I'm not sure about the others. If you want we could merge this PR and deal with that separately?

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.

Replace appdirs with platform dirs?

2 participants