This repository was archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
205 lines (157 loc) · 5.47 KB
/
Copy pathtasks.py
File metadata and controls
205 lines (157 loc) · 5.47 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import contextlib
import os
import sys
import tempfile
from invoke import task
from invoke.exceptions import UnexpectedExit
REPO_DIR = os.path.dirname(__file__)
class Log(object):
def __init__(self, out=sys.stdout, err=sys.stderr):
self.out = out
self.err = err
def flush(self):
self.out.flush()
self.err.flush()
def write(self, message):
self.flush()
self.out.write(message + "\n")
self.out.flush()
def info(self, message):
self.write("[INFO] %s" % message)
def warn(self, message):
self.write("[WARN] %s" % message)
log = Log()
@task(default=True)
def help(ctx):
"""List available tasks and usage."""
ctx.run("invoke --list")
log.write('Use "invoke -h <taskname>" to get detailed help for a task.')
@task
def clean(ctx, interactive=True):
"""Cleans the local copy from compiled artifacts."""
cmd = "git clean -xd"
if interactive:
cmd += " --interactive"
with chdir(REPO_DIR): # change dir to show paths relative to repo root
ctx.run(cmd)
@task(
help={
"clean": "True to clean repo before building docsstarting.",
"check_links": "True to check all web links in docs for validity.",
}
)
def docs(ctx, clean=False, check_links=False):
"""Build package's HTML documentation."""
pass # not implemented yet
# if clean:
# clean(ctx)
# with chdir(REPO_DIR):
# opts = "-E" if clean else ""
# ctx.run("sphinx-build {} -b html docs dist/docs".format(opts))
# if check_links:
# linkcheck(ctx)
@task()
def check(ctx):
"""Check the consistency of documentation, coding style and a few other things."""
with chdir(REPO_DIR):
log.write("Running all pre-commit hooks on whole repository.")
ctx.run("pre-commit run --all-files")
@task
def build(ctx):
"""Build project."""
with chdir(REPO_DIR):
ctx.run("python -m build")
@task
def raise_if_dirty(ctx):
"""Raise if there's modified or untracked files in repository."""
try:
ctx.run('test -z "$(git status --porcelain)"')
except UnexpectedExit:
raise Exception("Working directory contains changes or untracked files.")
@task()
def linkcheck(ctx):
"""Check links in documentation."""
with chdir(REPO_DIR):
log.write("Running link check...")
ctx.run("sphinx-build -b linkcheck docs dist/docs")
@task(
help={
"doctest": "True to run doctest on all modules, otherwise False.",
}
)
def test(ctx, doctest=False):
"""Run all tests."""
with chdir(REPO_DIR):
cmd = ["pytest"]
if doctest:
cmd.append("--doctest-modules")
ctx.run(" ".join(cmd))
@task
def prepare_changelog(ctx):
"""Prepare changelog for next release."""
unreleased_changelog_template = (
"## Unreleased\n\n### Added\n\n### Changed\n\n### Removed\n\n\n## "
)
commit_msg = "[skip ci] Prepare changelog for next release"
with chdir(REPO_DIR):
# Preparing changelog for next release
with open("CHANGELOG.md", "r+") as changelog:
content = changelog.read()
changelog.seek(0)
changelog.write(content.replace("## ", unreleased_changelog_template, 1))
ctx.run('git add CHANGELOG.md && git commit -m "{}"'.format(commit_msg))
@task(
help={
"gh_io_folder": "Folder where GH_IO.dll is located. Defaults to the Rhino 6.0 installation folder (platform-specific).", # noqa: E501
"ironpython": "Command for running the IronPython executable. Defaults to `ipy`.", # noqa: E501
}
)
def build_ghuser_components(ctx, gh_io_folder=None, ironpython=None):
"""Build Grasshopper user objects from source"""
with chdir(dirname=REPO_DIR):
with tempfile.TemporaryDirectory("actions.ghcomponentizer") as action_dir:
source_dir = os.path.abspath(
"src/compas_convert/rhino/grasshopper_components"
)
target_dir = os.path.join(source_dir, "ghuser")
repo_url = (
"https://github.com/compas-dev/compas-actions.ghpython_components.git"
)
ctx.run("git clone {} {}".format(repo_url, action_dir))
if not gh_io_folder:
import compas_ghpython
gh_io_folder = compas_ghpython.get_grasshopper_plugin_path("6.0")
if not ironpython:
ironpython = "ipy"
gh_io_folder = os.path.abspath(gh_io_folder)
componentizer_script = os.path.join(action_dir, "componentize.py")
ctx.run(
'{} {} {} {} --ghio "{}"'.format(
ironpython,
componentizer_script,
source_dir,
target_dir,
gh_io_folder,
)
)
@task(
pre=[raise_if_dirty, clean, check, test, build, docs, build_ghuser_components],
help={"new_version": "Version number to release"},
post=[prepare_changelog],
)
def release(ctx, new_version):
"""Releases the project in one swift command."""
# Bump version and git tag it
ctx.run("git -s tag {}".format(new_version))
@contextlib.contextmanager
def chdir(dirname=None):
current_dir = os.getcwd()
try:
if dirname is not None:
os.chdir(dirname)
yield
finally:
os.chdir(current_dir)