-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtasks.py
More file actions
178 lines (143 loc) · 4.67 KB
/
tasks.py
File metadata and controls
178 lines (143 loc) · 4.67 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import datetime
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, live=False):
"""
Build the documentation
"""
if live:
c.run(
"sphinx-autobuild -b html --watch docs -c docs docs docs/_build/html --ignore docs/data_models/* --open-browser --port 5000"
)
else:
c.run("sphinx-build -E -b html docs docs/_build")
@task(help={"overwrite": "Re-release the current version (overwrite tag if needed)"})
def release(c, overwrite=False):
"""
Release a new version of the app using year.release-number versioning.
"""
if overwrite:
version = c.run("poetry version -s", hide=True).stdout.strip()
print(f"Overwriting release {version}")
else:
# 1. Determine the current year
current_year = datetime.datetime.now().year
# 2. Get the current version
year, num = c.run("poetry version -s", hide=True).stdout.strip().split(".")
year = int(year)
num = int(num)
# 3. Form the new version string
version = f"{current_year}.1" if year != current_year else f"{year}.{num + 1}"
# 4. Update the version in pyproject.toml
c.run(f"poetry version {version}")
# 5. Commit the change
c.run(f'git commit pyproject.toml -m "release v{version}"')
# 6. Delete the existing tag if overwriting
if overwrite:
c.run(f"git tag -d v{version}", warn=True)
c.run(f"git push --delete origin v{version}", warn=True)
# 7. Create a tag and push it
c.run(f'git tag -a v{version} -m "Release {version}"')
c.run("git push --tags")
c.run("git push origin main")
@task
def dumpdata(c):
c.run(
"docker compose -f local.yml run django python manage.py dumpdata users organizations contributors projects"
" datasets samples core --natural-foreign --natural-primary --output=fairdm.json.gz"
)
@task
def loaddata(c):
c.run("docker compose -f local.yml run django python manage.py loaddata core --app fairdm")
@task
def create_fixtures(c, users=75, orgs=25, projects=12):
"""
Build the documentation and open it in a live browser
"""
c.run(
f"docker compose -f local.yml run django python manage.py create_fixtures --users {users} --orgs {orgs} --projects {projects}"
)
@task
def savedemo(c):
"""Save the initial data for the core fairdm app"""
c.run(
" ".join(
[
"python -Xutf8 manage.py dumpdata",
"--natural-foreign",
"--natural-primary",
"-e users.User",
"-e admin.LogEntry",
"-e contenttypes",
"-e auth.Permission",
"-e sessions",
"-o fixtures/demo.json",
]
)
)
@task
def update_deps(c):
"""
Update the project dependencies
"""
packages = [
"django-easy-icons",
"django-literature",
"django-jsonfield-toolkit",
"django-polymorphic-treebeard",
"django-account-management",
"fairdm-docs",
"django-research-vocabs",
"django-setup-tools",
"django-flex-menus",
"cotton-bs5",
"fairdm",
"fairdm-discussions",
"fairdm-geo",
"fairdm-rest-api",
]
c.run(f"poetry update {' '.join(packages)}")
@task
def build_image(c):
c.run("docker build -t ghcr.io/ihfc-iugg/ghfd-portal .")
@task
def screenshots(c):
"""
Take screenshots of the application
"""
c.run(
"cd docs/_static/screenshots && shot-scraper multi shots.yml -a auth.json --auth-password admin --auth-username super.user@example.com"
)