-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
96 lines (76 loc) · 2.62 KB
/
tasks.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
from invoke import task
@task
def install(c):
"""
Install the project dependencies
"""
print("🚀 Creating virtual environment using pyenv and poetry")
c.run("poetry install")
c.run("poetry run pre-commit install")
c.run("poetry shell")
@task
def check(c):
"""
Check the consistency of the project using various tools
"""
print("🚀 Checking Poetry lock file consistency with 'pyproject.toml': Running poetry lock --check")
c.run("poetry lock --check")
print("🚀 Linting code: Running pre-commit")
c.run("poetry run pre-commit run -a")
print("🚀 Static type checking: Running mypy")
c.run("poetry run mypy")
print("🚀 Checking for obsolete dependencies: Running deptry")
c.run("poetry run deptry .")
@task
def test(c, tox=False):
"""
Run the test suite
"""
if tox:
print("🚀 Testing code: Running pytest with all tests")
c.run("tox")
else:
print("🚀 Testing code: Running pytest")
c.run("poetry run pytest --cov --cov-config=pyproject.toml --cov-report=html")
@task
def docs(c):
"""
Build the documentation and open it in the browser
"""
c.run("sphinx-apidoc -M -T -o docs/ licensing **/migrations/* -e --force -d 2")
c.run("sphinx-build -E -b html docs docs/_build")
@task
def release(c, rule=""):
"""
Create a new git tag and push it to the remote repository.
.. note::
This will create a new tag and push it to the remote repository, which will trigger a new build and deployment of the package to PyPI.
RULE BEFORE AFTER
major 1.3.0 2.0.0
minor 2.1.4 2.2.0
patch 4.1.1 4.1.2
premajor 1.0.2 2.0.0a0
preminor 1.0.2 1.1.0a0
prepatch 1.0.2 1.0.3a0
prerelease 1.0.2 1.0.3a0
prerelease 1.0.3a0 1.0.3a1
prerelease 1.0.3b0 1.0.3b1
"""
if rule:
# bump the current version using the specified rule
c.run(f"poetry version {rule}")
# 1. Get the current version number as a variable
version_short = c.run("poetry version -s", hide=True).stdout.strip()
version = c.run("poetry version", hide=True).stdout.strip()
# 2. commit the changes to pyproject.toml
c.run(f'git commit pyproject.toml -m "bump to v{version_short}"')
# 3. create a tag and push it to the remote repository
c.run(f'git tag -a v{version_short} -m "{version}"')
c.run("git push --tags")
c.run("git push origin main")
@task
def live_docs(c):
"""
Build the documentation and open it in a live browser
"""
c.run("sphinx-autobuild -b html --host 0.0.0.0 --port 9000 --watch . -c . . _build/html")