Skip to content

Commit 0f2accb

Browse files
Update config files and post hook installation messages (#5)
* Updating post hook debug messages and adding pytest and coverage to pre-commit hook * Excluding toml and yaml files from project_slug due to presence of jinja syntax
1 parent ab656e0 commit 0f2accb

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ repos:
1010
stages: [push]
1111
- id: check-toml
1212
stages: [push]
13+
exclude: "{{ cookiecutter.project_slug }}/pyproject.toml"
1314
- id: check-yaml
1415
stages: [push]
16+
exclude: "{{ cookiecutter.project_slug }}/.pre-commit-config.yaml"
1517
- id: end-of-file-fixer
1618
stages: [push]
1719
- id: trailing-whitespace
@@ -28,18 +30,19 @@ repos:
2830
- id: flake8
2931
name: Running flake8 from local poetry env
3032
entry: poetry run flake8 .
31-
language: python
33+
language: system
3234
files: ".*.py"
3335
exclude: "{{ cookiecutter.project_slug }}"
3436
- id: isort
3537
name: Running isort from local poetry env
3638
entry: poetry run isort .
37-
language: python
39+
language: system
3840
files: ".*.py"
3941
exclude: "{{ cookiecutter.project_slug }}"
4042
- id: lizard
4143
name: Running lizard from local poetry env
4244
entry: poetry run lizard
4345
# Max 7 arguments allowed, show only warnings, sort by CCN, exclude .venv
4446
args: ["--CCN", "8", "-a", "7", "-w", "-s", "cyclomatic_complexity", "-x", ".\\.venv\\*"]
45-
language: python
47+
language: system
48+
files: ".*.py"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ A [Cookiecutter](https://github.com/cookiecutter/cookiecutter) template for a Py
3434
python -m cookiecutter https://github.com/gurashish1singh/cookiecutter-python.git
3535
```
3636
- This template uses post-project generation hooks to:
37-
- Initialize a git repository (with default branch as main), IF the working directory is not already a git repository
37+
- Initialize a git repository (with default branch as main), IF the working directory is not already a git repository.
38+
39+
**NOTE**: You will have to create a repositry on remote if it doesn't already exist before running the cookiecutter command.
3840
- Create a Poetry virtualenv
3941
- Install all dependencies
4042
- Install the pre-commit and pre-push hooks

hooks/post_gen_project.py

100644100755
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
import sys
77
from pathlib import Path
88

9-
ERROR_MSG = "Error occured while running cmd"
9+
ERROR_MSG = "Error occured while running command"
1010
PRETTY_LINES = "*" * 80
1111

1212

1313
def main() -> int:
1414
working_dir = Path().resolve()
1515
git_dir = Path(working_dir, ".git")
16-
ret_code_one = 0
16+
return_code_one = 0
1717
if not git_dir.exists():
18-
ret_code_one = initialize_git()
18+
return_code_one = initialize_git()
1919

20-
if ret_code_one == 0:
21-
ret_code_two = setup_environment()
22-
return ret_code_one or ret_code_two or 0
20+
if return_code_one == 0:
21+
return_code_two = setup_environment()
22+
return 0 or return_code_one or return_code_two
2323

2424

2525
def initialize_git() -> int:
@@ -30,7 +30,8 @@ def initialize_git() -> int:
3030
),
3131
"init_git": (
3232
shlex.split("git init"),
33-
"Initializing an empty git repository\n",
33+
"Initializing an empty git repository locally. You will have to create a repo "
34+
"on remote.\n",
3435
),
3536
}
3637
for cmds, message in COMMANDS_AND_MESSAGE.values():

{{ cookiecutter.project_slug }}/.pre-commit-config.yaml

100644100755
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
default_stages: [commit]
23
repos:
34
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -37,7 +38,26 @@ repos:
3738
files: ".*.py"
3839
- id: lizard
3940
name: Running lizard from local poetry env
40-
entry: poetry run lizard .
41+
entry: poetry run lizard
4142
# Max 7 arguments allowed, show only warnings, sort by CCN, exclude .venv
4243
args: ["--CCN", "8", "-a", "7", "-w", "-s", "cyclomatic_complexity", "-x", ".\\.venv\\*"]
4344
language: python
45+
{% if cookiecutter.pytest == "y" -%}
46+
- id: pytest
47+
name: Running tests using pytest from local poetry env
48+
entry: poetry run coverage run -m pytest
49+
args: ["-x"]
50+
language: system
51+
types:
52+
- python
53+
pass_filenames: false
54+
stages: [push]
55+
- id: coverage
56+
name: Generating coverage report
57+
entry: poetry run coverage report -m
58+
language: system
59+
types:
60+
- python
61+
pass_filenames: false
62+
stages: [push]
63+
{%- endif %}

{{ cookiecutter.project_slug }}/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ plugins = ["covdefaults"]
4040

4141
[tool.coverage.report]
4242
fail_under = 95
43+
omit = [
44+
"logger.py"
45+
]
4346
{%- endif %}
4447

4548
[build-system]

0 commit comments

Comments
 (0)