diff --git a/hatch.toml b/hatch.toml index 053ff6bfb..4aa700eed 100644 --- a/hatch.toml +++ b/hatch.toml @@ -1,5 +1,6 @@ [build.targets.sdist] include = [ + '.pre-commit-hooks.yaml', 'src/', ] @@ -8,6 +9,9 @@ packages = [ 'src/pre_commit_terraform/', ] +[build.targets.wheel.force-include] +'.pre-commit-hooks.yaml' = 'pre_commit_terraform/_artifacts/.pre-commit-hooks.yaml' + [metadata.hooks.vcs.urls] 'Source Archive' = 'https://github.com/antonbabenko/pre-commit-terraform/archive/{commit_hash}.tar.gz' 'GitHub: repo' = 'https://github.com/antonbabenko/pre-commit-terraform' diff --git a/src/pre_commit_terraform/common.py b/src/pre_commit_terraform/common.py index 05a793287..af15cac28 100644 --- a/src/pre_commit_terraform/common.py +++ b/src/pre_commit_terraform/common.py @@ -13,7 +13,7 @@ import shutil import subprocess from collections.abc import Sequence -from pathlib import Path +from importlib.resources import files as access_artifacts_of from typing import Callable import yaml @@ -305,15 +305,18 @@ def is_hook_run_on_whole_repo(hook_id: str, file_paths: list[str]) -> bool: """ logger.debug('Hook ID: %s', hook_id) - # Get the directory containing `.pre-commit-hooks.yaml` file - git_repo_root = Path(__file__).resolve().parents[5] - hook_config_path = os.path.join(git_repo_root, '.pre-commit-hooks.yaml') + # Get the directory containing the packaged `.pre-commit-hooks.yaml` copy + artifacts_root_path = access_artifacts_of('pre_commit_terraform') / '_artifacts' + pre_commit_hooks_yaml_path = artifacts_root_path / '.pre-commit-hooks.yaml' + pre_commit_hooks_yaml_path.read_text(encoding='utf-8') - logger.debug('Hook config path: %s', hook_config_path) + logger.debug('Hook config path: %s', pre_commit_hooks_yaml_path) # Read the .pre-commit-hooks.yaml file - with open(hook_config_path, 'r', encoding='utf-8') as pre_commit_hooks_yaml: - hooks_config = yaml.safe_load(pre_commit_hooks_yaml) + pre_commit_hooks_yaml_txt = pre_commit_hooks_yaml_path.read_text( + encoding='utf-8', + ) + hooks_config = yaml.safe_load(pre_commit_hooks_yaml_txt) # Get the included and excluded file patterns for the given hook_id for hook in hooks_config: