-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevelopment.html
More file actions
113 lines (103 loc) · 22.4 KB
/
development.html
File metadata and controls
113 lines (103 loc) · 22.4 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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Development | opa-stack</title>
<meta name="description" content="">
<meta name="generator" content="VuePress 1.3.0">
<link rel="preload" href="/assets/css/0.styles.a2b7d327.css" as="style"><link rel="preload" href="/assets/js/app.4e27d91f.js" as="script"><link rel="preload" href="/assets/js/3.ab9a3b8e.js" as="script"><link rel="preload" href="/assets/js/10.15db5ece.js" as="script"><link rel="prefetch" href="/assets/js/11.b8f9ff69.js"><link rel="prefetch" href="/assets/js/12.3a8e2acb.js"><link rel="prefetch" href="/assets/js/13.e8dd8de7.js"><link rel="prefetch" href="/assets/js/14.5b8196d5.js"><link rel="prefetch" href="/assets/js/15.79dc74f3.js"><link rel="prefetch" href="/assets/js/16.bff4d9f4.js"><link rel="prefetch" href="/assets/js/17.7b74f075.js"><link rel="prefetch" href="/assets/js/18.718f9d0a.js"><link rel="prefetch" href="/assets/js/4.ae135471.js"><link rel="prefetch" href="/assets/js/5.3e16bd23.js"><link rel="prefetch" href="/assets/js/6.52732cdc.js"><link rel="prefetch" href="/assets/js/7.b108359b.js"><link rel="prefetch" href="/assets/js/8.1da2c1df.js"><link rel="prefetch" href="/assets/js/9.76f32432.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.abc87a80.js">
<link rel="stylesheet" href="/assets/css/0.styles.a2b7d327.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">opa-stack</span></a> <div class="links"><form id="search-form" role="search" class="algolia-search-wrapper search-box"><input id="algolia-search-input" class="search-query"></form> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Guide" class="dropdown-title"><span class="title">Guide</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/guide/index.html" class="nav-link">
Intro
</a></li><li class="dropdown-item"><h4>
Development
</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/guide/development.html" class="nav-link router-link-exact-active router-link-active">
Info
</a></li><li class="dropdown-subitem"><a href="/guide/components.html" class="nav-link">
Components (optional)
</a></li><li class="dropdown-subitem"><a href="/guide/new-project.html" class="nav-link">
Creating a new project
</a></li><li class="dropdown-subitem"><a href="/guide/examples.html" class="nav-link">
Example projects
</a></li></ul></li><li class="dropdown-item"><h4>
API details
</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/guide/api/configuration.html" class="nav-link">
Configuration
</a></li><li class="dropdown-subitem"><a href="/guide/api/plugin-system.html" class="nav-link">
Plugin system
</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/more-info/" class="nav-link">
Learn more
</a></div> <a href="https://github.com/opa-stack/opa-stack" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Guide" class="dropdown-title"><span class="title">Guide</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/guide/index.html" class="nav-link">
Intro
</a></li><li class="dropdown-item"><h4>
Development
</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/guide/development.html" class="nav-link router-link-exact-active router-link-active">
Info
</a></li><li class="dropdown-subitem"><a href="/guide/components.html" class="nav-link">
Components (optional)
</a></li><li class="dropdown-subitem"><a href="/guide/new-project.html" class="nav-link">
Creating a new project
</a></li><li class="dropdown-subitem"><a href="/guide/examples.html" class="nav-link">
Example projects
</a></li></ul></li><li class="dropdown-item"><h4>
API details
</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/guide/api/configuration.html" class="nav-link">
Configuration
</a></li><li class="dropdown-subitem"><a href="/guide/api/plugin-system.html" class="nav-link">
Plugin system
</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/more-info/" class="nav-link">
Learn more
</a></div> <a href="https://github.com/opa-stack/opa-stack" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav> <ul class="sidebar-links"><li><a href="/guide/" class="sidebar-link">Intro</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/guide/#getting-started" class="sidebar-link">Getting started</a></li></ul></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Development</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/guide/development.html" class="active sidebar-link">Info</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/guide/development.html#commands" class="sidebar-link">Commands</a></li><li class="sidebar-sub-header"><a href="/guide/development.html#resources" class="sidebar-link">Resources</a></li><li class="sidebar-sub-header"><a href="/guide/development.html#builtin-libs-utils" class="sidebar-link">Builtin libs/utils</a></li><li class="sidebar-sub-header"><a href="/guide/development.html#development-mode-env-dev" class="sidebar-link">Development mode (ENV=dev)</a></li><li class="sidebar-sub-header"><a href="/guide/development.html#plugins" class="sidebar-link">Plugins</a></li><li class="sidebar-sub-header"><a href="/guide/development.html#interactive-shell" class="sidebar-link">Interactive shell</a></li></ul></li><li><a href="/guide/new-project.html" class="sidebar-link">New project</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/guide/new-project.html#orchestrators" class="sidebar-link">Orchestrators</a></li></ul></li><li><a href="/guide/plugins.html" class="sidebar-link">Plugins</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/guide/plugins.html#types-of-plugins" class="sidebar-link">Types of plugins</a></li><li class="sidebar-sub-header"><a href="/guide/plugins.html#metadata" class="sidebar-link">Metadata</a></li><li class="sidebar-sub-header"><a href="/guide/plugins.html#examples" class="sidebar-link">Examples</a></li></ul></li><li><a href="/guide/optional-components-reference.html" class="sidebar-link">Optional-components reference</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/guide/optional-components-reference.html#configuration" class="sidebar-link">Configuration</a></li><li class="sidebar-sub-header"><a href="/guide/optional-components-reference.html#usage" class="sidebar-link">Usage</a></li><li class="sidebar-sub-header"><a href="/guide/optional-components-reference.html#drivers" class="sidebar-link">Drivers</a></li></ul></li><li><a href="/guide/examples.html" class="sidebar-link">Examples</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/guide/examples.html#hello-world" class="sidebar-link">Hello world</a></li><li class="sidebar-sub-header"><a href="/guide/examples.html#timekeeper" class="sidebar-link">Timekeeper</a></li><li class="sidebar-sub-header"><a href="/guide/examples.html#redis" class="sidebar-link">Redis</a></li><li class="sidebar-sub-header"><a href="/guide/examples.html#background-tasks" class="sidebar-link">Background tasks</a></li><li class="sidebar-sub-header"><a href="/guide/examples.html#celery-task" class="sidebar-link">Celery task</a></li></ul></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>API details</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="development"><a href="#development" class="header-anchor">#</a> Development</h1> <h2 id="commands"><a href="#commands" class="header-anchor">#</a> Commands</h2> <ul><li><p>Getting a mongo-shell</p> <ul><li>docker-compose exec mongo mongo mongodb://mongo:mongo@localhost:27017/api</li></ul></li> <li><p>Stop api and run manually</p> <ul><li>s6-svc -dq /var/run/s6/services/api/</li> <li>cd /data/
<ul><li>uvicorn opa.main:app --host 0.0.0.0</li> <li>OPA_PLUGIN_PATHS=/opa-stack/examples/docker-compose/celery-task/plugins/ uvicorn opa.main:app --host 0.0.0.0 --log-level debug</li></ul></li></ul></li></ul> <h2 id="resources"><a href="#resources" class="header-anchor">#</a> Resources</h2> <ul><li>Cheatsheet - https://gitlab.com/euri10/fastapi_cheatsheet</li></ul> <h2 id="builtin-libs-utils"><a href="#builtin-libs-utils" class="header-anchor">#</a> Builtin libs/utils</h2> <h3 id="logging"><a href="#logging" class="header-anchor">#</a> Logging</h3> <ul><li><code>from opa import log</code></li></ul> <p>The log object will behave just like a <a href="https://github.com/Delgan/loguru" target="_blank" rel="noopener noreferrer">loguru<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a> object. In addition to use the <code>log.info('...')</code> and other log-function, you can also use it in after an object to get additional quick info.</p> <p>Example</p> <div class="language-py extra-class"><pre class="language-py"><code><span class="token keyword">from</span> opa <span class="token keyword">import</span> log
log<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'Hello'</span><span class="token punctuation">)</span>
a <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token string">'b'</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token operator">|</span> log <span class="token comment"># Will output the object `a` as `DEBUG`.</span>
<span class="token keyword">print</span><span class="token punctuation">(</span>a<span class="token punctuation">[</span><span class="token string">'b'</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment"># [1, 2, 3]</span>
</code></pre></div><h2 id="development-mode-env-dev"><a href="#development-mode-env-dev" class="header-anchor">#</a> Development mode (ENV=dev)</h2> <ul><li>Currently, only the <code>api</code> does something when <code>ENV</code> is set.. But this might change when more components are added later.</li></ul> <p>On dev, if you set <code>ENV</code> to <code>dev</code>, a <a href="/guide/api/configuration.html#dev">few things happens</a>, some of them are</p> <h3 id="ptvsd"><a href="#ptvsd" class="header-anchor">#</a> PTVSD</h3> <ul><li><a href="https://github.com/Microsoft/ptvsd/" target="_blank" rel="noopener noreferrer">Python Tools for Visual Studio debug server<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul> <p>The port <code>5678</code> will be exposed, and you can connect example vscode to it so it can help you debug your code.
You will be able to set breakpoints, and do the regular debugging in vscode. This also works inside async code.</p> <p>Example-configuration (<code>launch.json</code>) for vscode if you use docker-compose and expose the port like <code>"127.0.0.1:5678:5678"</code></p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
<span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"0.2.0"</span><span class="token punctuation">,</span>
<span class="token property">"configurations"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span>
<span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Python: Remote Attach"</span><span class="token punctuation">,</span>
<span class="token property">"type"</span><span class="token operator">:</span> <span class="token string">"python"</span><span class="token punctuation">,</span>
<span class="token property">"request"</span><span class="token operator">:</span> <span class="token string">"attach"</span><span class="token punctuation">,</span>
<span class="token property">"port"</span><span class="token operator">:</span> <span class="token number">5678</span><span class="token punctuation">,</span>
<span class="token property">"host"</span><span class="token operator">:</span> <span class="token string">"localhost"</span><span class="token punctuation">,</span>
<span class="token property">"pathMappings"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span>
<span class="token property">"localRoot"</span><span class="token operator">:</span> <span class="token string">"${workspaceFolder}/api/data/opa"</span><span class="token punctuation">,</span>
<span class="token property">"remoteRoot"</span><span class="token operator">:</span> <span class="token string">"/data/opa"</span>
<span class="token punctuation">}</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre></div><h3 id="better-exceptions"><a href="#better-exceptions" class="header-anchor">#</a> Better exceptions</h3> <ul><li><a href="https://github.com/Qix-/better-exceptions" target="_blank" rel="noopener noreferrer">github<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul> <p>Get better exception output on the console. It does many things, but one very usefull thing is that it shows you the content of variables inside the different exception frames.</p> <h2 id="plugins"><a href="#plugins" class="header-anchor">#</a> Plugins</h2> <p>The plugin-system is powerfull, you can read about it <a href="./api/plugin-system">here</a>.
Since there is a lot to it for developing them, there is a <a href="./plugins">dedicated</a> page for info about it.</p> <h2 id="interactive-shell"><a href="#interactive-shell" class="header-anchor">#</a> Interactive shell</h2> <p>You can get an interactive shell in the context of opa-stack by using <code>opa/scripts/shell.sh</code>. It will start an ipython shell where the plugins are available.</p> <p>Example (from a host-machine using docker-compose)</p> <div class="language-python extra-class"><pre class="language-python"><code>docker<span class="token operator">-</span>compose <span class="token keyword">exec</span> <span class="token operator">-</span>w <span class="token operator">/</span>data api <span class="token punctuation">.</span><span class="token operator">/</span>opa<span class="token operator">/</span>scripts<span class="token operator">/</span>shell<span class="token punctuation">.</span>sh
In <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token keyword">from</span> opa <span class="token keyword">import</span> get_instance
In <span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">:</span> walrus <span class="token operator">=</span> get_instance<span class="token punctuation">(</span><span class="token string">'walrus'</span><span class="token punctuation">)</span>
In <span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">:</span> walrus
Out<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">:</span> Database<span class="token operator"><</span>ConnectionPool<span class="token operator"><</span>Connection<span class="token operator"><</span>host<span class="token operator">=</span>redis<span class="token punctuation">,</span>port<span class="token operator">=</span><span class="token number">6379</span><span class="token punctuation">,</span>db<span class="token operator">=</span><span class="token number">0</span><span class="token operator">>></span><span class="token operator">></span>
In <span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">:</span> walrus<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">'test'</span><span class="token punctuation">)</span>
In <span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">:</span> walrus<span class="token punctuation">.</span><span class="token builtin">set</span><span class="token punctuation">(</span><span class="token string">'test'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
Out<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token boolean">True</span>
In <span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">:</span> walrus<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">'test'</span><span class="token punctuation">)</span>
Out<span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token string">b'1'</span>
</code></pre></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/opa-stack/opa-stack.github.io/edit/source/guide/development.md" target="_blank" rel="noopener noreferrer">Edit this page</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <div class="last-updated"><span class="prefix">Last Updated:</span> <span class="time">4/21/2020, 7:57:29 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
←
<a href="/guide/" class="prev router-link-active">
Intro
</a></span> <span class="next"><a href="/guide/new-project.html">
New project
</a>
→
</span></p></div> </main></div><div class="global-ui"><!----></div></div>
<script src="/assets/js/app.4e27d91f.js" defer></script><script src="/assets/js/3.ab9a3b8e.js" defer></script><script src="/assets/js/10.15db5ece.js" defer></script>
</body>
</html>