Skip to content

ENH: Allow overriding user preferences directory with PSYCHOPY_CONFIG_FOLDER environment variable#7207

Merged
TEParsons merged 6 commits intopsychopy:devfrom
wieluk:custom-psychopy-config-location
May 21, 2025
Merged

ENH: Allow overriding user preferences directory with PSYCHOPY_CONFIG_FOLDER environment variable#7207
TEParsons merged 6 commits intopsychopy:devfrom
wieluk:custom-psychopy-config-location

Conversation

@wieluk
Copy link
Copy Markdown
Contributor

@wieluk wieluk commented Apr 22, 2025

This pull request changes psychopy/preferences/preferences.py to let users override PsychoPy’s config folder by setting PSYCHOPY_CONFIG_FOLDER. The new logic checks that the override exists and is readable/writable. It currently applies only to non‑Windows systems (it would be easy to enable on Windows, I’m just not sure if we want to). It works with:

export PSYCHOPY_CONFIG_FOLDER=/path/to/config
psychopy

but the monitors subfolder still defaults to ~/.psychopy3/monitors. The code doesn’t issue a message on invalid/succesfull overrides. Adding one could be a useful follow‑up.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 22, 2025

Codecov Report

Attention: Patch coverage is 35.71429% with 9 lines in your changes missing coverage. Please review.

Project coverage is 12.24%. Comparing base (aa120ee) to head (5568c3f).
Report is 159 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #7207      +/-   ##
==========================================
- Coverage   12.28%   12.24%   -0.04%     
==========================================
  Files         346      347       +1     
  Lines       64005    64349     +344     
==========================================
+ Hits         7860     7882      +22     
- Misses      56145    56467     +322     
Components Coverage Δ
app ∅ <ø> (∅)
boilerplate ∅ <ø> (∅)
library ∅ <ø> (∅)
vm-safe library ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wieluk
Copy link
Copy Markdown
Contributor Author

wieluk commented Apr 24, 2025

I’ve already created a corresponding branch in psychopy_linux_installer that would work with this implementation of the config folder, if this PR is accepted:
wieluk/psychopy_linux_installer@start-wrapper

@wieluk
Copy link
Copy Markdown
Contributor Author

wieluk commented Apr 24, 2025

I would have preferred to add a --config-folder=... flag instead of relying on an environment variable. However, this approach seems more complicated, since the config folder is needed before command-line arguments are parsed.

@peircej
Copy link
Copy Markdown
Member

peircej commented Apr 24, 2025

@TEParsons @mdcutone this seems sensible to me (for other OSs as well as linux, actually)

It would mean, for instance, that we can launch a psychopy process with a deliberately different set of preferences by setting that as an env var while launching the process

@TEParsons
Copy link
Copy Markdown
Contributor

I would have preferred to add a --config-folder=... flag instead of relying on an environment variable. However, this approach seems more complicated, since the config folder is needed before command-line arguments are parsed.

This was my first thought too - I think it's workable still as the only thing prefs is needed for in the arg parsing stage is a default for showSplash. We could have that default to None, then import and setup prefs after parsing args, then say if args.showSplash is None: args.showSplash = prefs.app['showSplash'].

I have an idea of how this could look so I'll submit a PR to your branch :)

@TEParsons
Copy link
Copy Markdown
Contributor

wieluk#1

FF: Use call args rather than environment variable for setting custom prefs dir
@wieluk
Copy link
Copy Markdown
Contributor Author

wieluk commented Apr 24, 2025

Thanks for your help @TEParsons!

However, with your version, the .psychopy3 folder is still being created in the home directory when PsychoPy starts, even when I specify a different directory using --user-dir=/any/other/folder.

As it stands, the folder ends up being created in both locations.
This also results in a strangely split configuration: for example, if I change the theme in Preferences and then delete the .psychopy3 folder in HOME, the theme resets to default on the next launch — even though that preference should have been saved in /any/other/folder.

It seems like PsychoPy is still relying on the home directory for certain settings despite the --user-dir override.

@TEParsons
Copy link
Copy Markdown
Contributor

Ah, I see what you mean... I was testing it by checking that self.paths['userPrefsDir'] was populated correctly, so I missed that the actual prefs weren't changed. I think it's because loadAll is called when prefs is initialised, but isn't called again when we do getPaths with the new directory.

Maybe rather than calling the two separately in __init__, we could have getPaths be called inside loadAll & call that when setting the custom path? I'll update the PR (and test it properly this time!)

@wieluk
Copy link
Copy Markdown
Contributor Author

wieluk commented May 9, 2025

I've updated the PR. It appears to be functioning correctly now. However, it still creates a .psychopy3 directory in both locations. Under /home/.psychopy3, everything except the monitors and themes folders is now empty in /home. Preventing this behavior would likely require a significant refactor of the preferences.

@TEParsons TEParsons marked this pull request as ready for review May 9, 2025 11:09
@TEParsons
Copy link
Copy Markdown
Contributor

I think that's okay :) It'll be creating the folder when initially importing the class, but so long as it doesn't use that folder when told not to it's fine for it to exist.

@TEParsons TEParsons merged commit 9fad03f into psychopy:dev May 21, 2025
7 checks passed
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.

3 participants