From f072bb622fb1608754f0df43ac484b2d82a68105 Mon Sep 17 00:00:00 2001 From: David Paz Date: Fri, 15 Jul 2022 14:49:26 +0200 Subject: [PATCH] Move get_template_path function to pakcage utils Moved out the function from testing package to project main package. --- pre_commit_hooks/prepare_commit_msg.py | 2 +- pre_commit_hooks/util.py | 6 ++++++ testing/util.py | 5 ----- tests/prepare_commit_msg_test.py | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pre_commit_hooks/prepare_commit_msg.py b/pre_commit_hooks/prepare_commit_msg.py index c8ff3e8..ef91ad2 100644 --- a/pre_commit_hooks/prepare_commit_msg.py +++ b/pre_commit_hooks/prepare_commit_msg.py @@ -8,7 +8,7 @@ from jinja2 import Template from pre_commit_hooks.util import CalledProcessError from pre_commit_hooks.util import cmd_output -from testing.util import get_template_path +from pre_commit_hooks.util import get_template_path def get_current_branch() -> str: diff --git a/pre_commit_hooks/util.py b/pre_commit_hooks/util.py index d6c90ae..64c026f 100644 --- a/pre_commit_hooks/util.py +++ b/pre_commit_hooks/util.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os import subprocess from typing import Any @@ -30,3 +31,8 @@ def zsplit(s: str) -> list[str]: return s.split('\0') else: return [] + + +def get_template_path(path: str) -> str: + parent_dir = os.path.abspath(os.path.join(os.getcwd(), os.pardir)) + return os.path.join(parent_dir, 'templates', path) diff --git a/testing/util.py b/testing/util.py index fb735b3..2bbbe64 100644 --- a/testing/util.py +++ b/testing/util.py @@ -14,8 +14,3 @@ def get_resource_path(path): def git_commit(*args, **kwargs): cmd = ('git', 'commit', '--no-gpg-sign', '--no-verify', '--no-edit', *args) subprocess.check_call(cmd, **kwargs) - - -def get_template_path(path): - parent_dir = os.path.abspath(os.path.join(TESTING_DIR, os.pardir)) - return os.path.join(parent_dir, 'templates', path) diff --git a/tests/prepare_commit_msg_test.py b/tests/prepare_commit_msg_test.py index e066cd6..d2a4c7e 100644 --- a/tests/prepare_commit_msg_test.py +++ b/tests/prepare_commit_msg_test.py @@ -6,7 +6,7 @@ from pre_commit_hooks.prepare_commit_msg import get_current_branch from pre_commit_hooks.prepare_commit_msg import main from pre_commit_hooks.prepare_commit_msg import update_commit_file from pre_commit_hooks.util import cmd_output -from testing.util import get_template_path +from pre_commit_hooks.util import get_template_path def test_current_branch(temp_git_dir):