zrb 0.0.50__py3-none-any.whl → 0.0.52__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zrb/action/runner.py +15 -3
- zrb/builtin/generator/docker_compose_task/template/_automate/snake_task_name.py +1 -1
- zrb/builtin/generator/fastapp/add.py +3 -2
- zrb/builtin/generator/fastapp/template/_automate/snake_app_name/frontend.py +17 -2
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/.gitignore +2 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/Dockerfile +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/config.py +3 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/core/messagebus/rabbitmq/consumer.py +4 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/.gitignore +2 -2
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/package-lock.json +197 -115
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/package.json +7 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/app.html +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/auth/auth.ts +83 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/auth/store.ts +4 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/auth/type.ts +10 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/components/navigation/Menu.svelte +20 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/components/navigation/Navigation.svelte +77 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/components/navigation/type.ts +6 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/config/config.ts +4 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/config/navData.ts +25 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/cookie/cookie.ts +19 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/routes/+layout.svelte +9 -6
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/routes/greetings/[slug]/+page.js +4 -4
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/routes/greetings/[slug]/+page.svelte +3 -7
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/routes/sample/+page.svelte +37 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/routes/sample/delete/[id]/+page.svelte +1 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/static/favicon.png +0 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/static/logo.png +0 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/tailwind.config.js +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/api.py +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/component/authorizer.py +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/component/token_scheme.py +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/core/authorizer/authorizer.py +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/core/authorizer/rpc_authorizer.py +9 -5
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/core/token_scheme/oauth2_bearer_token_scheme.py +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/entity/user/api.py +32 -8
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/entity/user/model.py +60 -52
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/entity/user/rpc.py +23 -8
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/module/auth/schema/request.py +10 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/template.env +4 -0
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/test/auth/test_group_crud.py +3 -3
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/test/auth/test_permission_crud.py +3 -3
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/test/auth/test_user_crud.py +3 -3
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/test/auth/test_user_login.py +12 -12
- zrb/builtin/generator/fastapp_crud/add.py +86 -5
- zrb/builtin/generator/fastapp_crud/nodejs/codemod/.gitignore +1 -0
- zrb/builtin/generator/fastapp_crud/nodejs/codemod/package-lock.json +317 -0
- zrb/builtin/generator/fastapp_crud/nodejs/codemod/package.json +18 -0
- zrb/builtin/generator/fastapp_crud/nodejs/codemod/src/addNav.ts +38 -0
- zrb/builtin/generator/fastapp_crud/nodejs/codemod/tsconfig.json +109 -0
- zrb/builtin/generator/fastapp_crud/template/src/kebab-app-name/test/snake_module_name/test_snake_entity_name.py +3 -3
- zrb/builtin/generator/project/template/.gitignore +1 -1
- zrb/builtin/generator/simple_python_app/template/src/kebab-app-name/src/.gitignore +1 -1
- zrb/task/base_task.py +3 -1
- zrb-0.0.52.dist-info/METADATA +605 -0
- {zrb-0.0.50.dist-info → zrb-0.0.52.dist-info}/RECORD +60 -44
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/components/Navigation.svelte +0 -24
- zrb/builtin/generator/fastapp/template/src/kebab-app-name/src/frontend/src/lib/data/navData.json +0 -5
- zrb-0.0.50.dist-info/METADATA +0 -450
- /zrb/builtin/generator/{fastapp/template/src/kebab-app-name/src/frontend/src/routes/greetings/[slug]/page.js → fastapp_crud/nodejs/codemod/src/fastapp/src/frontend/src/lib/config/navData.ts} +0 -0
- {zrb-0.0.50.dist-info → zrb-0.0.52.dist-info}/LICENSE +0 -0
- {zrb-0.0.50.dist-info → zrb-0.0.52.dist-info}/WHEEL +0 -0
- {zrb-0.0.50.dist-info → zrb-0.0.52.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,605 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: zrb
|
3
|
+
Version: 0.0.52
|
4
|
+
Summary: Your faithful companion
|
5
|
+
Author-email: Go Frendi Gunawan <gofrendiasgard@gmail.com>
|
6
|
+
Requires-Python: >=3.8
|
7
|
+
Description-Content-Type: text/markdown
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Dist: click==8.1.3
|
12
|
+
Requires-Dist: aiofiles==23.1.0
|
13
|
+
Requires-Dist: typeguard==2.13.3
|
14
|
+
Requires-Dist: termcolor==2.2.0
|
15
|
+
Requires-Dist: Jinja2==3.1.2
|
16
|
+
Requires-Dist: libcst==0.4.9
|
17
|
+
Requires-Dist: python-dotenv==0.21.1
|
18
|
+
Requires-Dist: jsons==1.6.3
|
19
|
+
Requires-Dist: ruamel.yaml==0.17.21
|
20
|
+
Requires-Dist: setuptools==49.2.1
|
21
|
+
Requires-Dist: autopep8==2.0.1
|
22
|
+
Requires-Dist: flake8==6.0.0 ; extra == "dev"
|
23
|
+
Requires-Dist: pytest==7.2.1 ; extra == "test"
|
24
|
+
Requires-Dist: pytest-cov==4.0.0 ; extra == "test"
|
25
|
+
Requires-Dist: pytest-xdist==3.2.0 ; extra == "test"
|
26
|
+
Requires-Dist: pytest-asyncio==0.21.0 ; extra == "test"
|
27
|
+
Project-URL: Bug Tracker, https://github.com/state-alchemists/zaruba/issues
|
28
|
+
Project-URL: Homepage, https://github.com/state-alchemists/zaruba
|
29
|
+
Provides-Extra: dev
|
30
|
+
Provides-Extra: test
|
31
|
+
|
32
|
+
# Zrb (WIP): Your Faithful Companion
|
33
|
+
|
34
|
+

|
35
|
+
|
36
|
+
Zrb is a task runner to help you automate day-to-day tasks.
|
37
|
+
# Installation
|
38
|
+
|
39
|
+
```bash
|
40
|
+
pip install zrb
|
41
|
+
```
|
42
|
+
|
43
|
+
# Create a project
|
44
|
+
|
45
|
+
A project is a directory containing a Python file named `zrb_init.py`.
|
46
|
+
|
47
|
+
The recommended way to create a Zrb project is by using Zrb built-in generator. To create a Zrb project using the built-in generator, you can invoke the following command:
|
48
|
+
|
49
|
+
```bash
|
50
|
+
zrb project create --project-dir=my-project
|
51
|
+
```
|
52
|
+
|
53
|
+
To start working on the project, you can invoke the following command:
|
54
|
+
|
55
|
+
```bash
|
56
|
+
source project.sh
|
57
|
+
```
|
58
|
+
|
59
|
+
The command will make you a Python virtual environment, as well as install necessary Python packages.
|
60
|
+
|
61
|
+
## Create a very minimal project
|
62
|
+
|
63
|
+
Aside from the built-in generator, you can also make a project manually by invoking the following command:
|
64
|
+
|
65
|
+
```bash
|
66
|
+
mkdir my-project
|
67
|
+
cd my-project
|
68
|
+
touch zrb_init.py
|
69
|
+
```
|
70
|
+
|
71
|
+
This might be useful for demo/experimentation.
|
72
|
+
|
73
|
+
# Define tasks
|
74
|
+
|
75
|
+
Zrb comes with many types of tasks:
|
76
|
+
|
77
|
+
- Python task
|
78
|
+
- Cmd task
|
79
|
+
- Docker compose task
|
80
|
+
- Http checker
|
81
|
+
- Port Checker
|
82
|
+
- Path Checker
|
83
|
+
- Resource maker
|
84
|
+
|
85
|
+
Every task has its inputs, environments, and upstreams. By defining the upstreams, you can make several tasks run in parallel. Let's see the following example:
|
86
|
+
|
87
|
+
```
|
88
|
+
install-pip --------------------------------------> run-server
|
89
|
+
|
|
90
|
+
install-node-modules ---> build-frontend ----
|
91
|
+
```
|
92
|
+
|
93
|
+
```python
|
94
|
+
# File location: zrb_init.py
|
95
|
+
from zrb import CmdTask, HttpChecker, EnvFile, runner
|
96
|
+
|
97
|
+
# Install pip package for requirements.txt in src directory
|
98
|
+
install_pip_packages = CmdTask(
|
99
|
+
name='install-pip',
|
100
|
+
cmd='pip install -r requirements.txt',
|
101
|
+
cwd='src'
|
102
|
+
)
|
103
|
+
|
104
|
+
# Install node modules in src/frontend directory
|
105
|
+
install_node_modules = CmdTask(
|
106
|
+
name='install-node-modules',
|
107
|
+
cmd='npm install --save-dev',
|
108
|
+
cwd='src/frontend'
|
109
|
+
)
|
110
|
+
|
111
|
+
# Build src/frontend
|
112
|
+
# To build the frontend, you need to make sure that node_modules has already been installed.
|
113
|
+
build_frontend = CmdTask(
|
114
|
+
name='build-frontend',
|
115
|
+
cmd='npm run build',
|
116
|
+
cwd='src/frontend',
|
117
|
+
upstreams=[install_node_modules]
|
118
|
+
)
|
119
|
+
|
120
|
+
# Start the server.
|
121
|
+
# In order to start the server, you need to make sure that:
|
122
|
+
# - Necessary pip packages has been already installed
|
123
|
+
# - Frontend has already been built
|
124
|
+
# By default it should use environment defined in `src/template.env`.
|
125
|
+
# You can set the port using environment variable WEB_PORT
|
126
|
+
# This WEB_PORT environment will be translated into PORT variable internally
|
127
|
+
# You can use the port to check whether a server is ready or not.
|
128
|
+
run_server = CmdTask(
|
129
|
+
name='run-server',
|
130
|
+
envs=[
|
131
|
+
Env(name='PORT', os_name='WEB_PORT', default='3000')
|
132
|
+
],
|
133
|
+
env_files=[
|
134
|
+
EnvFile(env_file='src/template.env', prefix='WEB')
|
135
|
+
]
|
136
|
+
cmd='python main.py',
|
137
|
+
cwd='src',
|
138
|
+
upstreams=[
|
139
|
+
install_pip_packages,
|
140
|
+
build_frontend
|
141
|
+
],
|
142
|
+
checkers=[HTTPChecker(port='{{env.PORT}}')],
|
143
|
+
)
|
144
|
+
runner.register(run_server)
|
145
|
+
```
|
146
|
+
|
147
|
+
Once defined, you can start the server by invoking the following command:
|
148
|
+
|
149
|
+
```bash
|
150
|
+
zrb run-server
|
151
|
+
```
|
152
|
+
|
153
|
+
Zrb will make sure that the tasks are executed in order based on their upstreams.
|
154
|
+
You will also see that `install-pip-packages` and `install-node-modules` are executed in parallel since they are independent of each other.
|
155
|
+
|
156
|
+
# Define a Python task
|
157
|
+
|
158
|
+
Defining a Python task is simple.
|
159
|
+
|
160
|
+
```python
|
161
|
+
from zrb import python_task, Env, StrInput, runner
|
162
|
+
|
163
|
+
@python_task(
|
164
|
+
name='say-hello',
|
165
|
+
inputs=[
|
166
|
+
StrInput(name='name')
|
167
|
+
],
|
168
|
+
envs=[
|
169
|
+
Env(name='PYTHONUNBUFFERED', default=1)
|
170
|
+
],
|
171
|
+
runner=runner
|
172
|
+
)
|
173
|
+
def say_hello(*args, **kwargs) -> str:
|
174
|
+
name = kwargs.get('name')
|
175
|
+
greetings = f'Hello, {name}'
|
176
|
+
task = kwargs.get('_task')
|
177
|
+
task.print_out(greetings)
|
178
|
+
return greetings
|
179
|
+
```
|
180
|
+
|
181
|
+
You can then run the task by invoking:
|
182
|
+
|
183
|
+
```
|
184
|
+
zrb say-hello --name=John
|
185
|
+
```
|
186
|
+
|
187
|
+
Python task is very powerful to do complex logic. You can also use `async` function if you think you need to.
|
188
|
+
|
189
|
+
# Define a Cmd task
|
190
|
+
|
191
|
+
You can define a Cmd task by using `CmdTask` class.
|
192
|
+
|
193
|
+
```python
|
194
|
+
from zrb import CmdTask, StrInput, Env, runner
|
195
|
+
|
196
|
+
say_hello = CmdTask(
|
197
|
+
name='say-hello',
|
198
|
+
inputs=[
|
199
|
+
StrInput(name='name')
|
200
|
+
],
|
201
|
+
envs=[
|
202
|
+
Env(name='SOME_ENV')
|
203
|
+
],
|
204
|
+
cmd='echo {{input.name}}'
|
205
|
+
)
|
206
|
+
runner.register(say_hello)
|
207
|
+
```
|
208
|
+
|
209
|
+
If you need a multi-line command, you can also define the command as a list:
|
210
|
+
|
211
|
+
```python
|
212
|
+
from zrb import CmdTask, StrInput, Env, runner
|
213
|
+
|
214
|
+
say_hello = CmdTask(
|
215
|
+
name='say-hello',
|
216
|
+
inputs=[
|
217
|
+
StrInput(name='name')
|
218
|
+
],
|
219
|
+
envs=[
|
220
|
+
Env(name='SOME_ENV')
|
221
|
+
],
|
222
|
+
cmd=[
|
223
|
+
'echo {{input.name}}',
|
224
|
+
'echo Yeay!!!'
|
225
|
+
]
|
226
|
+
)
|
227
|
+
runner.register(say_hello)
|
228
|
+
```
|
229
|
+
|
230
|
+
However, if your command is too long, you can also load it from other file:
|
231
|
+
|
232
|
+
|
233
|
+
```python
|
234
|
+
from zrb import CmdTask, StrInput, Env, runner
|
235
|
+
|
236
|
+
say_hello = CmdTask(
|
237
|
+
name='say-hello',
|
238
|
+
inputs=[
|
239
|
+
StrInput(name='name')
|
240
|
+
],
|
241
|
+
envs=[
|
242
|
+
Env(name='SOME_ENV')
|
243
|
+
],
|
244
|
+
cmd_path='hello_script.sh'
|
245
|
+
)
|
246
|
+
runner.register(say_hello)
|
247
|
+
```
|
248
|
+
|
249
|
+
|
250
|
+
You can then run the task by invoking:
|
251
|
+
|
252
|
+
```
|
253
|
+
zrb say-hello --name=John
|
254
|
+
```
|
255
|
+
|
256
|
+
|
257
|
+
# Define a Docker Compose task
|
258
|
+
|
259
|
+
Docker Compose is a convenient way to run containers on your local computer.
|
260
|
+
|
261
|
+
Suppose you have the following Docker Compose file:
|
262
|
+
|
263
|
+
```yaml
|
264
|
+
# docker-compose.yml file
|
265
|
+
version: '3'
|
266
|
+
|
267
|
+
services:
|
268
|
+
# The load balancer
|
269
|
+
nginx:
|
270
|
+
image: nginx:1.16.0-alpine
|
271
|
+
volumes:
|
272
|
+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
273
|
+
ports:
|
274
|
+
- "${HOST_PORT:-8080}:80"
|
275
|
+
```
|
276
|
+
|
277
|
+
You can define a task to run your Docker Compose file (i.e., `docker compose up`) like this:
|
278
|
+
|
279
|
+
```python
|
280
|
+
from zrb import DockerComposeTask, HTTPChecker, Env, runner
|
281
|
+
|
282
|
+
run_container = DockerComposeTask(
|
283
|
+
name='run-container',
|
284
|
+
compose_cmd='up',
|
285
|
+
compose_file='docker-compose.yml',
|
286
|
+
envs=[
|
287
|
+
Env(name='HOST_PORT', default='3000')
|
288
|
+
],
|
289
|
+
checkers=[
|
290
|
+
HTTPChecker(
|
291
|
+
name='check-readiness', port='{{env.HOST_PORT}}'
|
292
|
+
)
|
293
|
+
]
|
294
|
+
)
|
295
|
+
runner.register(run_container)
|
296
|
+
```
|
297
|
+
|
298
|
+
# Define checkers
|
299
|
+
|
300
|
+
Some tasks might run forever, and you need a way to make sure whether those tasks are ready or not.
|
301
|
+
|
302
|
+
Let's say you invoke `npm run build:watch`. This command will build your Node.js App into `dist` directory, as well as watch the changes and rebuild your app as soon as there are some changes.
|
303
|
+
|
304
|
+
- You need to start the server after the app has been built for the first time.
|
305
|
+
- You can do this by checking whether the `dist` folder already exists or not.
|
306
|
+
- You can use `PathChecker` for this purpose
|
307
|
+
|
308
|
+
Let's see how to do this:
|
309
|
+
|
310
|
+
```python
|
311
|
+
from zrb import CmdTask, PathChecker, Env, EnvFile, runner
|
312
|
+
|
313
|
+
build_frontend = CmdTask(
|
314
|
+
name='build-frontend',
|
315
|
+
cmd='npm run build',
|
316
|
+
cwd='src/frontend',
|
317
|
+
checkers=[
|
318
|
+
PathChecker(path='src/frontend/dist')
|
319
|
+
]
|
320
|
+
)
|
321
|
+
|
322
|
+
run_server = CmdTask(
|
323
|
+
name='run-server',
|
324
|
+
envs=[
|
325
|
+
Env(name='PORT', os_name='WEB_PORT', default='3000')
|
326
|
+
],
|
327
|
+
env_files=[
|
328
|
+
EnvFile(env_file='src/template.env', prefix='WEB')
|
329
|
+
]
|
330
|
+
cmd='python main.py',
|
331
|
+
cwd='src',
|
332
|
+
upstreams=[
|
333
|
+
build_frontend
|
334
|
+
],
|
335
|
+
checkers=[HTTPChecker(port='{{env.PORT}}')],
|
336
|
+
)
|
337
|
+
runner.register(run_server)
|
338
|
+
```
|
339
|
+
|
340
|
+
Aside from `PathChecker`, Zrb also has `HTTPChecker` and `PortChecker`.
|
341
|
+
|
342
|
+
# Define a resource maker
|
343
|
+
|
344
|
+
ResourceMaker is used to generate resources. Let's say you have a `template` folder containing a file named `app_name.py`:
|
345
|
+
|
346
|
+
```python
|
347
|
+
# file: template/app_name.py
|
348
|
+
message = 'Hello world_name'
|
349
|
+
print(message)
|
350
|
+
```
|
351
|
+
|
352
|
+
You can define a ResourceMaker like this:
|
353
|
+
|
354
|
+
```python
|
355
|
+
from zrb import ResourceMaker, StrInput, runner
|
356
|
+
|
357
|
+
create_hello_world = ResourceMaker(
|
358
|
+
name='create-hello-world',
|
359
|
+
inputs=[
|
360
|
+
StrInput('app-name'),
|
361
|
+
StrInput('world-name'),
|
362
|
+
],
|
363
|
+
replacements={
|
364
|
+
'app_name': '{{input.app_name}}',
|
365
|
+
'world_name': '{{input.world_name}}',
|
366
|
+
},
|
367
|
+
template_path='template',
|
368
|
+
destination_path='.',
|
369
|
+
)
|
370
|
+
runner.register(create_hello_world)
|
371
|
+
```
|
372
|
+
|
373
|
+
Now when you invoke the task, you will get a new file as expected:
|
374
|
+
|
375
|
+
```bash
|
376
|
+
zrb create-hello-world --app-name=wow --world-name=kalimdor
|
377
|
+
echo ./wow.py
|
378
|
+
```
|
379
|
+
|
380
|
+
The result will be:
|
381
|
+
|
382
|
+
```python
|
383
|
+
# file: template/wow.py
|
384
|
+
message = 'Hello kalimdor'
|
385
|
+
print(message)
|
386
|
+
```
|
387
|
+
|
388
|
+
This is a very powerful building block to build anything based on the template.
|
389
|
+
|
390
|
+
# Using Zrb to build an application (WIP)
|
391
|
+
|
392
|
+
You can use Zrb to build a powerful application with a few commands:
|
393
|
+
|
394
|
+
```bash
|
395
|
+
# Create a project
|
396
|
+
zrb project create --project-dir my-project --project-name "My Project"
|
397
|
+
cd my-project
|
398
|
+
|
399
|
+
# Create a Fastapp
|
400
|
+
zrb project add fastapp --project-dir . --app-name "fastapp" --http-port 3000
|
401
|
+
|
402
|
+
# Add library module to fastapp
|
403
|
+
zrb project add fastapp-module --project-dir . --app-name "fastapp" --module-name "library"
|
404
|
+
|
405
|
+
# Add entity named "books"
|
406
|
+
zrb project add fastapp-crud --project-dir . --app-name "fastapp" --module-name "library" \
|
407
|
+
--entity-name "book" --plural-entity-name "books" --column-name "code"
|
408
|
+
|
409
|
+
# Add column to the entity
|
410
|
+
zrb project add fastapp-field --project-dir . --app-name "fastapp" --module-name "library" \
|
411
|
+
--entity-name "book" --column-name "title" --column-type "str"
|
412
|
+
|
413
|
+
# Run Fastapp
|
414
|
+
zrb project start-fastapp
|
415
|
+
|
416
|
+
# Run Fastapp as container
|
417
|
+
zrb project start-fastapp-container
|
418
|
+
|
419
|
+
# Deploy fastapp
|
420
|
+
zrb project deploy-fastapp
|
421
|
+
```
|
422
|
+
|
423
|
+
You should notice that every module in `fastapp` can be deployed/treated as microservices.
|
424
|
+
|
425
|
+
# Autoloaded tasks
|
426
|
+
|
427
|
+
Zrb will automatically load the following task definitions:
|
428
|
+
|
429
|
+
- Every task definition in `ZRB_INIT_SCRIPTS`.
|
430
|
+
- You can use a colon separator (`:`) to define multiple scripts in `ZRB_INIT_SCRIPTS`. For example:
|
431
|
+
```bash
|
432
|
+
ZRB_INIT_SCRIPTS=~/personal/zrb_init.py:~/work/zrb_init.py
|
433
|
+
```
|
434
|
+
- Every task definition in `zrb_init.py` in your current directory.
|
435
|
+
- If Zrb cannot find any in your current directory, it will look at the parent directories until it finds one.
|
436
|
+
- Every built-in task definition given `ZRB_SHOULD_LOAD_BUILTIN` equals `1` or unset.
|
437
|
+
|
438
|
+
# How to run tasks programmatically
|
439
|
+
|
440
|
+
To run a task programmatically, you need to create a `main loop`.
|
441
|
+
|
442
|
+
For example:
|
443
|
+
|
444
|
+
```python
|
445
|
+
from zrb import CmdTask
|
446
|
+
|
447
|
+
cmd_task = CmdTask(
|
448
|
+
name='sample',
|
449
|
+
cmd='echo hello'
|
450
|
+
)
|
451
|
+
main_loop = cmd_task.create_main_loop(env_prefix='')
|
452
|
+
result = main_loop() # This run the task
|
453
|
+
print(result.output) # Should be "hello"
|
454
|
+
```
|
455
|
+
|
456
|
+
# Enable shell completion
|
457
|
+
|
458
|
+
To enable shell completion, you need to set `_ZRB_COMPLETE` variable.
|
459
|
+
|
460
|
+
For `bash`:
|
461
|
+
|
462
|
+
```bash
|
463
|
+
eval $(_ZRB_COMPLETE=bash_source zrb)
|
464
|
+
```
|
465
|
+
|
466
|
+
For `zsh`:
|
467
|
+
|
468
|
+
```bash
|
469
|
+
eval $(_ZRB_COMPLETE=zsh_source zrb)
|
470
|
+
```
|
471
|
+
|
472
|
+
Once set, you will have a shell completion in your session:
|
473
|
+
|
474
|
+
```bash
|
475
|
+
zrb <TAB>
|
476
|
+
zrb md5 hash -<TAB>
|
477
|
+
```
|
478
|
+
|
479
|
+
Visit [click shell completion](https://click.palletsprojects.com/en/8.1.x/shell-completion/) for more information.
|
480
|
+
|
481
|
+
# Configuration
|
482
|
+
|
483
|
+
The following configurations are available:
|
484
|
+
|
485
|
+
- `ZRB_HOME_DIR`: Zrb home directory.
|
486
|
+
- Default: Zrb home directory
|
487
|
+
- `ZRB_LOGGING_LEVEL`: Logging verbosity.
|
488
|
+
- Default: `WARNING`
|
489
|
+
- Possible values:
|
490
|
+
- `CRITICAL`
|
491
|
+
- `ERROR`
|
492
|
+
- `WARNING`
|
493
|
+
- `WARN` (The same as `WARNING`)
|
494
|
+
- `INFO`
|
495
|
+
- `DEBUG`
|
496
|
+
- `NOTSET`
|
497
|
+
- `ZRB_INIT_SCRIPTS`: List of task registration script that should be loaded by default.
|
498
|
+
- Default: Empty
|
499
|
+
- Possible values: List of script paths, separated by colons(`:`).
|
500
|
+
- Example: `~/personal/zrb_init.py:~/work/zrb_init.py`
|
501
|
+
- `ZRB_ENV`: Environment prefix that will be used when loading Operating System's environment.
|
502
|
+
- Default: Empty
|
503
|
+
- Possible values: Any combination of alpha-numeric and underscore
|
504
|
+
- Example: `DEV`
|
505
|
+
- `ZRB_SHOULD_LOAD_BUILTIN`: Whether load builtin tasks or not
|
506
|
+
- Default: `1`
|
507
|
+
- Possible values:
|
508
|
+
- `1`
|
509
|
+
- `0`
|
510
|
+
- `ZRB_SHELL`: Default shell for running cmdTask
|
511
|
+
- Default: `bash`
|
512
|
+
- Possible value:
|
513
|
+
- `/usr/bin/bash`
|
514
|
+
- `/usr/bin/sh`
|
515
|
+
- `ZRB_SHOW_ADVERTISEMENT`: Whether show advertisement or not.
|
516
|
+
- Default: `1`
|
517
|
+
- Possible value:
|
518
|
+
- `1`
|
519
|
+
- `0`
|
520
|
+
- `ZRB_SHOW_PROMPT`: Whether show prompt or not.
|
521
|
+
- Default: `1`
|
522
|
+
- Possible value:
|
523
|
+
- `1`
|
524
|
+
- `0`
|
525
|
+
|
526
|
+
# Quirks
|
527
|
+
|
528
|
+
- No one is sure how to pronounce Zrb. Let's keep it that way.
|
529
|
+
- If not set, `PYTHONUNBUFFERED` will be set to `1`.
|
530
|
+
- Once `zrb_init.py` is loaded, Zrb will automatically:
|
531
|
+
- Set `ZRB_PROJECT_DIR` to `zrb_init.py`'s parent directory.
|
532
|
+
- If loaded as CLI, Zrb will also:
|
533
|
+
- Adding `ZRB_PROJECT_DIR` to `PYTHONPATH`.
|
534
|
+
- Zrb passes several keyword arguments that will be accessible from the task's run method:
|
535
|
+
- `_args`: Shell argument when the task is invoked.
|
536
|
+
- `_task`: Reference to the current task.
|
537
|
+
- You can access the built-in command groups by importing `zrb.builtin_group`.
|
538
|
+
- How environments are loaded:
|
539
|
+
- `env_files` has the lowest priority, it will be overridden by `env`
|
540
|
+
- `env` will override each other, the last one takes greater priority
|
541
|
+
- If you define a `DockerComposeTask`, it will automatically fill your environment with the ones you use in your docker-compose file. The environment defined that way will have a very low priority. They will be overridden by both `env_files` and `env`.
|
542
|
+
|
543
|
+
# For contributors
|
544
|
+
|
545
|
+
There is a toolkit you can use to test whether Zrb is working as intended.
|
546
|
+
|
547
|
+
To use the toolkit, you can invoke the following command:
|
548
|
+
|
549
|
+
```bash
|
550
|
+
source ./project.sh
|
551
|
+
```
|
552
|
+
|
553
|
+
Once you load the toolkit, you can start playing around.
|
554
|
+
|
555
|
+
```bash
|
556
|
+
# Run test and serve coverage.
|
557
|
+
zrb test
|
558
|
+
|
559
|
+
# Test zrb in playground
|
560
|
+
zrb prepare-playground
|
561
|
+
```
|
562
|
+
|
563
|
+
|
564
|
+
# For maintainers
|
565
|
+
|
566
|
+
To publish Zrb, you need a `Pypi` account:
|
567
|
+
|
568
|
+
- Log in or register to [https://pypi.org/](https://pypi.org/)
|
569
|
+
- Create an API token
|
570
|
+
|
571
|
+
You can also create a `TestPypi` account:
|
572
|
+
|
573
|
+
- Log in or register to [https://test.pypi.org/](https://test.pypi.org/)
|
574
|
+
- Create an API token
|
575
|
+
|
576
|
+
Once you have your API token, you need to create a `~/.pypirc` file:
|
577
|
+
|
578
|
+
```
|
579
|
+
[distutils]
|
580
|
+
index-servers =
|
581
|
+
pypi
|
582
|
+
testpypi
|
583
|
+
|
584
|
+
[pypi]
|
585
|
+
repository = https://upload.pypi.org/legacy/
|
586
|
+
username = __token__
|
587
|
+
password = pypi-xxx-xxx
|
588
|
+
[testpypi]
|
589
|
+
repository = https://test.pypi.org/legacy/
|
590
|
+
username = __token__
|
591
|
+
password = pypi-xxx-xxx
|
592
|
+
```
|
593
|
+
|
594
|
+
To publish Zrb, you can do the following:
|
595
|
+
|
596
|
+
```bash
|
597
|
+
source ./project.sh
|
598
|
+
|
599
|
+
# Publish Zrb to TestPypi
|
600
|
+
zrb publish-test
|
601
|
+
|
602
|
+
# Publish Zrb to Pypi
|
603
|
+
zrb publish
|
604
|
+
```
|
605
|
+
|