Skip to content

Commit 127b3c2

Browse files
committed
Re-run black format.
1 parent bc89951 commit 127b3c2

25 files changed

+427
-98
lines changed

conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ def pytest_configure():
1010
"DIRS": ["tests"],
1111
}
1212
]
13-
databases = {"default": {"ENGINE": "django.db.backends.sqlite3",}}
13+
databases = {
14+
"default": {
15+
"ENGINE": "django.db.backends.sqlite3",
16+
}
17+
}
1418

1519
installed_apps = [
1620
"example.coffee.apps.Config",

django_unicorn/call_method_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def eval_value(value):
6868
"""
6969
Uses `ast.literal_eval` to parse strings into an appropriate Python primative.
7070
71-
Also returns an appropriate object for strings that look like they represent datetime,
71+
Also returns an appropriate object for strings that look like they represent datetime,
7272
date, time, duration, or UUID.
7373
"""
7474

@@ -92,7 +92,7 @@ def eval_value(value):
9292
def parse_kwarg(kwarg: str, raise_if_unparseable=False) -> Dict[str, Any]:
9393
"""
9494
Parses a potential kwarg as a string into a dictionary.
95-
95+
9696
Example:
9797
`parse_kwarg("test='1'")` == `{"test": "1"}`
9898

django_unicorn/components/unicorn_view.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ def render(self, init_js=False) -> str:
301301
"""
302302

303303
response = self.render_to_response(
304-
context=self.get_context_data(), component=self, init_js=init_js,
304+
context=self.get_context_data(),
305+
component=self,
306+
init_js=init_js,
305307
)
306308

307309
# render_to_response() could only return a HttpResponse, so check for render()

django_unicorn/management/commands/startunicorn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def handle(self, *args, **options):
7575

7676
if should_create_app.strip().lower() in ("y", "yes"):
7777
call_command(
78-
"startapp", app_name, verbosity=0,
78+
"startapp",
79+
app_name,
80+
verbosity=0,
7981
)
8082
app_directory = base_path / app_name
8183

django_unicorn/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def generate_checksum(data: Union[str, bytes]) -> str:
3333
data_bytes = data
3434

3535
checksum = hmac.new(
36-
str.encode(settings.SECRET_KEY), data_bytes, digestmod="sha256",
36+
str.encode(settings.SECRET_KEY),
37+
data_bytes,
38+
digestmod="sha256",
3739
).hexdigest()
3840
checksum = shortuuid.uuid(checksum)[:8]
3941

django_unicorn/views/__init__.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,22 +235,31 @@ def _process_component_request(
235235
rendered_component = str(get_root_element(soup))
236236

237237
res.update(
238-
{"dom": rendered_component, "hash": hash,}
238+
{
239+
"dom": rendered_component,
240+
"hash": hash,
241+
}
239242
)
240243

241244
if return_data:
242245
res.update(
243-
{"return": return_data.get_data(),}
246+
{
247+
"return": return_data.get_data(),
248+
}
244249
)
245250

246251
if return_data.redirect:
247252
res.update(
248-
{"redirect": return_data.redirect,}
253+
{
254+
"redirect": return_data.redirect,
255+
}
249256
)
250257

251258
if return_data.poll:
252259
res.update(
253-
{"poll": return_data.poll,}
260+
{
261+
"poll": return_data.poll,
262+
}
254263
)
255264

256265
parent_component = component.parent
@@ -300,11 +309,11 @@ def _handle_component_request(
300309
- processing all of the component requests in the cache and returning the resulting value if
301310
it is the first component request for that particular component name + component id combination
302311
- return a `dict` saying that the request has been queued
303-
312+
304313
Args:
305314
param request: HttpRequest for the function-based view.
306315
param: component_request: Component request to process.
307-
316+
308317
Returns:
309318
`dict` with the following structure:
310319
{
@@ -331,7 +340,9 @@ def _handle_component_request(
331340
component_requests.append(component_request)
332341

333342
cache.set(
334-
queue_cache_key, component_requests, timeout=get_serial_timeout(),
343+
queue_cache_key,
344+
component_requests,
345+
timeout=get_serial_timeout(),
335346
)
336347

337348
if len(component_requests) > 1:
@@ -361,7 +372,7 @@ def _handle_queued_component_requests(
361372
param: component_name: Name of the component, e.g. "hello-world".
362373
param: queue_cache_key: Cache key created from component id which should be unique
363374
for any particular user's request lifecycle.
364-
375+
365376
Returns:
366377
JSON with the following structure:
367378
{
@@ -398,7 +409,9 @@ def _handle_queued_component_requests(
398409
if component_requests:
399410
component_requests.pop(0)
400411
cache.set(
401-
queue_cache_key, component_requests, timeout=get_serial_timeout(),
412+
queue_cache_key,
413+
component_requests,
414+
timeout=get_serial_timeout(),
402415
)
403416

404417
if component_requests:
@@ -426,7 +439,9 @@ def _handle_queued_component_requests(
426439

427440
component_requests.pop(0)
428441
cache.set(
429-
queue_cache_key, component_requests, timeout=get_serial_timeout(),
442+
queue_cache_key,
443+
component_requests,
444+
timeout=get_serial_timeout(),
430445
)
431446

432447
merged_json_result = _handle_component_request(
@@ -450,7 +465,7 @@ def message(request: HttpRequest, component_name: str = None) -> JsonResponse:
450465
Args:
451466
param request: HttpRequest for the function-based view.
452467
param: component_name: Name of the component, e.g. "hello-world".
453-
468+
454469
Returns:
455470
`JsonRequest` with the following structure in the body:
456471
{

django_unicorn/views/action_parsers/call_method.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def handle(component_request: ComponentRequest, component: UnicornView, payload:
4949
)
5050

5151
# Set component properties based on request data
52-
for (property_name, property_value,) in component_request.data.items():
52+
for (
53+
property_name,
54+
property_value,
55+
) in component_request.data.items():
5356
set_property_from_data(component, property_name, property_value)
5457
component.hydrate()
5558

django_unicorn/views/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def get_origin(type_hint):
2828

2929
@timed
3030
def set_property_from_data(
31-
component_or_field: Union[UnicornView, UnicornField, Model], name: str, value: Any,
31+
component_or_field: Union[UnicornView, UnicornField, Model],
32+
name: str,
33+
value: Any,
3234
) -> None:
3335
"""
3436
Sets properties on the component based on passed-in data.
@@ -43,8 +45,8 @@ def set_property_from_data(
4345
return
4446

4547
field = getattr(component_or_field, name)
46-
component_field_is_model_or_unicorn_field = _is_component_field_model_or_unicorn_field(
47-
component_or_field, name
48+
component_field_is_model_or_unicorn_field = (
49+
_is_component_field_model_or_unicorn_field(component_or_field, name)
4850
)
4951

5052
# UnicornField and Models are always a dictionary (can be nested)
@@ -90,7 +92,8 @@ def set_property_from_data(
9092

9193
@timed
9294
def _is_component_field_model_or_unicorn_field(
93-
component_or_field: Union[UnicornView, UnicornField, Model], name: str,
95+
component_or_field: Union[UnicornView, UnicornField, Model],
96+
name: str,
9497
) -> bool:
9598
"""
9699
Determines whether a component's field is a Django `Model` or `UnicornField` either

example/project/settings.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,15 @@
7979
{
8080
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
8181
},
82-
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
83-
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
84-
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
82+
{
83+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
84+
},
85+
{
86+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
87+
},
88+
{
89+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
90+
},
8591
]
8692

8793

@@ -97,24 +103,45 @@
97103
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
98104

99105

100-
UNICORN = {"SERIAL": {"ENABLED": True, "TIMEOUT": 5,}, "CACHE_ALIAS": "default"}
106+
UNICORN = {
107+
"SERIAL": {
108+
"ENABLED": True,
109+
"TIMEOUT": 5,
110+
},
111+
"CACHE_ALIAS": "default",
112+
}
101113

102114

103115
LOGGING = {
104116
"version": 1,
105117
"disable_existing_loggers": False,
106118
"handlers": {
107-
"console": {"class": "logging.StreamHandler",},
108-
"null": {"class": "logging.NullHandler",},
119+
"console": {
120+
"class": "logging.StreamHandler",
121+
},
122+
"null": {
123+
"class": "logging.NullHandler",
124+
},
125+
},
126+
"root": {
127+
"handlers": ["console"],
128+
"level": "WARNING",
109129
},
110-
"root": {"handlers": ["console"], "level": "WARNING",},
111130
"loggers": {
112131
"django": {
113132
"handlers": ["console"],
114133
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
115134
"propagate": False,
116135
},
117-
"django.server": {"handlers": ["null"], "level": "INFO", "propagate": False,},
118-
"profile": {"handlers": ["console"], "level": "INFO", "propagate": False,},
136+
"django.server": {
137+
"handlers": ["null"],
138+
"level": "INFO",
139+
"propagate": False,
140+
},
141+
"profile": {
142+
"handlers": ["console"],
143+
"level": "INFO",
144+
"propagate": False,
145+
},
119146
},
120147
}

tests/call_method_parser/test_parse_call_method_name.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,26 @@ def test_multiple_args_2():
3030

3131

3232
def test_var_with_curly_braces():
33-
expected = ("set_name", ["{}",], {})
33+
expected = (
34+
"set_name",
35+
[
36+
"{}",
37+
],
38+
{},
39+
)
3440
actual = parse_call_method_name('set_name("{}")')
3541

3642
assert actual == expected
3743

3844

3945
def test_one_arg():
40-
expected = ("set_name", ["1",], {})
46+
expected = (
47+
"set_name",
48+
[
49+
"1",
50+
],
51+
{},
52+
)
4153
actual = parse_call_method_name('set_name("1")')
4254

4355
assert actual == expected

0 commit comments

Comments
 (0)