generated from rochacbruno/python-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.py
105 lines (81 loc) · 2.84 KB
/
make.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
import shutil
from pathlib import Path
import typer
os.environ["PYTHONIOENCODING"] = "utf-8"
app = typer.Typer()
HERE = Path(__file__).parent
@app.command()
def release(tag: str):
print(f"WARNING: This operation will create version {tag=} and push to github")
typer.confirm("Do you want to continue?", abort=True)
Path("piecash2/VERSION").write_text(tag)
print(f"creating git tag : {tag}")
os.system(f"git tag {tag}")
os.system("gitchangelog > HISTORY.md")
os.startfile("HISTORY.md")
typer.confirm("Did you update the changelog?", abort=True)
os.system("git add piecash2/VERSION HISTORY.md")
os.system(f'git commit -m "release: version {tag}')
os.system("git push -u origin HEAD --tags")
print("Github Actions will detect the new tag and release the new version.")
@app.command()
def lint():
"""lint: ## Run pep8, black, mypy linters."""
os.system("flake8 piecash2/")
os.system("black -l 140 --check piecash2/")
os.system("black -l 140 --check tests/")
os.system("mypy --ignore-missing-imports piecash2/")
@app.command()
def fmt():
"""fmt: ## Format code using black & isort."""
os.system("isort piecash2/")
os.system("black -l 140 piecash2/")
os.system("black -l 140 tests/")
@app.command()
def docs():
"""fmt: ## Format code using black & isort."""
os.system("mkdocs build")
os.startfile(Path(__file__).parent / "site" / "index.html")
@app.command()
def clean():
"""clean: ## Clean up unused files."""
patterns = [
"**/*.pyc",
"**/__pycache__",
"**/Thumbs.db",
"**/*~",
".cache",
".pytest_cache",
".mypy_cache",
".tox",
"build",
"dist",
"*.egg-info",
"htmlcov",
"docs/_build",
]
for fp in patterns:
for f in HERE.glob(fp):
if f.is_file():
f.unlink()
else:
shutil.rmtree(f)
@app.command()
def test():
"""test: ## Run tests and generate coverage report."""
os.system("pytest -v --cov-config .coveragerc --cov=piecash2 -l --tb=short --maxfail=1 tests/")
os.system("coverage xml")
os.system("coverage html")
os.startfile(HERE / "htmlcov" / "index.html")
@app.command()
def schema():
"""schema: ## Generate the schema from the sqlite database using sqlacodegen."""
import piecash2.schema.generation.schema_generation as schema_generation
import piecash2.schema.generated as generated
schema_generation.path_schemas = Path(generated.__file__).parent
print(f"Generating schemas in {schema_generation.path_schemas}")
for book in (HERE / "data").glob("*.gnucash"):
schema_generation.generate_schema(book, schema_generation.get_schema_name(book))
if __name__ == "__main__":
app()