Skip to content

Use platformdirs package for all user-related file paths #3166

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

Merged
merged 33 commits into from
Apr 9, 2025
Merged

Conversation

krzywon
Copy link
Contributor

@krzywon krzywon commented Jan 3, 2025

Description

This moves our user file handling to the platformdirs package for os preferred pathing. This is used to store log files, configurations, and app data. This was suggested by @llimeht in the wheels discussion in #3161. This automatically creates subfolders for each version so docs no longer require versioning in their paths.

What has changed:

  • No longer storing data in ~/.sasview
    • The files are not all be in the same place depending on the OS
  • Using more OS prefered storage locations for application files
  • Updated calls to the directories to ensure new locations are used for docs, plugin models, the log file, categories, and config files.
  • Added user documentation to let users know where these files live (Waiting on Flatpak info...)

Good ideas, but outside the scope of this PR

  • Add a method to open explorer windows directly to each file directory for to give the user easy access to the directories - OS-agnostic methods to do this don't exist.
  • Copy example data from the as-installed location to the user directory - Working on in separate branch built off this one: https://github.com/SasView/sasview/tree/platfromdirs-example-data-move

Other work to be done:

Fixes #3142

How Has This Been Tested?

CI is able to launch both the Windows and Ubuntu 22 binaries.

Review Checklist:

Documentation (check at least one)

  • There is nothing that needs documenting
  • Documentation changes are in this PR
  • There is an issue open for the documentation

Installers

  • This will affect the installers
    • Windows installer (GH artifact) has been tested (installed and worked)
    • MacOSX installer (GH artifact) has been tested (installed and worked)

Licencing (untick if necessary)

  • The introduced changes comply with SasView license (BSD 3-Clause)

@rozyczko
Copy link
Member

Shouldn't this be now against main?

@krzywon
Copy link
Contributor Author

krzywon commented Mar 28, 2025

Shouldn't this be now against main?

Yes. I'll rebase later today

@krzywon krzywon changed the base branch from release_6.0.1 to main March 28, 2025 14:56
…t-creation to bypass initial permissions issue
Copy link
Contributor

@jamescrake-merani jamescrake-merani left a comment

Choose a reason for hiding this comment

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

It looks like I was wrong at the fortnightly meeting. The problem isn't a GitHub action permission error like I expected as I'm also able to reproduce it on my machine.

I have left a comment on the line I think is the culprit.

Copy link
Contributor

@jamescrake-merani jamescrake-merani left a comment

Choose a reason for hiding this comment

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

It now works on my machine, and code LGTM.

@jamescrake-merani
Copy link
Contributor

I've just noticed this is still marked as a draft. Is there any work left do on this?

@krzywon
Copy link
Contributor Author

krzywon commented Apr 2, 2025

I've just noticed this is still marked as a draft. Is there any work left do on this?

Two items left:

  • Documenting new user file locations (Required)
  • Adding methods and GUI hooks to open user file locations (I strongly suggest this be added now that files are in different places)

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Gates Failed
Enforce advisory code health rules (1 file with Complex Method)

Gates Passed
3 Quality Gates Passed

See analysis details in CodeScene

Reason for failure
Enforce advisory code health rules Violations Code Health Impact
user.py 1 advisory rule 10.00 → 9.69 Suppress

Quality Gate Profile: Clean Code Collective
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@krzywon krzywon added the Discuss At The Call Issues to be discussed at the fortnightly call label Apr 7, 2025
@krzywon
Copy link
Contributor Author

krzywon commented Apr 8, 2025

This is making pathing os specific rather than os agnostic. The previous system didn't care which operating system it was using.

I updated the PR description.

The plugins were copied to ~/Library/Application Support/SasView/plugin_models, including weights. [edit: weights were correctly copied to ~/Library/Application Support/SasView/weights]

Thanks, I updated the documentation with this.

Logs are appended to ~/Library/Logs/SasView/sasview.log

This file already had logs from existing versions of python.

The log file gets copied to the new directory on app launch, if no log exists in the new location.

Bug: The new log entries are missing the date portion of the timestamp.

Fixed.

Feature request: Show the path to the file on disk in the model editor window.

Feature request: Plugin polydispersity distributions are not appearing in the plugin manager.

Beyond the PR scope at this point.

Bug: On my intel mac I'm getting the following when I click "Load File" on the model editor window:

Fixed.

Feature request: Store base doc tree in the application install directory. Only store patches in the user data.

Another beyond the PR scope, though, noted.

Copy link
Contributor

@jamescrake-merani jamescrake-merani left a comment

Choose a reason for hiding this comment

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

Code LGTM. Just a few comments regarding the documentation.

@krzywon krzywon merged commit acec360 into main Apr 9, 2025
15 checks passed
@krzywon krzywon deleted the platfromdirs branch April 9, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discuss At The Call Issues to be discussed at the fortnightly call SasView 6.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linux filepaths do not comply with the XDG Base Directory Specification
4 participants