|
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. |
2 | 3 | It compares the local template version against the remote template version. |
3 | 4 | It prints a message to the screen if the user should update their template. |
4 | 5 | It will always pass the pre-commit check, i.e. it will always return 0. |
|
9 | 10 | test passed and return 0. |
10 | 11 | """ |
11 | 12 | import argparse |
12 | | -import git |
13 | 13 | import os |
14 | | -import yaml |
15 | 14 | from typing import Sequence |
| 15 | +import git |
| 16 | +import yaml |
16 | 17 | from packaging.version import parse, InvalidVersion |
17 | 18 |
|
18 | | -def check_version(template_url:str) -> int: |
| 19 | +def check_version(template_url:str, copier_answers_file:str) -> int: |
19 | 20 | """The main method""" |
20 | | - copier_answers_file = ".copier-answers.yml" |
21 | 21 |
|
22 | 22 | # If we can't find the file, we'll just return 0 and move on |
23 | 23 | if not os.path.isfile(copier_answers_file): |
@@ -61,15 +61,18 @@ def main(argv: Sequence[str] | None = None) -> int: |
61 | 61 | """Parse input arguments and return results of `check_version`""" |
62 | 62 |
|
63 | 63 | 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", |
65 | 66 | help="The repository URL for the template") |
66 | 67 |
|
| 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 | + |
67 | 72 | args = parser.parse_args(argv) |
68 | 73 |
|
69 | | - lincc_template_url = "https://github.com/lincc-frameworks/python-project-template" |
70 | | - template_url = frozenset(args.remote or lincc_template_url) |
71 | 74 | try: |
72 | | - return check_version(lincc_template_url) |
| 75 | + return check_version(args.template_url, args.copier_answers_file) |
73 | 76 | except Exception: |
74 | 77 | return 0 |
75 | 78 |
|
|
0 commit comments