-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
181 lines (146 loc) · 5 KB
/
justfile
File metadata and controls
181 lines (146 loc) · 5 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
set shell := ["bash", "-uc"]
python_version := "3.9"
remote_url := "https://raw.githubusercontent.com/shapediver/OpenApiSpecifications"
remote_tag_prefix := "gb_v2"
remote_file_name := "geometry_backend_v2.yaml"
spec_file := "oas_spec.yaml"
target_dir := "./out"
# Path of the local OAS repository.
oas_repo := "../OpenApiSpecifications/"
# Executes the 'build' recipe.
default: build
# Creates a virtual environment and installs the package and its dependencies.
setup:
# Check Python version.
# Run `pyenv install -v {{python_version}}` to install globally.
command -v python{{python_version}}
# Creates a virtual environment for Python.
python{{python_version}} -m venv './.venv'
# Update pip.
.venv/bin/python{{python_version}} -m pip install --upgrade pip
# Install dependencies.
.venv/bin/python{{python_version}} -m pip install -e . \
-r 'requirements.txt' \
-r 'requirements_dev.txt'
# Removes the virtual environment and all build artifacts
reset: clean
rm -rf './.venv'
find . -type d -path './src/*' -name '__pycache__' -exec rm -rf {} \; || :
find . -type d -path './tests/*' -name '__pycache__' -exec rm -rf {} \; || :
# Builds the Python package.
[no-exit-message]
build:
tox -e build
# Removes Python build artifacts.
clean:
tox -e clean
# Run all Python tests.
[no-exit-message]
test:
tox
# Run all pre-commit hooks.
[no-exit-message]
check:
pre-commit run --all-files
# Release the Python package with the specified version.
release version:
# Stop when repo is dirty
test -z "$(git diff --shortstat)"
# Update sdk version number.
case $(uname -s) in \
Linux) \
sed -i \
's/_sdk_version = ".*"/_sdk_version = "{{version}}"/' \
"./src/shapediver/geometry_api_v2/sd_client.py" \
;; \
Darwin) \
sed -i '' \
's/_sdk_version = ".*"/_sdk_version = "{{version}}"/' \
"./src/shapediver/geometry_api_v2/sd_client.py" \
;; \
*) exit 1 ;; \
esac
# Build package and docs.
rm -rf './dist'
tox -e docs
# Commit and tag.
git add -A .
git commit -m "Publish v{{version}}"
git tag -a "v{{version}}" -m "Publish v{{version}}"
# Build the package - the package version is taken from the Git tag.
tox -e build
# Publish to test registry and then to PyPI.
tox -e publish
tox -e publish -- --repository pypi
# Pushing branch main and tag v{{version}} to Git
git push --atomic origin v{{version}} main
# Generate the Python client from the OpenAPI specification.
generate version:
# Ensure that the generator is installed.
command -v openapi-generator-cli
# Stop when repo is dirty
test -z "$(git diff --shortstat)"
# Either link local file or fetch the requested version of the specification.
if [ "{{version}}" == "local" ]; then \
\cp "{{oas_repo}}/geometry_backend_v2.yaml" "{{spec_file}}" ; \
else \
curl -f \
"{{remote_url}}/{{remote_tag_prefix}}%40{{version}}/{{remote_file_name}}" \
-o "{{spec_file}}" ; \
fi
# Generate the Python client.
mkdir -p "{{target_dir}}"
openapi-generator-cli generate \
--package-name "shapediver.geometry_api_v2.client" \
--generate-alias-as-model \
-i "{{spec_file}}" \
-g python \
-o "{{target_dir}}" || { \
rm -rf "{{target_dir}}"; \
exit 1; \
}
# Replace old client with new one.
rm -rf "src/shapediver/geometry_api_v2/client/" || :
cp -r "{{target_dir}}/shapediver/geometry_api_v2/client" "src/shapediver/geometry_api_v2/"
just _update-deps
# Clean up.
rm -rf "{{target_dir}}"
# Commit changes.
if [ "{{version}}" != "local" ]; then \
git add -A . ; \
git commit -m "Generate spec version {{version}}" ; \
fi
# Tests the Python client generation with the current version of the checked out OAS repo.
test-generator:
openapi-generator-cli generate \
--package-name "shapediver.geometry_api_v2.client" \
--generate-alias-as-model \
--dry-run \
-i "{{oas_repo}}/geometry_backend_v2.yaml" \
-g python
# Updates dependencies.
_update-deps:
#!/usr/bin/env bash
src="{{target_dir}}/requirements.txt"
dist="requirements.txt"
start=$(grep -Fn 'AUTO-GENERATED CODE: START' "${dist}" | cut -f1 -d:)
end=$(grep -Fn 'AUTO-GENERATED CODE: END' "${dist}" | cut -f1 -d:)
# Delete old dependencies.
case $(uname -s) in
Linux) sed -i "$(($start + 1)),$(($end - 1))d" "${dist}" ;;
Darwin) sed -i '' "$(($start + 1)),$(($end - 1))d" "${dist}" ;;
*) exit 1 ;;
esac
# Insert new dependencies.
deps="$(cat "${src}")"
while IFS= read -r line; do
case $(uname -s) in
Linux) sed -i "/AUTO-GENERATED CODE: END/i \ ${line}" "${dist}" ;;
Darwin)
sed -i '' "/AUTO-GENERATED CODE: END/i\\
${line}
" "${dist}"
;;
*) exit 1 ;;
esac
done <<< "${deps}"