Skip to content

Commit

Permalink
Ensure get_cache_dir works with relative paths (#131)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ssbarnea and pre-commit-ci[bot] authored Mar 17, 2022
1 parent f056ef8 commit 2140084
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ansible_compat/prerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_cache_dir(project_dir: str) -> str:
# we would use the same key regardless the location of the user home
# directory or where the project is clones (as long the project folder uses
# the same name).
basename = os.path.basename(project_dir).encode(encoding="utf-8")
basename = os.path.basename(os.path.abspath(project_dir)).encode(encoding="utf-8")
# 6 chars of entropy should be enough
cache_key = hashlib.sha256(basename).hexdigest()[:6]
cache_dir = (
Expand Down
11 changes: 11 additions & 0 deletions test/test_prerun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Tests for ansible_compat.prerun module."""
import os

from ansible_compat.prerun import get_cache_dir


def test_get_cache_dir_relative() -> None:
"""Test behaviors of get_cache_dir."""
relative_path = "."
abs_path = os.path.abspath(relative_path)
assert get_cache_dir(relative_path) == get_cache_dir(abs_path)
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ setenv =
PIP_DISABLE_PIP_VERSION_CHECK = 1
PIP_CONSTRAINT = {toxinidir}/constraints.txt
PRE_COMMIT_COLOR = always
PYTEST_REQPASS = 73
PYTEST_REQPASS = 74
FORCE_COLOR = 1
allowlist_externals =
ansible
sh

[testenv:lint]
Expand Down

0 comments on commit 2140084

Please sign in to comment.