-
-
Notifications
You must be signed in to change notification settings - Fork 827
Respect local environment configuration for app file storage #4606
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
100jinwoo001
wants to merge
17
commits into
beeware:main
Choose a base branch
from
100jinwoo001:fix-2867-local-storage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f26bc36
Respect local environment configuration for app file storage (#2867)
100jinwoo001 2f71930
Fix #2867: Validate absolute XDG and LOCALAPPDATA paths and add CI re…
100jinwoo001 7263543
Fix line length and trailing whitespace in test_paths.py
100jinwoo001 aa7a41f
Make test_invalid_env_vars async to prevent testbed hang
100jinwoo001 d28cd44
Fix AttributeError by accessing app.paths._impl instead of app._impl.…
100jinwoo001 24127b0
Revert "Fix AttributeError by accessing app.paths._impl instead of ap…
100jinwoo001 db0438e
Initialize paths attribute before testing
100jinwoo001 62a2aac
Revert to f26bc36 (discarding recent failing changes)
100jinwoo001 ee18b57
Fix Qt selection widget flex size and macOS WebKit test flakiness
100jinwoo001 86464b7
Fix trailing whitespace in test_webview.py
100jinwoo001 cffccf1
Update textual/src/toga_textual/paths.py
100jinwoo001 6d5a646
Refactor _app_dir to use base_dir variable
100jinwoo001 234af0d
Address PR feedback: Revert unrelated changes and simplify os.environ…
100jinwoo001 31ea1ad
Fix pre-commit formatting and unused import
100jinwoo001 577da44
fix: address review feedback
100jinwoo001 599b222
fix: address review feedback
100jinwoo001 c97ba8c
Revert unrelated QSizePolicy changes in selection.py
100jinwoo001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Desktop backends now respect user and system environment configuration (`XDG_CONFIG_HOME`, `XDG_DATA_HOME`, `XDG_CACHE_HOME`, and `XDG_STATE_HOME` on Linux; `%LOCALAPPDATA%` on Windows) for application storage paths. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
|
|
@@ -35,41 +36,62 @@ def __init__(self, app): | |
| self.app = app | ||
| assert isinstance(self.app._impl.native, TextualApp) | ||
|
|
||
| @property | ||
| def _win32_app_dir(self): | ||
| local_app_data = os.environ.get("LOCALAPPDATA") | ||
| base_dir = ( | ||
| Path(local_app_data) if local_app_data else (Path.home() / "AppData/Local") | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, |
||
| return base_dir / AUTHOR / FORMAL_NAME | ||
|
|
||
| @property | ||
| def config_path(self): | ||
| if sys.platform == "darwin": | ||
| return Path.home() / f"Library/Preferences/{APP_ID}" | ||
| elif sys.platform == "win32": | ||
| return Path.home() / f"AppData/Local/{AUTHOR}/{FORMAL_NAME}/Config" | ||
| return self._win32_app_dir / "Config" | ||
| else: | ||
| return Path.home() / f".config/{APP_NAME}" | ||
| return ( | ||
| Path(os.environ.get("XDG_CONFIG_HOME") or (Path.home() / ".config")) | ||
| / APP_NAME | ||
| ) | ||
|
|
||
| @property | ||
| def data_path(self): | ||
| if sys.platform == "darwin": | ||
| return Path.home() / f"Library/Application Support/{APP_ID}" | ||
| elif sys.platform == "win32": | ||
| return Path.home() / f"AppData/Local/{AUTHOR}/{FORMAL_NAME}/Data" | ||
| return self._win32_app_dir / "Data" | ||
| else: | ||
| return Path.home() / f".local/share/{APP_NAME}" | ||
| return ( | ||
| Path(os.environ.get("XDG_DATA_HOME") or (Path.home() / ".local/share")) | ||
| / APP_NAME | ||
| ) | ||
|
|
||
| @property | ||
| def cache_path(self): | ||
| if sys.platform == "darwin": | ||
| return Path.home() / f"Library/Caches/{APP_ID}" | ||
| elif sys.platform == "win32": | ||
| return Path.home() / f"AppData/Local/{AUTHOR}/{FORMAL_NAME}/Cache" | ||
| return self._win32_app_dir / "Cache" | ||
| else: | ||
| return Path.home() / f".cache/{APP_NAME}" | ||
| return ( | ||
| Path(os.environ.get("XDG_CACHE_HOME") or (Path.home() / ".cache")) | ||
| / APP_NAME | ||
| ) | ||
|
|
||
| @property | ||
| def logs_path(self): | ||
| if sys.platform == "darwin": | ||
| return Path.home() / f"Library/Logs/{APP_ID}" | ||
| elif sys.platform == "win32": | ||
| return Path.home() / f"AppData/Local/{AUTHOR}/{FORMAL_NAME}/Logs" | ||
| return self._win32_app_dir / "Logs" | ||
| else: | ||
| return Path.home() / f".local/state/{APP_NAME}/log" | ||
| return ( | ||
| Path(os.environ.get("XDG_STATE_HOME") or (Path.home() / ".local/state")) | ||
| / APP_NAME | ||
| / "log" | ||
| ) | ||
|
|
||
| async def assert_event_loop(self): | ||
| pytest.skip("Event loop assertions are not implemented on Textual.") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import os | ||
| from functools import cached_property | ||
| from pathlib import Path | ||
|
|
||
|
|
@@ -13,7 +14,11 @@ def _app_dir(self): | |
| # No coverage testing of this because we can't easily configure | ||
| # the app to have no author. | ||
| author = "Unknown" if App.app.author is None else App.app.author | ||
| return Path.home() / f"AppData/Local/{author}/{App.app.formal_name}" | ||
| local_app_data = os.environ.get("LOCALAPPDATA") | ||
| base_dir = ( | ||
| Path(local_app_data) if local_app_data else (Path.home() / "AppData/Local") | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same again - fallback mode can be used to simplify things. |
||
| return base_dir / author / App.app.formal_name | ||
|
|
||
| # The rest are cached at the interface level: | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't remove comments that are still accurate, correct, and unrelated to the changes that you're making.