Skip to content

Commit 3e49165

Browse files
committed
lint _jl_components_generation
1 parent c7e7c03 commit 3e49165

File tree

1 file changed

+71
-63
lines changed

1 file changed

+71
-63
lines changed

dash/development/_jl_components_generation.py

Lines changed: 71 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
{children_definitions}
3939
''' # noqa:E501
4040

41-
jl_children_signatures = '''
41+
jl_children_signatures = """
4242
{funcname}(children::Any;kwargs...)
4343
{funcname}(children_maker::Function;kwargs...)
44-
'''
44+
"""
4545

46-
jl_children_definitions = '''
46+
jl_children_definitions = """
4747
{funcname}(children::Any; kwargs...) = {funcname}(;kwargs..., children = children)
4848
{funcname}(children_maker::Function; kwargs...) = {funcname}(children_maker(); kwargs...)
49-
'''
49+
"""
5050

51-
jl_package_file_string = '''
51+
jl_package_file_string = """
5252
module {package_name}
5353
using {base_package}
5454
@@ -67,13 +67,13 @@
6767
{resources_dist}
6868
]
6969
)
70-
70+
7171
)
7272
end
7373
end
74-
'''
74+
"""
7575

76-
jl_projecttoml_string = '''
76+
jl_projecttoml_string = """
7777
name = "{package_name}"
7878
uuid = "{package_uuid}"
7979
{authors}version = "{version}"
@@ -84,19 +84,20 @@
8484
[compact]
8585
julia = "1.2"
8686
{base_package} = ">=0.1"
87-
'''
87+
"""
8888

8989
jl_component_include_string = 'include("{name}.jl")'
9090

91-
jl_resource_tuple_string = '''DashBase.Resource(
91+
jl_resource_tuple_string = """DashBase.Resource(
9292
relative_package_path = {relative_package_path},
9393
external_url = {external_url},
9494
dynamic = {dynamic},
9595
async = {async_string},
9696
type = :{type}
97-
)'''
97+
)"""
98+
99+
core_packages = ["dash_html_components", "dash_core_components", "dash_table"]
98100

99-
core_packages = ['dash_html_components', 'dash_core_components', 'dash_table']
100101

101102
def jl_package_name(namestring):
102103
s = namestring.split("_")
@@ -105,13 +106,9 @@ def jl_package_name(namestring):
105106

106107
def stringify_wildcards(wclist, no_symbol=False):
107108
if no_symbol:
108-
wcstring = "|".join(
109-
'{}-'.format(item) for item in wclist
110-
)
109+
wcstring = "|".join("{}-".format(item) for item in wclist)
111110
else:
112-
wcstring = ", ".join(
113-
'Symbol("{}-")'.format(item) for item in wclist
114-
)
111+
wcstring = ", ".join('Symbol("{}-")'.format(item) for item in wclist)
115112
return wcstring
116113

117114

@@ -289,11 +286,7 @@ def create_docstring_jl(component_name, props, description):
289286

290287

291288
def create_prop_docstring_jl(
292-
prop_name,
293-
type_object,
294-
required,
295-
description,
296-
indent_num,
289+
prop_name, type_object, required, description, indent_num,
297290
):
298291
"""
299292
Create the Dash component prop docstring
@@ -353,24 +346,34 @@ def format_fn_name(prefix, name):
353346
def generate_metadata_strings(resources, metatype):
354347
def nothing_or_string(v):
355348
return '"{}"'.format(v) if v else "nothing"
356-
return [jl_resource_tuple_string.format(
357-
relative_package_path=nothing_or_string(resource.get("relative_package_path", "")),
358-
external_url=nothing_or_string(resource.get("external_url", "")),
359-
dynamic=str(resource.get("dynamic", 'nothing')).lower(),
360-
type=metatype,
361-
async_string=":{}".format(str(resource.get("async")).lower())
362-
if "async" in resource.keys()
363-
else 'nothing'
364-
) for resource in resources]
349+
350+
return [
351+
jl_resource_tuple_string.format(
352+
relative_package_path=nothing_or_string(
353+
resource.get("relative_package_path", "")
354+
),
355+
external_url=nothing_or_string(resource.get("external_url", "")),
356+
dynamic=str(resource.get("dynamic", "nothing")).lower(),
357+
type=metatype,
358+
async_string=":{}".format(str(resource.get("async")).lower())
359+
if "async" in resource.keys()
360+
else "nothing",
361+
)
362+
for resource in resources
363+
]
364+
365365

366366
def is_core_package(project_shortname):
367367
return project_shortname in core_packages
368368

369+
369370
def base_package_name(project_shortname):
370371
return "DashBase" if is_core_package(project_shortname) else "Dash"
371372

373+
372374
def base_package_uid(project_shortname):
373-
return jl_dash_base_uuid if is_core_package(project_shortname) else jl_base_uuid
375+
return jl_dash_base_uuid if is_core_package(project_shortname) else jl_dash_uuid
376+
374377

375378
def generate_package_file(project_shortname, components, pkg_data, prefix):
376379
package_name = jl_package_name(project_shortname)
@@ -382,33 +385,41 @@ def generate_package_file(project_shortname, components, pkg_data, prefix):
382385
project_ver = pkg_data.get("version")
383386

384387
resources_dist = ",\n".join(
385-
generate_metadata_strings(js_dist, "js") + generate_metadata_strings(css_dist, "css")
388+
generate_metadata_strings(js_dist, "js")
389+
+ generate_metadata_strings(css_dist, "css")
386390
)
387391

388392
package_string = jl_package_file_string.format(
389393
package_name=package_name,
390394
component_includes="\n".join(
391-
[jl_component_include_string.format(name=format_fn_name(prefix, comp_name)) for comp_name in components]
395+
[
396+
jl_component_include_string.format(
397+
name=format_fn_name(prefix, comp_name)
398+
)
399+
for comp_name in components
400+
]
392401
),
393402
resources_dist=resources_dist,
394403
version=project_ver,
395404
project_shortname=project_shortname,
396-
base_package=base_package_name(project_shortname)
397-
405+
base_package=base_package_name(project_shortname),
398406
)
399407
file_path = os.path.join("src", package_name + ".jl")
400408
with open(file_path, "w") as f:
401409
f.write(package_string)
402410
print("Generated {}".format(file_path))
403411

412+
404413
def generate_toml_file(project_shortname, pkg_data):
405414
package_author = pkg_data.get("author", "")
406415
project_ver = pkg_data.get("version")
407416
package_name = jl_package_name(project_shortname)
408417
u = uuid.UUID(jl_dash_uuid)
409418
package_uuid = uuid.UUID(hex=u.hex[:-12] + hex(hash(package_name))[-12:])
410419

411-
authors_string = 'authors = ["{}"]\n'.format(package_author) if package_author else ""
420+
authors_string = (
421+
'authors = ["{}"]\n'.format(package_author) if package_author else ""
422+
)
412423

413424
toml_string = jl_projecttoml_string.format(
414425
package_name=package_name,
@@ -423,15 +434,20 @@ def generate_toml_file(project_shortname, pkg_data):
423434
f.write(toml_string)
424435
print("Generated {}".format(file_path))
425436

437+
426438
def generate_class_string(name, props, description, project_shortname, prefix):
427439
# Ensure props are ordered with children first
428440
filtered_props = reorder_props(filter_props(props))
429441

430442
prop_keys = list(filtered_props.keys())
431443

432-
docstring = create_docstring_jl(
433-
component_name=name, props=filtered_props, description=description
434-
).replace("\r\n", "\n").replace('$', '\$')
444+
docstring = (
445+
create_docstring_jl(
446+
component_name=name, props=filtered_props, description=description
447+
)
448+
.replace("\r\n", "\n")
449+
.replace("$", "\\$")
450+
)
435451

436452
wclist = get_wildcards_jl(props)
437453
default_paramtext = ""
@@ -449,15 +465,16 @@ def generate_class_string(name, props, description, project_shortname, prefix):
449465
).format(item, name)
450466
)
451467

452-
default_paramtext += ", ".join(
453-
":{}".format(p)
454-
for p in prop_keys
455-
)
468+
default_paramtext += ", ".join(":{}".format(p) for p in prop_keys)
456469

457470
has_children = "children" in prop_keys
458471
funcname = format_fn_name(prefix, name)
459-
children_signatures = jl_children_signatures.format(funcname=funcname) if has_children else ""
460-
children_definitions = jl_children_definitions.format(funcname=funcname) if has_children else ""
472+
children_signatures = (
473+
jl_children_signatures.format(funcname=funcname) if has_children else ""
474+
)
475+
children_definitions = (
476+
jl_children_definitions.format(funcname=funcname) if has_children else ""
477+
)
461478
return jl_component_string.format(
462479
funcname=format_fn_name(prefix, name),
463480
docstring=docstring,
@@ -466,21 +483,17 @@ def generate_class_string(name, props, description, project_shortname, prefix):
466483
wildcard_names=stringify_wildcards(wclist, no_symbol=True),
467484
element_name=name,
468485
module_name=project_shortname,
469-
children_signatures = children_signatures,
470-
children_definitions = children_definitions
486+
children_signatures=children_signatures,
487+
children_definitions=children_definitions,
471488
)
472489

473490

474-
def generate_struct_file(
475-
name, props, description, project_shortname, prefix
476-
):
491+
def generate_struct_file(name, props, description, project_shortname, prefix):
477492
props = reorder_props(props=props)
478493
import_string = "# AUTO GENERATED FILE - DO NOT EDIT\n"
479-
class_string = generate_class_string(name,
480-
props,
481-
description,
482-
project_shortname,
483-
prefix)
494+
class_string = generate_class_string(
495+
name, props, description, project_shortname, prefix
496+
)
484497

485498
file_name = format_fn_name(prefix, name) + ".jl"
486499

@@ -494,12 +507,7 @@ def generate_struct_file(
494507

495508
# pylint: disable=unused-argument
496509
def generate_module(
497-
project_shortname,
498-
components,
499-
metadata,
500-
pkg_data,
501-
prefix,
502-
**kwargs
510+
project_shortname, components, metadata, pkg_data, prefix, **kwargs
503511
):
504512
# the Julia source directory for the package won't exist on first call
505513
# create the Julia directory if it is missing

0 commit comments

Comments
 (0)