Skip to content

Commit 2add4e3

Browse files
committed
Fixed input parameters and prevent pre-commit from passing filenames.
1 parent 969839f commit 2add4e3

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

.pre-commit-hooks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
description: Compares local template version to latest available version.
44
entry: check-lincc-frameworks-template-version
55
language: python
6+
pass_filenames: false
67
always_run: true

src/pre_commit_hooks/check_template_version.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""This module is meant to be used in a pre-commit check.
1+
"""This module is meant to be used in a pre-commit check for projects created
2+
from a Copier template.
23
It compares the local template version against the remote template version.
34
It prints a message to the screen if the user should update their template.
45
It will always pass the pre-commit check, i.e. it will always return 0.
@@ -9,15 +10,14 @@
910
test passed and return 0.
1011
"""
1112
import argparse
12-
import git
1313
import os
14-
import yaml
1514
from typing import Sequence
15+
import git
16+
import yaml
1617
from packaging.version import parse, InvalidVersion
1718

18-
def check_version(template_url:str) -> int:
19+
def check_version(template_url:str, copier_answers_file:str) -> int:
1920
"""The main method"""
20-
copier_answers_file = ".copier-answers.yml"
2121

2222
# If we can't find the file, we'll just return 0 and move on
2323
if not os.path.isfile(copier_answers_file):
@@ -61,15 +61,18 @@ def main(argv: Sequence[str] | None = None) -> int:
6161
"""Parse input arguments and return results of `check_version`"""
6262

6363
parser = argparse.ArgumentParser()
64-
parser.add_argument("-r", "--remote", action="append",
64+
parser.add_argument("--template-url",
65+
default="https://github.com/lincc-frameworks/python-project-template",
6566
help="The repository URL for the template")
6667

68+
parser.add_argument("--copier-answers-file",
69+
default=".copier-answers.yml",
70+
help="The name of the copier answers file. Typically .copier-answers.yml")
71+
6772
args = parser.parse_args(argv)
6873

69-
lincc_template_url = "https://github.com/lincc-frameworks/python-project-template"
70-
template_url = frozenset(args.remote or lincc_template_url)
7174
try:
72-
return check_version(lincc_template_url)
75+
return check_version(args.template_url, args.copier_answers_file)
7376
except Exception:
7477
return 0
7578

0 commit comments

Comments
 (0)