1+ # https://taskfile.dev/usage/
2+ # https://pkg.go.dev/text/template
3+ # https://go-task.github.io/slim-sprig/
14version : " 3"
25
36vars :
7+ TASKFILE_DIR :
8+ sh : pwd
49 # The path to the virtual environment to use when using a virtual
510 # environment.
6- VENV_PATH : ' {{default ".venv" (env "VENV_PATH" )}}'
11+ VENV_PATH : ' {{(env "VENV_PATH") | default (osClean (print .TASKFILE_DIR "/.venv") )}}'
712 # Non empty string results in tasks using a virtual environment.
8- WITH_VENV : ' {{env "WITH_VENV"}}'
13+ WITH_VENV : ' {{env "WITH_VENV" | default "false" }}'
914 # The virtual environemtn specific python interpreter to use.
10- VENV_PYTHON : ' {{if (eq OS "windows")}}{{.VENV_PATH}}/Scripts/python.exe{{else}}{{.VENV_PATH}}/bin/python{{end}}'
15+ VENV_BINPREFIX : ' {{if (mustFromJson .WITH_VENV)}}{{if (eq OS "windows")}}{{.VENV_PATH}}/Scripts/{{else}}{{.VENV_PATH}}/bin/{{end}}{{end}}'
16+ VENV_PYTHON : ' {{if (eq OS "windows")}}{{.VENV_BINPREFIX}}python.exe{{else}}{{.VENV_BINPREFIX}}python{{end}}'
1117 # The python interpreter to use.
1218 PYTHON : python
13- _PYTHON : ' {{if .WITH_VENV}}{{.VENV_PYTHON}}{{else}}{{.PYTHON}}{{end}}'
14- # Non empty string results in java being installed as a system dependency.
15- INSTALL_SYSTEM_DEPS_JAVA : " "
16- # Non empty string results in extras being installed with pip.
17- INSTALL_PIP_EXTRAS : " "
18- # Non empty string results in extensive tests being ran and dependencies for
19- # extensive tests being installed.
20- EXTENSIVE : " "
19+ _PYTHON : ' {{if (mustFromJson .WITH_VENV)}}{{.VENV_PYTHON}}{{else}}{{.PYTHON}}{{end}}'
20+ # Truthish values ("true", "1", etc.) results in java being installed as a
21+ # system dependency.
22+ INSTALL_SYSTEM_DEPS_JAVA : " false"
23+ # Truthish values ("true", "1", etc.) results in extras being installed with
24+ # pip.
25+ INSTALL_PIP_EXTRAS : " false"
26+ # Truthish values ("true", "1", etc.) results in extensive tests being ran and
27+ # dependencies for extensive tests being installed.
28+ EXTENSIVE : " false"
2129 # The python version for which tox should run, empty string does not restrict
2230 # python versions.
2331 TOX_PYTHON_VERSION : " "
24- TEST_HARNESS : ' {{if (and .EXTENSIVE (not (eq OS "windows")))}}./with-fuseki.sh{{end}} '
25- # A non empty string results in github specific things being done.
26- WITH_GITHUB_ACTIONS : " "
27- # A non empty string results in coverage being generated for relevant
28- # commands.
29- WITH_COVERAGE : " "
32+ TEST_HARNESS : ' {{if (and (mustFromJson .EXTENSIVE) (not (eq OS "windows")))}}./with-fuseki.sh{{end}} '
33+ # Truthish values ("true", "1", etc.) results in github specific things being
34+ # done.
35+ WITH_GITHUB_ACTIONS : " false"
36+ # Truthish values ("true", "1", etc.) results in coverage being generated for
37+ # relevant commands.
38+ WITH_COVERAGE : " false"
3039
3140tasks :
3241 install:system-deps :
@@ -35,27 +44,27 @@ tasks:
3544 - echo "OS = {{OS}}"
3645 - echo "ARCH = {{ARCH}}"
3746 - |
38- {{if (and .EXTENSIVE (eq OS "linux"))}}
47+ {{if (and (mustFromJson .EXTENSIVE) (eq OS "linux"))}}
3948 if type apt-get >/dev/null 2>&1
4049 then
4150 sudo apt-get install -y libdb-dev
4251 elif type dnf >/dev/null 2>&1
4352 then
4453 sudo dnf install -y libdb-devel
4554 fi
46- {{else if (and .EXTENSIVE (eq OS "darwin"))}}
55+ {{else if (and (mustFromJson .EXTENSIVE) (eq OS "darwin"))}}
4756 brew install berkeley-db@4
4857 {{end}}
4958
5059 install:tox :
5160 desc : Install tox
5261 cmds :
53- - " {{._PYTHON}} -m pip install tox {{if .WITH_GITHUB_ACTIONS}}tox-gh-actions{{end}}"
62+ - ' {{._PYTHON}} -m pip install tox {{if (mustFromJson .WITH_GITHUB_ACTIONS) }}tox-gh-actions{{end}}'
5463
5564 install:pip-deps :
5665 desc : Install pip dependencies
5766 cmds :
58- - " {{._PYTHON}} -m pip install --upgrade -r requirements.txt -r requirements.dev.txt -r docs/sphinx-requirements.txt {{if .INSTALL_PIP_EXTRAS}}-r requirements.dev-extras.txt{{end}}"
67+ - ' {{._PYTHON}} -m pip install --upgrade -r requirements.txt -r requirements.dev.txt -r docs/sphinx-requirements.txt {{if (mustFromJson .INSTALL_PIP_EXTRAS) }}-r requirements.dev-extras.txt{{end}}'
5968
6069 install:flake8 :
6170 desc : Install flake8 dependencies
@@ -82,6 +91,22 @@ tasks:
8291 - task : _rimraf
8392 vars : { _PYTHON: "{{.PYTHON}}", RIMRAF_TARGET: "{{.VENV_PATH}}" }
8493
94+ venv:run :
95+ desc : Run a command inside the venv
96+ cmds :
97+ - cmd : |
98+ VIRTUAL_ENV="{{.VENV_PATH}}" PATH="{{.VENV_PATH}}/bin${PATH:+:${PATH}}" {{.CLI_ARGS}}
99+
100+ run :
101+ desc : Run a command. If WITH_VENV is truthish, the command will be run inside the virtual environment.
102+ cmds :
103+ - cmd : |
104+ {{if (mustFromJson .WITH_VENV)}}
105+ VIRTUAL_ENV="{{.VENV_PATH}}" PATH="{{.VENV_PATH}}/bin${PATH:+:${PATH}}" {{.CLI_ARGS}}
106+ {{else}}
107+ {{.CLI_ARGS}}
108+ {{end}}
109+
85110 tox :
86111 desc : Run tox
87112 cmds :
@@ -95,36 +120,50 @@ tasks:
95120 -m tox \
96121 {{.CLI_ARGS}}
97122 env :
98- TOXENV : ' {{if .TOX_PYTHON_VERSION}}py{{mustRegexReplaceAll "^([0-9]+)[.]([0-9]+).*" .TOX_PYTHON_VERSION "${1}${2}"}}{{if .EXTENSIVE}}-extensive{{end}}{{.TOXENV_SUFFIX | default ""}}{{end}}'
123+ TOXENV : ' {{if .TOX_PYTHON_VERSION}}py{{mustRegexReplaceAll "^([0-9]+)[.]([0-9]+).*" .TOX_PYTHON_VERSION "${1}${2}"}}{{if (mustFromJson .EXTENSIVE) }}-extensive{{end}}{{.TOXENV_SUFFIX | default ""}}{{end}}'
99124 test :
100125 desc : Run tests
101126 cmds :
102- - " {{.TEST_HARNESS}}{{._PYTHON}} -m pytest {{if .WITH_COVERAGE}}--cov --cov-report={{end}} {{.CLI_ARGS}}"
127+ - ' {{.TEST_HARNESS}}{{.VENV_BINPREFIX}} pytest {{if (mustFromJson .WITH_COVERAGE) }}--cov --cov-report={{end}} {{.CLI_ARGS}}'
103128
104129 flake8 :
105130 desc : Run flake8
106131 cmds :
107132 - " {{._PYTHON}} -m flakeheaven lint {{.CLI_ARGS}}"
108133
134+ black :
135+ desc : Run black
136+ cmds :
137+ - ' {{._PYTHON}} -m black {{if (mustFromJson (.CHECK | default "false"))}}--check --diff {{end}}{{.CLI_ARGS | default "."}}'
138+ isort :
139+ desc : Run isort
140+ cmds :
141+ - ' {{._PYTHON}} -m isort {{if (mustFromJson (.CHECK | default "false"))}}--check --diff {{end}}{{.CLI_ARGS | default "."}}'
142+ mypy :
143+ desc : Run mypy
144+ cmds :
145+ - " {{._PYTHON}} -m mypy --show-error-context --show-error-codes"
146+
109147 lint:fix :
110148 desc : Fix auto-fixable linting errors
111149 cmds :
112- - " {{._PYTHON}} -m black . "
113- - " {{._PYTHON}} -m isort . "
150+ - task : isort
151+ - task : black
114152
115153 lint :
116154 desc : Perform linting
117155 cmds :
118- - " {{._PYTHON}} -m isort --check --diff ."
119- - " {{._PYTHON}} -m black --check --diff ."
156+ - task : isort
157+ vars : { CHECK: true }
158+ - task : black
159+ vars : { CHECK: true }
120160 - task : flake8
121161
122-
123162 validate:static :
124163 desc : Perform static validation
125164 cmds :
126165 - task : lint
127- - " {{._PYTHON}} -m mypy --show-error-context --show-error-codes "
166+ - task : mypy
128167
129168 validate:fix :
130169 desc : Fix auto-fixable validation errors.
@@ -217,7 +256,7 @@ tasks:
217256 - task : install:system-deps
218257 - task : install:tox
219258 vars :
220- WITH_GITHUB_ACTIONS : 1
259+ WITH_GITHUB_ACTIONS : true
221260 - cmd : " {{._PYTHON}} -m pip install coveralls"
222261 - task : tox
223262 vars :
0 commit comments