Skip to content

Commit 1dda2d8

Browse files
author
Tom Nijboer
committed
docs: add code formatting
1 parent 6526876 commit 1dda2d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+205
-225
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
clearskies is a very opinionated Python framework intended for developing microservices in the cloud via declarative programming principles. It is mainly intended for backend services and so is designed for RESTful API endpoints, queue listeners, scheduled tasks, and the like.
44

5-
# Installation, Documentation, and Usage
5+
## Installation, Documentation, and Usage
66

77
To install:
88

9-
```
9+
```bash
1010
pip3 install clear-skies
1111
```
1212

docs/models_and_columns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Models are configured by attaching columns as properties:
22

3-
```
3+
```python
44
import clearskies.
55
def SomeModel:
66
name = columns.String(required=True)

src/clearskies/authentication/secret_bearer.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SecretBearer(Authentication, clearskies.di.InjectableProperties):
2121
environment variable which is set in the code itself. Normally you wouldn't set environment variables like this,
2222
but it's done here to create a self-contained example that is easy to run:
2323
24-
```
24+
```python
2525
import os
2626
import clearskies
2727
@@ -37,7 +37,7 @@ class SecretBearer(Authentication, clearskies.di.InjectableProperties):
3737
```
3838
We can then call it with and without the authentication header:
3939
40-
```
40+
```bash
4141
$ curl 'http://localhost:8080' -H 'Authorization: SUPERSECRET' | jq
4242
{
4343
"status": "success",
@@ -73,7 +73,7 @@ class SecretBearer(Authentication, clearskies.di.InjectableProperties):
7373
The secret bearer class can also be attached to an API Backend to provide authentication to remote APIs. To
7474
demonstrate, here is an example server that expects a secret token in the authorization header:
7575
76-
```
76+
```python
7777
import os
7878
import clearskies
7979
from clearskies import columns
@@ -111,7 +111,7 @@ class Widget(clearskies.Model):
111111
Then here is a client app (you can launch the above server and then run this in a new terminal) that
112112
similarly uses the secret bearer class to authenticate to the server:
113113
114-
```
114+
```python
115115
import os
116116
import clearskies
117117
from clearskies import columns
@@ -160,7 +160,7 @@ def api_demo(widgets: Widget) -> Widget:
160160
writeable columns, the API would return an input error. If you launch the above server/API and then run
161161
the given client script, you'll see output like this:
162162
163-
```
163+
```json
164164
{
165165
"status": "success",
166166
"error": "",
@@ -200,7 +200,7 @@ def api_demo(widgets: Widget) -> Widget:
200200
Of course, to use `secret_key`, you must also provide a secret manager. The below example uses the dependency
201201
injection system to create a faux secret manager to demonstrate how it works in general:
202202
203-
```
203+
```python
204204
from types import SimpleNamespace
205205
import clearskies
206206
@@ -225,7 +225,7 @@ def fetch_secret(path):
225225
226226
And when invoked:
227227
228-
```
228+
```bash
229229
$ curl 'http://localhost:8080/' -H "Authorization: SUPERSECRET" | jq
230230
{
231231
"status": "success",
@@ -258,7 +258,7 @@ def fetch_secret(path):
258258
be accepted and you can migrate your applications to only send the new secret. Once they are all updated,
259259
remove the alternate_secret_key:
260260
261-
```
261+
```python
262262
from types import SimpleNamespace
263263
import clearskies
264264
@@ -288,7 +288,7 @@ def fetch_secret(path):
288288
289289
And when invoked:
290290
291-
```
291+
```bash
292292
$ curl 'http://localhost:8080/' -H "Authorization: SUPERSECRET" | jq
293293
{
294294
"status": "success",
@@ -337,7 +337,7 @@ def fetch_secret(path):
337337
to use the new key and, once they are all migrated, remove the old key from the application
338338
configuration. Here's an example:
339339
340-
```
340+
```python
341341
import os
342342
import clearskies
343343
@@ -358,7 +358,7 @@ def fetch_secret(path):
358358
359359
And when invoked:
360360
361-
```
361+
```bash
362362
$ curl 'http://localhost:8080/' -H "Authorization: SUPERSECRET" | jq
363363
{
364364
"status": "success",
@@ -403,7 +403,7 @@ def fetch_secret(path):
403403
to provide such a prefix. Note that the prefix is case-insensitive and it does not assume a space between the
404404
prefix and the token (so, if you want a space, you must explicitly put it in the prefix). Here's an example:
405405
406-
```
406+
```python
407407
import os
408408
import clearskies
409409
@@ -423,7 +423,7 @@ def fetch_secret(path):
423423
424424
And then usage:
425425
426-
```
426+
```bash
427427
$ curl 'http://localhost:8080/' -H "Authorization: SECRET-TOKEN SUPERSECRET" | jq
428428
{
429429
"status": "success",

src/clearskies/backends/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
See the documentation for each backend to understand how to configure and use it. In all cases though, you specify
3434
the backend by instantiating the backend and attaching it to the model class via the `backend` attribute:
3535
36-
```
36+
```python
3737
import clearskies
3838
3939

src/clearskies/backends/api_backend.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ApiBackend(clearskies.configurable.Configurable, Backend, InjectableProper
7373
7474
Here's an example of how to use the API Backend to integrate with the Github API:
7575
76-
```
76+
```python
7777
import clearskies
7878
7979
@@ -191,7 +191,7 @@ def fetch_user(users: User, user_repos: UserRepo):
191191
other model. Note that the following example is re-using the above models and backend, I have just omitted them for the sake
192192
of brevity:
193193
194-
```
194+
```python
195195
wsgi = clearskies.contexts.WsgiRef(
196196
clearskies.endpoints.List(
197197
model_class=User,
@@ -209,7 +209,7 @@ def fetch_user(users: User, user_repos: UserRepo):
209209
210210
And if you invoke it:
211211
212-
```
212+
```bash
213213
$ curl 'http://localhost:8080' | jq
214214
{
215215
"status": "success",
@@ -281,8 +281,8 @@ def fetch_user(users: User, user_repos: UserRepo):
281281
makes API calls. It also tracks pagination as expected, so you can use the data in `pagination.next_page` to
282282
fetch the next set of results, just as you would if this were backed by a database, e.g.:
283283
284-
```
285-
curl http://localhost:8080?since=19
284+
```bash
285+
$ curl http://localhost:8080?since=19
286286
```
287287
288288
## Mapping from Queries to API calls
@@ -343,7 +343,7 @@ def fetch_user(users: User, user_repos: UserRepo):
343343
request will succeed and the service will continue to operate successfully with only a slight delay in response time
344344
caused by refreshing the cache.
345345
346-
```
346+
```python
347347
import clearskies
348348
349349
class GithubBackend(clearskies.backends.ApiBackend):
@@ -409,7 +409,7 @@ def destination_name(cls):
409409
example, these parameters are used to convert from the snake_casing native to the Github API into the
410410
TitleCasing used in the model class:
411411
412-
```
412+
```python
413413
import clearskies
414414
415415
class User(clearskies.Model):
@@ -448,8 +448,8 @@ class User(clearskies.Model):
448448
449449
and when executed:
450450
451-
```
452-
$ curl http://localhost:8080 | jq
451+
```bash
452+
$ curl http://localhost:8080 | jq
453453
{
454454
"Status": "Success",
455455
"Error": "",
@@ -495,7 +495,7 @@ class User(clearskies.Model):
495495
is the name of the column in the model. The API Backend will use this to match the API data to your model.
496496
In the example below, `html_url` from the API has been mapped to `profile_url` in the model:
497497
498-
```
498+
```python
499499
import clearskies
500500
501501
class User(clearskies.Model):
@@ -528,8 +528,8 @@ class User(clearskies.Model):
528528
529529
And if you invoke it:
530530
531-
```
532-
$ curl http://localhost:8080 | jq
531+
```bash
532+
$ curl http://localhost:8080 | jq
533533
{
534534
"status": "success",
535535
"error": "",
@@ -606,7 +606,7 @@ def finalize_url(self, url: str, available_routing_data: dict[str, str], operati
606606
607607
For example, consider a base URL of `/my/api/{record_id}/:other_id` and then this is called as so:
608608
609-
```
609+
```python
610610
(url, used_routing_parameters) = api_backend.finalize_url(
611611
"entries",
612612
{
@@ -1001,8 +1001,11 @@ def build_response_to_model_map(self, columns: dict[str, clearskies.column.Colum
10011001
return self._response_to_model_map
10021002

10031003
def set_next_page_data_from_response(
1004-
self, next_page_data: dict[str, Any], query: clearskies.query.Query, response: requests.models.Response
1005-
) -> None: # type: ignore
1004+
self,
1005+
next_page_data: dict[str, Any],
1006+
query: clearskies.query.Query,
1007+
response: requests.Response, # type: ignore
1008+
) -> None:
10061009
"""
10071010
Update the next_page_data dictionary with the appropriate data needed to fetch the next page of records.
10081011
@@ -1011,13 +1014,13 @@ def set_next_page_data_from_response(
10111014
information is necessary. Note that this relies on next_page_data being passed by reference, hence the need to update
10121015
it in place. That means that you can do this:
10131016
1014-
```
1017+
```python
10151018
next_page_data["some_key"] = "some_value"
10161019
```
10171020
10181021
but if you do this:
10191022
1020-
```
1023+
```python
10211024
next_page_data = {"some_key": "some_value"}
10221025
```
10231026

src/clearskies/backends/cursor_backend.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CursorBackend(Backend, InjectableProperties):
1717
clearskies uses PyMySQL to manage the database connection and make queries. This is not installed by default,
1818
but is a named extra that you can install when needed via:
1919
20-
```
20+
```bash
2121
pip install clear-skies[mysql]
2222
```
2323
@@ -37,7 +37,7 @@ class CursorBackend(Backend, InjectableProperties):
3737
However, you can fully control the credential provisioning process by declaring a dependency named `connection_details` and
3838
setting it to a dictionary with the above keys, minus the `db_` prefix:
3939
40-
```
40+
```python
4141
class ConnectionDetails(clearskies.di.AdditionalConfig):
4242
provide_connection_details(self, secrets):
4343
return {
@@ -68,7 +68,7 @@ class ConnectionDetails(clearskies.di.AdditionalConfig):
6868
class named `UserPreference` then the cursor backend will look for a table called `user_preferences`. If this
6969
isn't what you want, then you can simply override `destination_name` to return whatever table you want:
7070
71-
```
71+
```python
7272
class UserPreference(clearskies.Model):
7373
@classmethod
7474
def destination_name(cls):
@@ -84,7 +84,7 @@ def destination_name(cls):
8484
2. The `table_prefix` argument to the CursorBackend constructor adds a prefix of `configuration_`
8585
3. The `global_table_prefix` binding sets a prefix of `user_`, wihch goes before everything else.
8686
87-
```
87+
```python
8888
import clearskies
8989
9090

src/clearskies/backends/memory_backend.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class MemoryBackend(Backend, InjectableProperties):
260260
but when you run this code it will actually end up with the memory backend, so the code will run even without
261261
attempting to connect to a database.
262262
263-
```
263+
```python
264264
import clearskies
265265
266266
@@ -314,7 +314,7 @@ class UserPreference(clearskies.Model):
314314
can be helpful in testing to setup your tests, and is occassionally helpful for keeping track of data in
315315
fixed, read-only tables. Here's an example:
316316
317-
```
317+
```python
318318
import clearskies
319319
320320
@@ -378,7 +378,7 @@ class Pet(clearskies.Model):
378378
379379
And if you invoke it:
380380
381-
```
381+
```bash
382382
$ curl 'http://localhost:8080' | jq
383383
{
384384
"status": "success",
@@ -420,7 +420,6 @@ class Pet(clearskies.Model):
420420
"input_errors": {}
421421
}
422422
```
423-
424423
"""
425424

426425
default_data = inject.ByName("memory_backend_default_data")
@@ -672,7 +671,7 @@ def join_rows(
672671
673672
`rows` should be something like:
674673
675-
```
674+
```python
676675
[
677676
{
678677
"table_1": {"table_1_row_1"},

0 commit comments

Comments
 (0)