bazaar-contrib-server 0.3.0rc1__tar.gz
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.
- bazaar_contrib_server-0.3.0rc1/LICENSE +202 -0
- bazaar_contrib_server-0.3.0rc1/PKG-INFO +88 -0
- bazaar_contrib_server-0.3.0rc1/README.md +64 -0
- bazaar_contrib_server-0.3.0rc1/pyproject.toml +74 -0
- bazaar_contrib_server-0.3.0rc1/pyproject.toml.orig +70 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/__init__.py +112 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/clock.py +40 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/contracts.py +196 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/i18n.py +84 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/markdown.py +83 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/pages.py +226 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/py.typed +0 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/refs.py +94 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/locales/en.toml +23 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/locales/zh-CN.toml +23 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/THIRD_PARTY.md +58 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/alpine-3.17.4.min.js +21 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/alpine-LICENSE.txt +21 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/alpine-collapse-3.17.4.min.js +1 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/alpine-collapse-LICENSE.txt +21 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/alpine-focus-3.17.4.min.js +18 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/alpine-focus-LICENSE.txt +21 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/base.css +175 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/embed.js +86 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/favicon.svg +9 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/fonts/fraunces-LICENSE.txt +93 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/fonts/fraunces-latin-full-italic.woff2 +0 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/fonts/fraunces-latin-full-normal.woff2 +0 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/fonts/inter-LICENSE.txt +93 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/fonts/inter-latin-wght-normal.woff2 +0 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/fonts/jetbrains-mono-LICENSE.txt +93 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/htmx-LICENSE.txt +13 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/htmx.min.js +1 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/hx-alpine-compat-4.0.0.js +110 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/static/shell.css +45 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/base.html +27 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/code.html +1 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/error.html +8 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/icons/chevron-left.svg +15 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/icons/chevron-right.svg +1 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/icons/layout-dashboard.svg +1 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/icons/log-out.svg +1 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/icons/settings.svg +1 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/icons.html +3 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/image.html +1 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/mark.svg +9 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/overview.html +5 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/overview_board.html +17 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/settings.html +16 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/shell.html +36 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/templates/server/theme.css +9 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/themes/day.toml +41 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/resources/themes/night.toml +37 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/schema.py +41 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/shell.py +505 -0
- bazaar_contrib_server-0.3.0rc1/src/bazaar_contrib_server/themes.py +48 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bazaar-contrib-server
|
|
3
|
+
Version: 0.3.0rc1
|
|
4
|
+
Summary: The Bazaar Compute server: the shell modules put their pages in, and its themes
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: bazaar-core~=0.3.0rc1
|
|
8
|
+
Requires-Dist: bazaar-contrib-http~=0.3.0rc1
|
|
9
|
+
Requires-Dist: bazaar-contrib-schema~=0.3.0rc1
|
|
10
|
+
Requires-Dist: bazaar-contrib-storage~=0.3.0rc1
|
|
11
|
+
Requires-Dist: bazaar-contrib-server-database~=0.3.0rc1
|
|
12
|
+
Requires-Dist: bazaar-contrib-server-migrations~=0.3.0rc2
|
|
13
|
+
Requires-Dist: jinja2>=3.1.6
|
|
14
|
+
Requires-Dist: markdown-it-py>=4.2.0
|
|
15
|
+
Requires-Dist: markupsafe>=3.0.0
|
|
16
|
+
Requires-Dist: pydantic>=2.12.0
|
|
17
|
+
Requires-Dist: pygments>=2.20.0
|
|
18
|
+
Requires-Dist: python-multipart>=0.0.32
|
|
19
|
+
Requires-Dist: starlette>=0.48.0
|
|
20
|
+
Requires-Dist: tzdata>=2024.1 ; sys_platform == 'win32'
|
|
21
|
+
Requires-Python: >=3.15
|
|
22
|
+
Project-URL: Repository, https://github.com/open-bazaar/contrib-server
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# bazaar-contrib-server
|
|
26
|
+
|
|
27
|
+
The Bazaar Compute server itself. The `server` entry draws the shell around every module — the sidebar, the overview and the settings page — and offers `SERVER`, where modules register their pages, API and permission points, and `THEME`, where theme contribs register the looks the pages can wear. The `server-theme-night` and `server-theme-day` entries are the theme plugins it comes with: the night market and the morning market.
|
|
28
|
+
|
|
29
|
+
```toml
|
|
30
|
+
[[contribs]]
|
|
31
|
+
package = "bazaar-contrib-server~=0.3.0rc1"
|
|
32
|
+
[[contribs.enabled]]
|
|
33
|
+
entry = "server"
|
|
34
|
+
[[contribs.enabled]]
|
|
35
|
+
entry = "server-theme-night"
|
|
36
|
+
[[contribs.enabled]]
|
|
37
|
+
entry = "server-theme-day"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
A module registers what it serves inside its lifespan; each registration holds while its context is open:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import asyncio
|
|
44
|
+
from contextlib import asynccontextmanager
|
|
45
|
+
|
|
46
|
+
from bazaar_contrib_server import SERVER, PermissionItem, SidebarItem
|
|
47
|
+
from bazaar_core import Context, Contrib
|
|
48
|
+
from importlib.resources import files
|
|
49
|
+
from pathlib import Path
|
|
50
|
+
from starlette.routing import Route
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@asynccontextmanager
|
|
54
|
+
async def lifespan(ctx: Context):
|
|
55
|
+
server = ctx.accept(SERVER)
|
|
56
|
+
pages = await server.pages("notes", __package__)
|
|
57
|
+
|
|
58
|
+
async def home(request):
|
|
59
|
+
return await pages.render(request, "notes.html")
|
|
60
|
+
|
|
61
|
+
resources = Path(str(files(__package__))) / "resources"
|
|
62
|
+
icon = await asyncio.to_thread((resources / "notes.svg").read_text)
|
|
63
|
+
async with (
|
|
64
|
+
server.module(
|
|
65
|
+
"notes",
|
|
66
|
+
ui=pages.application([Route("/", home)]),
|
|
67
|
+
static=resources / "static",
|
|
68
|
+
locales=resources / "locales",
|
|
69
|
+
),
|
|
70
|
+
server.permission(
|
|
71
|
+
PermissionItem(point="notes.view", description="notes.view.description")
|
|
72
|
+
),
|
|
73
|
+
server.sidebar(
|
|
74
|
+
SidebarItem(
|
|
75
|
+
text="notes.title",
|
|
76
|
+
icon=icon,
|
|
77
|
+
path="/notes",
|
|
78
|
+
permission="notes.view",
|
|
79
|
+
)
|
|
80
|
+
),
|
|
81
|
+
):
|
|
82
|
+
yield
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
notes = Contrib(accepts=[SERVER], lifespan=lifespan)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The icon is an SVG drawn as the design's are, with class `i` and a 24×24 view box. The module's interface is served at `/ui/notes` inside the shell at `/notes`, its API at `/api/notes` and its files at `/static/notes`. Its templates live in `resources/templates` of its package and extend `server/base.html`, which brings the theme stylesheet and the embedding script; pages of any other framework include `/static/server/theme.css` and `/static/server/embed.js` themselves. Everything behind the shell needs a login module, which registers itself with `server.login`; until one does, those pages and APIs answer 503.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# bazaar-contrib-server
|
|
2
|
+
|
|
3
|
+
The Bazaar Compute server itself. The `server` entry draws the shell around every module — the sidebar, the overview and the settings page — and offers `SERVER`, where modules register their pages, API and permission points, and `THEME`, where theme contribs register the looks the pages can wear. The `server-theme-night` and `server-theme-day` entries are the theme plugins it comes with: the night market and the morning market.
|
|
4
|
+
|
|
5
|
+
```toml
|
|
6
|
+
[[contribs]]
|
|
7
|
+
package = "bazaar-contrib-server~=0.3.0rc1"
|
|
8
|
+
[[contribs.enabled]]
|
|
9
|
+
entry = "server"
|
|
10
|
+
[[contribs.enabled]]
|
|
11
|
+
entry = "server-theme-night"
|
|
12
|
+
[[contribs.enabled]]
|
|
13
|
+
entry = "server-theme-day"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
A module registers what it serves inside its lifespan; each registration holds while its context is open:
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
import asyncio
|
|
20
|
+
from contextlib import asynccontextmanager
|
|
21
|
+
|
|
22
|
+
from bazaar_contrib_server import SERVER, PermissionItem, SidebarItem
|
|
23
|
+
from bazaar_core import Context, Contrib
|
|
24
|
+
from importlib.resources import files
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from starlette.routing import Route
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@asynccontextmanager
|
|
30
|
+
async def lifespan(ctx: Context):
|
|
31
|
+
server = ctx.accept(SERVER)
|
|
32
|
+
pages = await server.pages("notes", __package__)
|
|
33
|
+
|
|
34
|
+
async def home(request):
|
|
35
|
+
return await pages.render(request, "notes.html")
|
|
36
|
+
|
|
37
|
+
resources = Path(str(files(__package__))) / "resources"
|
|
38
|
+
icon = await asyncio.to_thread((resources / "notes.svg").read_text)
|
|
39
|
+
async with (
|
|
40
|
+
server.module(
|
|
41
|
+
"notes",
|
|
42
|
+
ui=pages.application([Route("/", home)]),
|
|
43
|
+
static=resources / "static",
|
|
44
|
+
locales=resources / "locales",
|
|
45
|
+
),
|
|
46
|
+
server.permission(
|
|
47
|
+
PermissionItem(point="notes.view", description="notes.view.description")
|
|
48
|
+
),
|
|
49
|
+
server.sidebar(
|
|
50
|
+
SidebarItem(
|
|
51
|
+
text="notes.title",
|
|
52
|
+
icon=icon,
|
|
53
|
+
path="/notes",
|
|
54
|
+
permission="notes.view",
|
|
55
|
+
)
|
|
56
|
+
),
|
|
57
|
+
):
|
|
58
|
+
yield
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
notes = Contrib(accepts=[SERVER], lifespan=lifespan)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The icon is an SVG drawn as the design's are, with class `i` and a 24×24 view box. The module's interface is served at `/ui/notes` inside the shell at `/notes`, its API at `/api/notes` and its files at `/static/notes`. Its templates live in `resources/templates` of its package and extend `server/base.html`, which brings the theme stylesheet and the embedding script; pages of any other framework include `/static/server/theme.css` and `/static/server/embed.js` themselves. Everything behind the shell needs a login module, which registers itself with `server.login`; until one does, those pages and APIs answer 503.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "bazaar-contrib-server"
|
|
3
|
+
version = "0.3.0rc1"
|
|
4
|
+
description = "The Bazaar Compute server: the shell modules put their pages in, and its themes"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.15"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"bazaar-core~=0.3.0rc1",
|
|
11
|
+
"bazaar-contrib-http~=0.3.0rc1",
|
|
12
|
+
"bazaar-contrib-schema~=0.3.0rc1",
|
|
13
|
+
"bazaar-contrib-storage~=0.3.0rc1",
|
|
14
|
+
"bazaar-contrib-server-database~=0.3.0rc1",
|
|
15
|
+
"bazaar-contrib-server-migrations~=0.3.0rc2",
|
|
16
|
+
"jinja2>=3.1.6",
|
|
17
|
+
"markdown-it-py>=4.2.0",
|
|
18
|
+
"markupsafe>=3.0.0",
|
|
19
|
+
"pydantic>=2.12.0",
|
|
20
|
+
"pygments>=2.20.0",
|
|
21
|
+
"python-multipart>=0.0.32",
|
|
22
|
+
"starlette>=0.48.0",
|
|
23
|
+
"tzdata>=2024.1; sys_platform == 'win32'",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.entry-points."bazaar_compute_node.contribs"]
|
|
27
|
+
server = "bazaar_contrib_server:server"
|
|
28
|
+
server-theme-night = "bazaar_contrib_server:night"
|
|
29
|
+
server-theme-day = "bazaar_contrib_server:day"
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Repository = "https://github.com/open-bazaar/contrib-server"
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["uv_build>=0.13.0,<0.14.0"]
|
|
36
|
+
build-backend = "uv_build"
|
|
37
|
+
|
|
38
|
+
[tool.pytest.ini_options]
|
|
39
|
+
testpaths = ["tests"]
|
|
40
|
+
addopts = "-p no:anyio"
|
|
41
|
+
asyncio_mode = "auto"
|
|
42
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
43
|
+
|
|
44
|
+
[tool.pyright]
|
|
45
|
+
include = [
|
|
46
|
+
"src",
|
|
47
|
+
"tests",
|
|
48
|
+
"scripts",
|
|
49
|
+
]
|
|
50
|
+
pythonVersion = "3.15"
|
|
51
|
+
pythonPlatform = "All"
|
|
52
|
+
venvPath = "."
|
|
53
|
+
venv = ".venv"
|
|
54
|
+
typeCheckingMode = "basic"
|
|
55
|
+
reportMatchNotExhaustive = "error"
|
|
56
|
+
reportUnreachable = "warning"
|
|
57
|
+
reportUnusedFunction = "warning"
|
|
58
|
+
reportUnusedVariable = "warning"
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint]
|
|
61
|
+
extend-select = ["ASYNC"]
|
|
62
|
+
|
|
63
|
+
[dependency-groups]
|
|
64
|
+
dev = [
|
|
65
|
+
"bazaar-contrib-sqlite~=0.3.0rc1",
|
|
66
|
+
"bazaar-contrib-timer-wheel~=0.3.0rc1",
|
|
67
|
+
"blockbuster>=1.5.29,<1.6",
|
|
68
|
+
"httpx>=0.28.0,<1",
|
|
69
|
+
"pyright==1.1.414",
|
|
70
|
+
"pytest>=8.3.0",
|
|
71
|
+
"pytest-asyncio>=0.24.0",
|
|
72
|
+
"ruff>=0.9.0",
|
|
73
|
+
"websockets>=15.0",
|
|
74
|
+
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "bazaar-contrib-server"
|
|
3
|
+
version = "0.3.0rc1"
|
|
4
|
+
description = "The Bazaar Compute server: the shell modules put their pages in, and its themes"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.15"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"bazaar-core~=0.3.0rc1",
|
|
11
|
+
"bazaar-contrib-http~=0.3.0rc1",
|
|
12
|
+
"bazaar-contrib-schema~=0.3.0rc1",
|
|
13
|
+
"bazaar-contrib-storage~=0.3.0rc1",
|
|
14
|
+
"bazaar-contrib-server-database~=0.3.0rc1",
|
|
15
|
+
"bazaar-contrib-server-migrations~=0.3.0rc2",
|
|
16
|
+
"jinja2>=3.1.6",
|
|
17
|
+
"markdown-it-py>=4.2.0",
|
|
18
|
+
"markupsafe>=3.0.0",
|
|
19
|
+
"pydantic>=2.12.0",
|
|
20
|
+
"pygments>=2.20.0",
|
|
21
|
+
"python-multipart>=0.0.32",
|
|
22
|
+
"starlette>=0.48.0",
|
|
23
|
+
"tzdata>=2024.1; sys_platform == 'win32'",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.entry-points."bazaar_compute_node.contribs"]
|
|
27
|
+
server = "bazaar_contrib_server:server"
|
|
28
|
+
server-theme-night = "bazaar_contrib_server:night"
|
|
29
|
+
server-theme-day = "bazaar_contrib_server:day"
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Repository = "https://github.com/open-bazaar/contrib-server"
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["uv_build>=0.13.0,<0.14.0"]
|
|
36
|
+
build-backend = "uv_build"
|
|
37
|
+
|
|
38
|
+
[tool.pytest.ini_options]
|
|
39
|
+
testpaths = ["tests"]
|
|
40
|
+
addopts = "-p no:anyio"
|
|
41
|
+
asyncio_mode = "auto"
|
|
42
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
43
|
+
|
|
44
|
+
[tool.pyright]
|
|
45
|
+
include = ["src", "tests", "scripts"]
|
|
46
|
+
pythonVersion = "3.15"
|
|
47
|
+
pythonPlatform = "All"
|
|
48
|
+
venvPath = "."
|
|
49
|
+
venv = ".venv"
|
|
50
|
+
typeCheckingMode = "basic"
|
|
51
|
+
reportMatchNotExhaustive = "error"
|
|
52
|
+
reportUnreachable = "warning"
|
|
53
|
+
reportUnusedFunction = "warning"
|
|
54
|
+
reportUnusedVariable = "warning"
|
|
55
|
+
|
|
56
|
+
[tool.ruff.lint]
|
|
57
|
+
extend-select = ["ASYNC"]
|
|
58
|
+
|
|
59
|
+
[dependency-groups]
|
|
60
|
+
dev = [
|
|
61
|
+
"bazaar-contrib-sqlite~=0.3.0rc1",
|
|
62
|
+
"bazaar-contrib-timer-wheel~=0.3.0rc1",
|
|
63
|
+
"blockbuster>=1.5.29,<1.6",
|
|
64
|
+
"httpx>=0.28.0,<1",
|
|
65
|
+
"pyright==1.1.414",
|
|
66
|
+
"pytest>=8.3.0",
|
|
67
|
+
"pytest-asyncio>=0.24.0",
|
|
68
|
+
"ruff>=0.9.0",
|
|
69
|
+
"websockets>=15.0",
|
|
70
|
+
]
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""The server itself: the shell modules put their pages in, its registrations,
|
|
2
|
+
the themes, and the two themes it comes with."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from contextlib import asynccontextmanager
|
|
7
|
+
lazy import asyncio
|
|
8
|
+
lazy import tomllib
|
|
9
|
+
lazy from collections.abc import AsyncIterator
|
|
10
|
+
lazy from importlib.resources import files
|
|
11
|
+
|
|
12
|
+
from bazaar_contrib_http import HTTP
|
|
13
|
+
from bazaar_contrib_server_database import SERVER_DB, SERVER_SCHEMA
|
|
14
|
+
from bazaar_contrib_server_migrations import SERVER_MIGRATIONS
|
|
15
|
+
from bazaar_core import Context, Contrib
|
|
16
|
+
lazy from starlette.exceptions import HTTPException
|
|
17
|
+
lazy from starlette.requests import HTTPConnection
|
|
18
|
+
|
|
19
|
+
from .contracts import (
|
|
20
|
+
SERVER,
|
|
21
|
+
THEME,
|
|
22
|
+
Account,
|
|
23
|
+
Login,
|
|
24
|
+
OverviewItem,
|
|
25
|
+
PermissionItem,
|
|
26
|
+
Server,
|
|
27
|
+
SettingsItem,
|
|
28
|
+
SidebarItem,
|
|
29
|
+
Theme,
|
|
30
|
+
Themes,
|
|
31
|
+
Tokens,
|
|
32
|
+
)
|
|
33
|
+
lazy from .i18n import LANGUAGES, Translator
|
|
34
|
+
lazy from .pages import Pages
|
|
35
|
+
lazy from .refs import Refs
|
|
36
|
+
lazy from .schema import MODULE
|
|
37
|
+
lazy from .shell import Shell
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
"LANGUAGES",
|
|
41
|
+
"SERVER",
|
|
42
|
+
"THEME",
|
|
43
|
+
"Account",
|
|
44
|
+
"Login",
|
|
45
|
+
"OverviewItem",
|
|
46
|
+
"Pages",
|
|
47
|
+
"PermissionItem",
|
|
48
|
+
"Refs",
|
|
49
|
+
"Server",
|
|
50
|
+
"SettingsItem",
|
|
51
|
+
"SidebarItem",
|
|
52
|
+
"Theme",
|
|
53
|
+
"Themes",
|
|
54
|
+
"Tokens",
|
|
55
|
+
"Translator",
|
|
56
|
+
"account",
|
|
57
|
+
"day",
|
|
58
|
+
"night",
|
|
59
|
+
"permitted",
|
|
60
|
+
"server",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def account(connection: HTTPConnection) -> Account:
|
|
65
|
+
"""The account a request or a WebSocket behind the login is from; a
|
|
66
|
+
FastAPI dependency."""
|
|
67
|
+
return connection.state.account
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def permitted(point: str):
|
|
71
|
+
"""A FastAPI dependency refusing accounts without the permission point."""
|
|
72
|
+
|
|
73
|
+
def check(connection: HTTPConnection) -> None:
|
|
74
|
+
if not account(connection).allows(point):
|
|
75
|
+
raise HTTPException(status_code=403)
|
|
76
|
+
|
|
77
|
+
return check
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@asynccontextmanager
|
|
81
|
+
async def _server(ctx: Context) -> AsyncIterator[None]:
|
|
82
|
+
async with ctx.accept(SERVER_SCHEMA).register(MODULE):
|
|
83
|
+
shell = await Shell.open(ctx.accept(HTTP), ctx.accept(SERVER_DB))
|
|
84
|
+
async with shell.serving():
|
|
85
|
+
ctx.offer(SERVER, shell)
|
|
86
|
+
ctx.offer(THEME, shell.themes)
|
|
87
|
+
yield
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _theme(name: str) -> Contrib:
|
|
91
|
+
"""A theme plugin for the theme in resources/themes/<name>.toml."""
|
|
92
|
+
|
|
93
|
+
@asynccontextmanager
|
|
94
|
+
async def lifespan(ctx: Context) -> AsyncIterator[None]:
|
|
95
|
+
path = files(__name__) / "resources" / "themes" / f"{name}.toml"
|
|
96
|
+
theme = Theme.model_validate(
|
|
97
|
+
tomllib.loads(await asyncio.to_thread(path.read_text, encoding="utf-8"))
|
|
98
|
+
)
|
|
99
|
+
async with ctx.accept(THEME).register(theme):
|
|
100
|
+
yield
|
|
101
|
+
|
|
102
|
+
return Contrib(accepts=[THEME], lifespan=lifespan)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
server = Contrib(
|
|
106
|
+
accepts=[HTTP, SERVER_DB, SERVER_SCHEMA, SERVER_MIGRATIONS],
|
|
107
|
+
offers=[SERVER, THEME],
|
|
108
|
+
lifespan=_server,
|
|
109
|
+
)
|
|
110
|
+
# the night market and the morning market of the approved design
|
|
111
|
+
night = _theme("night")
|
|
112
|
+
day = _theme("day")
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""The server's clock, and moments as the viewer reads them."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
lazy from datetime import datetime, tzinfo
|
|
6
|
+
lazy from time import time_ns
|
|
7
|
+
lazy from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def now_ms() -> int:
|
|
11
|
+
return time_ns() // 1_000_000
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def zone(name: str | None) -> tzinfo | None:
|
|
15
|
+
"""The viewer's zone by IANA name; nothing when there is none, so each
|
|
16
|
+
moment is read on the server's own clock, daylight time as it was then."""
|
|
17
|
+
if name:
|
|
18
|
+
try:
|
|
19
|
+
return ZoneInfo(name)
|
|
20
|
+
except ZoneInfoNotFoundError, ValueError:
|
|
21
|
+
pass
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def clock_text(at_ms: int, tz: tzinfo | None) -> str:
|
|
26
|
+
"""A moment on the viewer's clock: the time of day, with the date before
|
|
27
|
+
it when the day is not today's."""
|
|
28
|
+
today = datetime.now(tz).replace(hour=0, minute=0, second=0, microsecond=0)
|
|
29
|
+
form = "%H:%M:%S" if at_ms >= today.timestamp() * 1000 else "%Y-%m-%d %H:%M:%S"
|
|
30
|
+
return datetime.fromtimestamp(at_ms / 1000, tz).strftime(form)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def day_text(at_ms: int, tz: tzinfo | None) -> str:
|
|
34
|
+
"""The day a moment falls on, on the viewer's calendar."""
|
|
35
|
+
return datetime.fromtimestamp(at_ms / 1000, tz).strftime("%Y-%m-%d")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def time_text(at_ms: int, tz: tzinfo | None) -> str:
|
|
39
|
+
"""The time of day of a moment, whatever the day."""
|
|
40
|
+
return datetime.fromtimestamp(at_ms / 1000, tz).strftime("%H:%M:%S")
|