Skip to content
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

Add support for the XDG Base Directory Specification. #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions grip/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def __init__(self, source=None, auth=None, renderer=None,
if instance_path is None:
instance_path = os.environ.get('GRIPHOME')
if instance_path is None:
instance_path = DEFAULT_GRIPHOME
instance_path = os.path.expanduser(DEFAULT_GRIPHOME)
if not os.path.exists(instance_path):
instance_path = os.environ.get('XDG_CONFIG_HOME', '~/.config')
instance_path = os.path.join(instance_path, 'grip')
instance_path = os.path.abspath(os.path.expanduser(instance_path))

# Flask application
Expand Down Expand Up @@ -353,7 +356,9 @@ def default_asset_manager(self):
cache_directory = self.config['CACHE_DIRECTORY']
if cache_directory:
cache_directory = cache_directory.format(version=__version__)
cache_path = os.path.join(self.instance_path, cache_directory)
cache_path = os.environ.get('XDG_CACHE_HOME', '~/.cache')
cache_path = os.path.abspath(os.path.expanduser(cache_path))
cache_path = os.path.join(cache_path, 'grip', cache_directory)
return GitHubAssetManager(
cache_path, self.config['STYLE_URLS'], self.quiet)

Expand Down
5 changes: 4 additions & 1 deletion grip/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

Do NOT change the values here for risk of accidentally committing them.
Override them using command-line arguments or with a settings_local.py in
this directory or in ~/.grip/settings.py instead.
this directory or in one of the following (in order of precedence):
1. "${GRIPHOME}/settings.py" (if GRIPHOME is set)
2. "~/.grip/settings.py" (if "~/.grip" exists)
3. "${XDG_CONFIG_HOME:-~/.config}/grip/settings.py" (fallback)
"""


Expand Down