Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 7a92979

Browse files
authored
Merge pull request #451 from TezRomacH/v1.1.1
V1.1.1
2 parents 24f03c1 + 16a4d19 commit 7a92979

File tree

44 files changed

+693
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+693
-309
lines changed

Makefile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#* Variables
22
SHELL := /usr/bin/env bash
33
PYTHON := python
4+
PYTHONPATH := `pwd`
45

56
#* Poetry
67
.PHONY: poetry-download
@@ -16,7 +17,7 @@ poetry-remove:
1617
install:
1718
poetry lock -n && poetry export --without-hashes > requirements.txt
1819
poetry install -n
19-
-poetry run mypy --install-types --non-interactive ./
20+
-poetry run mypy --install-types --non-interactive hooks tests
2021

2122
.PHONY: pre-commit-install
2223
pre-commit-install:
@@ -35,7 +36,8 @@ formatting: codestyle
3536
#* Linting
3637
.PHONY: test
3738
test:
38-
poetry run pytest -c pyproject.toml
39+
PYTHONPATH=$(PYTHONPATH) poetry run pytest -c pyproject.toml --cov-report=html --cov=hooks tests/
40+
poetry run coverage-badge -o assets/images/coverage.svg -f
3941

4042
.PHONY: check-codestyle
4143
check-codestyle:
@@ -58,17 +60,33 @@ lint: test check-codestyle mypy check-safety
5860

5961
.PHONY: update-dev-deps
6062
update-dev-deps:
61-
poetry add -D bandit@latest darglint@latest "isort[colors]@latest" mypy@latest pre-commit@latest pydocstyle@latest pylint@latest pytest@latest pyupgrade@latest safety@latest
63+
poetry add -D bandit@latest darglint@latest "isort[colors]@latest" mypy@latest pre-commit@latest pydocstyle@latest pylint@latest pytest@latest pyupgrade@latest safety@latest coverage@latest coverage-badge@latest pytest-html@latest pytest-cov@latest
6264
poetry add -D --allow-prereleases black@latest
6365

6466
#* Cleaning
6567
.PHONY: pycache-remove
6668
pycache-remove:
6769
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf
6870

71+
.PHONY: dsstore-remove
72+
dsstore-remove:
73+
find . | grep -E ".DS_Store" | xargs rm -rf
74+
75+
.PHONY: mypycache-remove
76+
mypycache-remove:
77+
find . | grep -E ".mypy_cache" | xargs rm -rf
78+
79+
.PHONY: ipynbcheckpoints-remove
80+
ipynbcheckpoints-remove:
81+
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
82+
83+
.PHONY: pytestcache-remove
84+
pytestcache-remove:
85+
find . | grep -E ".pytest_cache" | xargs rm -rf
86+
6987
.PHONY: build-remove
7088
build-remove:
7189
rm -rf build/
7290

73-
.PHONY: clean-all
74-
clean-all: pycache-remove build-remove
91+
.PHONY: cleanup
92+
cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove pytestcache-remove

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
[![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/TezRomacH/python-package-template/blob/master/.pre-commit-config.yaml)
1111
[![Semantic Versions](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--versions-e10079.svg)](https://github.com/TezRomacH/python-package-template/releases)
1212
[![License](https://img.shields.io/github/license/TezRomacH/python-package-template)](https://github.com/TezRomacH/python-package-template/blob/master/LICENSE)
13+
![Coverage Report](assets/images/coverage.svg)
1314

1415
Your next Python package needs a bleeding-edge project structure.
1516
</div>
1617

1718
## TL;DR
1819

1920
```bash
20-
cookiecutter gh:TezRomacH/python-package-template --checkout v1.1.0
21+
cookiecutter gh:TezRomacH/python-package-template --checkout v1.1.1
2122
```
2223

2324
> All you need is the latest version of cookiecutter 😉
@@ -65,7 +66,7 @@ pip install -U cookiecutter
6566
then go to a directory where you want to create your project and run:
6667

6768
```bash
68-
cookiecutter gh:TezRomacH/python-package-template --checkout v1.1.0
69+
cookiecutter gh:TezRomacH/python-package-template --checkout v1.1.1
6970
```
7071

7172
### Input variables
@@ -213,6 +214,12 @@ make check-codestyle
213214

214215
> Note: `check-codestyle` uses `isort`, `black` and `darglint` library
215216
217+
Update all dev libraries to the latest version using one comand
218+
219+
```bash
220+
make update-dev-deps
221+
```
222+
216223
</p>
217224
</details>
218225

@@ -247,7 +254,7 @@ make mypy
247254
</details>
248255

249256
<details>
250-
<summary>6. Tests</summary>
257+
<summary>6. Tests with coverage badges</summary>
251258
<p>
252259

253260
Run `pytest`
@@ -318,10 +325,22 @@ Remove package build
318325
make build-remove
319326
```
320327

321-
Or to remove pycache, build and docker image run:
328+
Delete .DS_STORE files
329+
330+
```bash
331+
make dsstore-remove
332+
```
333+
334+
Remove .mypycache
335+
336+
```bash
337+
make mypycache-remove
338+
```
339+
340+
Or to remove all above run:
322341

323342
```bash
324-
make clean-all
343+
make cleanup
325344
```
326345

327346
</p>

assets/images/coverage.svg

Lines changed: 21 additions & 0 deletions
Loading

hooks/post_gen_project.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""This module is called after project is created."""
2-
3-
from typing import Callable, List
2+
from typing import List
43

54
import textwrap
65
from pathlib import Path
@@ -19,42 +18,58 @@
1918
# Values to generate github repository
2019
GITHUB_USER = "{{ cookiecutter.github_name }}"
2120

22-
licenses = {
21+
licences_dict = {
2322
"MIT": "mit",
2423
"BSD-3": "bsd3",
2524
"GNU GPL v3.0": "gpl3",
2625
"Apache Software License 2.0": "apache",
2726
}
2827

2928

30-
def generate_license() -> None:
31-
"""Generate license file for the project."""
32-
move(f"{PROJECT_DIRECTORY}/_licences/{licenses[LICENSE]}.txt", f"{PROJECT_DIRECTORY}/LICENSE")
33-
rmtree(f"{PROJECT_DIRECTORY}/_licences/")
29+
def generate_license(directory: Path, licence: str) -> None:
30+
"""Generate license file for the project.
31+
32+
Args:
33+
directory: path to the project directory
34+
licence: chosen licence
35+
"""
36+
move(str(directory / "_licences" / f"{licence}.txt"), str(directory / "LICENSE"))
37+
rmtree(str(directory / "_licences"))
38+
3439

40+
def remove_unused_files(directory: Path, module_name: str, need_to_remove_cli: bool) -> None:
41+
"""Remove unused files.
3542
36-
def remove_unused_files() -> None:
37-
"""Remove unused files."""
43+
Args:
44+
directory: path to the project directory
45+
module_name: project module name
46+
need_to_remove_cli: flag for removing CLI related files
47+
"""
3848
files_to_delete: List[Path] = []
3949

4050
def _cli_specific_files() -> List[Path]:
41-
return [Path(f"{PROJECT_DIRECTORY}/{PROJECT_MODULE}/__main__.py")]
51+
return [directory / module_name / "__main__.py"]
4252

43-
if CREATE_EXAMPLE_TEMPLATE != "cli":
53+
if need_to_remove_cli:
4454
files_to_delete.extend(_cli_specific_files())
4555

4656
for path in files_to_delete:
4757
path.unlink()
4858

4959

50-
def print_futher_instuctions() -> None:
51-
"""Show user what to do next after project creation."""
60+
def print_futher_instuctions(project_name: str, github: str) -> None:
61+
"""Show user what to do next after project creation.
62+
63+
Args:
64+
project_name: current project name
65+
github: GitHub username
66+
"""
5267
message = f"""
53-
Your project {PROJECT_NAME} is created.
68+
Your project {project_name} is created.
5469
5570
1) Now you can start working on it:
5671
57-
$ cd {PROJECT_NAME} && git init
72+
$ cd {project_name} && git init
5873
5974
2) If you don't have Poetry installed run:
6075
@@ -74,17 +89,21 @@ def print_futher_instuctions() -> None:
7489
$ git add .
7590
$ git commit -m ":tada: Initial commit"
7691
$ git branch -M main
77-
$ git remote add origin https://github.com/{GITHUB_USER}/{PROJECT_NAME}.git
92+
$ git remote add origin https://github.com/{github}/{project_name}.git
7893
$ git push -u origin main
7994
"""
8095
print(textwrap.dedent(message))
8196

8297

83-
post_functions: List[Callable[[], None]] = [
84-
generate_license,
85-
remove_unused_files,
86-
print_futher_instuctions,
87-
]
98+
def main() -> None:
99+
generate_license(directory=PROJECT_DIRECTORY, licence=licences_dict[LICENSE])
100+
remove_unused_files(
101+
directory=PROJECT_DIRECTORY,
102+
module_name=PROJECT_MODULE,
103+
need_to_remove_cli=CREATE_EXAMPLE_TEMPLATE != "cli",
104+
)
105+
print_futher_instuctions(project_name=PROJECT_NAME, github=GITHUB_USER)
106+
88107

89-
for fn in post_functions:
90-
fn()
108+
if __name__ == "__main__":
109+
main()

hooks/pre_gen_project.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""This module is called before project is created."""
22

3-
from typing import Callable, List
4-
53
import re
64
import sys
75

6+
PROJECT_NAME = "{{ cookiecutter.project_name }}"
7+
PROJECT_VERSION = "{{ cookiecutter.version }}"
8+
LINE_LENGTH_PARAMETER = "{{ cookiecutter.line_length }}"
9+
10+
811
MODULE_REGEX = re.compile(r"^[a-z][a-z0-9\-\_]+[a-z0-9]$")
912
SEMVER_REGEX = re.compile(
1013
r"""
@@ -27,28 +30,30 @@
2730
re.VERBOSE,
2831
)
2932

30-
module_name = "{{ cookiecutter.project_name }}"
31-
version = "{{ cookiecutter.version }}"
32-
line_length = "{{ cookiecutter.line_length }}"
3333

34-
35-
def validate_project_name() -> None:
34+
def validate_project_name(project_name: str) -> None:
3635
"""Ensure that `project_name` parameter is valid.
3736
3837
Valid inputs starts with the lowercase letter.
3938
Followed by any lowercase letters, numbers or underscores.
4039
40+
Args:
41+
project_name: current project name
42+
4143
Raises:
42-
ValueError: If module_name is not a valid Python module name
44+
ValueError: If project_name is not a valid Python module name
4345
"""
44-
if MODULE_REGEX.fullmatch(module_name) is None:
45-
message = f"ERROR: The project name `{module_name}` is not a valid Python module name."
46+
if MODULE_REGEX.fullmatch(project_name) is None:
47+
message = f"ERROR: The project name `{project_name}` is not a valid Python module name."
4648
raise ValueError(message)
4749

4850

49-
def validate_semver() -> None:
51+
def validate_semver(version: str) -> None:
5052
"""Ensure version in semver notation.
5153
54+
Args:
55+
version: string version. For example 0.1.2 or 1.2.4
56+
5257
Raises:
5358
ValueError: If version is not in semver notation
5459
"""
@@ -57,26 +62,29 @@ def validate_semver() -> None:
5762
raise ValueError(message)
5863

5964

60-
def validate_line_length() -> None:
65+
def validate_line_length(line_length: int) -> None:
6166
"""Validate line_length parameter. Length should be between 50 and 300.
6267
68+
Args:
69+
line_length: integer paramenter for isort and black formatters
70+
6371
Raises:
6472
ValueError: If line_length isn't between 50 and 300
6573
"""
66-
if not (50 <= int(line_length) <= 300):
74+
if not (50 <= line_length <= 300):
6775
message = f"ERROR: line_length must be between 50 and 300. Got `{line_length}`."
6876
raise ValueError(message)
6977

7078

71-
validators: List[Callable[[], None]] = [
72-
validate_project_name,
73-
validate_semver,
74-
validate_line_length,
75-
]
76-
77-
for validator in validators:
79+
def main() -> None:
7880
try:
79-
validator()
81+
validate_project_name(project_name=PROJECT_NAME)
82+
validate_semver(version=PROJECT_VERSION)
83+
validate_line_length(line_length=int(LINE_LENGTH_PARAMETER))
8084
except ValueError as ex:
8185
print(ex)
8286
sys.exit(1)
87+
88+
89+
if __name__ == "__main__":
90+
main()

0 commit comments

Comments
 (0)