mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Adhere to XDG specification for cache dir.
This commit is contained in:
parent
ef8347cf2d
commit
0120af56a7
9 changed files with 50 additions and 17 deletions
|
|
@ -8,7 +8,9 @@ from pre_commit.util import rmtree
|
|||
|
||||
|
||||
def clean(runner):
|
||||
if os.path.exists(runner.store.directory):
|
||||
rmtree(runner.store.directory)
|
||||
output.write_line('Cleaned {}.'.format(runner.store.directory))
|
||||
legacy_path = os.path.expanduser('~/.pre-commit')
|
||||
for directory in (runner.store.directory, legacy_path):
|
||||
if os.path.exists(directory):
|
||||
rmtree(directory)
|
||||
output.write_line('Cleaned {}.'.format(directory))
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -28,10 +28,11 @@ def _log_and_exit(msg, exc, formatted):
|
|||
_to_bytes(exc), b'\n',
|
||||
))
|
||||
output.write(error_msg)
|
||||
output.write_line('Check the log at ~/.pre-commit/pre-commit.log')
|
||||
store = Store()
|
||||
store.require_created()
|
||||
with open(os.path.join(store.directory, 'pre-commit.log'), 'wb') as log:
|
||||
log_path = os.path.join(store.directory, 'pre-commit.log')
|
||||
output.write_line('Check the log at {}'.format(log_path))
|
||||
with open(log_path, 'wb') as log:
|
||||
output.write(error_msg, stream=log)
|
||||
output.write_line(formatted, stream=log)
|
||||
raise SystemExit(1)
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ def _get_default_directory():
|
|||
`Store.get_default_directory` can be mocked in tests and
|
||||
`_get_default_directory` can be tested.
|
||||
"""
|
||||
return os.environ.get(
|
||||
'PRE_COMMIT_HOME',
|
||||
os.path.join(os.path.expanduser('~'), '.pre-commit'),
|
||||
return os.environ.get('PRE_COMMIT_HOME') or os.path.join(
|
||||
os.environ.get('XDG_CACHE_HOME') or os.path.expanduser('~/.cache'),
|
||||
'pre-commit',
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue