38
38
{children_definitions}
39
39
''' # noqa:E501
40
40
41
- jl_children_signatures = '''
41
+ jl_children_signatures = """
42
42
{funcname}(children::Any;kwargs...)
43
43
{funcname}(children_maker::Function;kwargs...)
44
- '''
44
+ """
45
45
46
- jl_children_definitions = '''
46
+ jl_children_definitions = """
47
47
{funcname}(children::Any; kwargs...) = {funcname}(;kwargs..., children = children)
48
48
{funcname}(children_maker::Function; kwargs...) = {funcname}(children_maker(); kwargs...)
49
- '''
49
+ """
50
50
51
- jl_package_file_string = '''
51
+ jl_package_file_string = """
52
52
module {package_name}
53
53
using {base_package}
54
54
67
67
{resources_dist}
68
68
]
69
69
)
70
-
70
+
71
71
)
72
72
end
73
73
end
74
- '''
74
+ """
75
75
76
- jl_projecttoml_string = '''
76
+ jl_projecttoml_string = """
77
77
name = "{package_name}"
78
78
uuid = "{package_uuid}"
79
79
{authors}version = "{version}"
84
84
[compact]
85
85
julia = "1.2"
86
86
{base_package} = ">=0.1"
87
- '''
87
+ """
88
88
89
89
jl_component_include_string = 'include("{name}.jl")'
90
90
91
- jl_resource_tuple_string = ''' DashBase.Resource(
91
+ jl_resource_tuple_string = """ DashBase.Resource(
92
92
relative_package_path = {relative_package_path},
93
93
external_url = {external_url},
94
94
dynamic = {dynamic},
95
95
async = {async_string},
96
96
type = :{type}
97
- )'''
97
+ )"""
98
+
99
+ core_packages = ["dash_html_components" , "dash_core_components" , "dash_table" ]
98
100
99
- core_packages = ['dash_html_components' , 'dash_core_components' , 'dash_table' ]
100
101
101
102
def jl_package_name (namestring ):
102
103
s = namestring .split ("_" )
@@ -105,13 +106,9 @@ def jl_package_name(namestring):
105
106
106
107
def stringify_wildcards (wclist , no_symbol = False ):
107
108
if no_symbol :
108
- wcstring = "|" .join (
109
- '{}-' .format (item ) for item in wclist
110
- )
109
+ wcstring = "|" .join ("{}-" .format (item ) for item in wclist )
111
110
else :
112
- wcstring = ", " .join (
113
- 'Symbol("{}-")' .format (item ) for item in wclist
114
- )
111
+ wcstring = ", " .join ('Symbol("{}-")' .format (item ) for item in wclist )
115
112
return wcstring
116
113
117
114
@@ -289,11 +286,7 @@ def create_docstring_jl(component_name, props, description):
289
286
290
287
291
288
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 ,
297
290
):
298
291
"""
299
292
Create the Dash component prop docstring
@@ -353,24 +346,34 @@ def format_fn_name(prefix, name):
353
346
def generate_metadata_strings (resources , metatype ):
354
347
def nothing_or_string (v ):
355
348
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
+
365
365
366
366
def is_core_package (project_shortname ):
367
367
return project_shortname in core_packages
368
368
369
+
369
370
def base_package_name (project_shortname ):
370
371
return "DashBase" if is_core_package (project_shortname ) else "Dash"
371
372
373
+
372
374
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
+
374
377
375
378
def generate_package_file (project_shortname , components , pkg_data , prefix ):
376
379
package_name = jl_package_name (project_shortname )
@@ -382,33 +385,41 @@ def generate_package_file(project_shortname, components, pkg_data, prefix):
382
385
project_ver = pkg_data .get ("version" )
383
386
384
387
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" )
386
390
)
387
391
388
392
package_string = jl_package_file_string .format (
389
393
package_name = package_name ,
390
394
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
+ ]
392
401
),
393
402
resources_dist = resources_dist ,
394
403
version = project_ver ,
395
404
project_shortname = project_shortname ,
396
- base_package = base_package_name (project_shortname )
397
-
405
+ base_package = base_package_name (project_shortname ),
398
406
)
399
407
file_path = os .path .join ("src" , package_name + ".jl" )
400
408
with open (file_path , "w" ) as f :
401
409
f .write (package_string )
402
410
print ("Generated {}" .format (file_path ))
403
411
412
+
404
413
def generate_toml_file (project_shortname , pkg_data ):
405
414
package_author = pkg_data .get ("author" , "" )
406
415
project_ver = pkg_data .get ("version" )
407
416
package_name = jl_package_name (project_shortname )
408
417
u = uuid .UUID (jl_dash_uuid )
409
418
package_uuid = uuid .UUID (hex = u .hex [:- 12 ] + hex (hash (package_name ))[- 12 :])
410
419
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
+ )
412
423
413
424
toml_string = jl_projecttoml_string .format (
414
425
package_name = package_name ,
@@ -423,15 +434,20 @@ def generate_toml_file(project_shortname, pkg_data):
423
434
f .write (toml_string )
424
435
print ("Generated {}" .format (file_path ))
425
436
437
+
426
438
def generate_class_string (name , props , description , project_shortname , prefix ):
427
439
# Ensure props are ordered with children first
428
440
filtered_props = reorder_props (filter_props (props ))
429
441
430
442
prop_keys = list (filtered_props .keys ())
431
443
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
+ )
435
451
436
452
wclist = get_wildcards_jl (props )
437
453
default_paramtext = ""
@@ -449,15 +465,16 @@ def generate_class_string(name, props, description, project_shortname, prefix):
449
465
).format (item , name )
450
466
)
451
467
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 )
456
469
457
470
has_children = "children" in prop_keys
458
471
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
+ )
461
478
return jl_component_string .format (
462
479
funcname = format_fn_name (prefix , name ),
463
480
docstring = docstring ,
@@ -466,21 +483,17 @@ def generate_class_string(name, props, description, project_shortname, prefix):
466
483
wildcard_names = stringify_wildcards (wclist , no_symbol = True ),
467
484
element_name = name ,
468
485
module_name = project_shortname ,
469
- children_signatures = children_signatures ,
470
- children_definitions = children_definitions
486
+ children_signatures = children_signatures ,
487
+ children_definitions = children_definitions ,
471
488
)
472
489
473
490
474
- def generate_struct_file (
475
- name , props , description , project_shortname , prefix
476
- ):
491
+ def generate_struct_file (name , props , description , project_shortname , prefix ):
477
492
props = reorder_props (props = props )
478
493
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
+ )
484
497
485
498
file_name = format_fn_name (prefix , name ) + ".jl"
486
499
@@ -494,12 +507,7 @@ def generate_struct_file(
494
507
495
508
# pylint: disable=unused-argument
496
509
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
503
511
):
504
512
# the Julia source directory for the package won't exist on first call
505
513
# create the Julia directory if it is missing
0 commit comments