-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
1189 julia components #1302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1189 julia components #1302
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ | |
from ._all_keywords import julia_keywords | ||
from ._py_components_generation import reorder_props | ||
|
||
# uuid of DashBase Julia package. | ||
jl_dash_base_uuid = "03207cf0-e2b3-4b91-9ca8-690cf0fb507e" | ||
|
||
# uuid of Dash Julia package. Used as base for component package uuid | ||
jl_dash_uuid = "1b08a953-4be3-4667-9a23-3db579824955" | ||
|
||
|
@@ -23,59 +26,48 @@ | |
export {funcname} | ||
|
||
""" | ||
{funcname}(;kwargs...) | ||
{funcname}(children::Any;kwargs...) | ||
{funcname}(children_maker::Function;kwargs...) | ||
{funcname}(;kwargs...){children_signatures} | ||
|
||
{docstring} | ||
""" | ||
function {funcname}(; kwargs...) | ||
available_props = Set(Symbol[{component_props}]) | ||
wild_props = Set(Symbol[{wildcard_symbols}]) | ||
wild_regs = r"^(?<prop>{wildcard_names})" | ||
|
||
result = Component("{element_name}", "{module_name}", Dict{{Symbol, Any}}(), available_props, Set(Symbol[{wildcard_symbols}])) | ||
|
||
for (prop, value) = pairs(kwargs) | ||
m = match(wild_regs, string(prop)) | ||
if (length(wild_props) == 0 || isnothing(m)) && !(prop in available_props) | ||
throw(ArgumentError("Invalid property $(string(prop)) for component " * "{funcname}")) | ||
end | ||
|
||
push!(result.props, prop => Front.to_dash(value)) | ||
end | ||
|
||
return result | ||
available_props = Symbol[{component_props}] | ||
wild_props = Symbol[{wildcard_symbols}] | ||
return Component("{funcname}", "{element_name}", "{module_name}", available_props, wild_props; kwargs...) | ||
end | ||
{children_definitions} | ||
''' # noqa:E501 | ||
|
||
function {funcname}(children::Any; kwargs...) | ||
result = {funcname}(;kwargs...) | ||
push!(result.props, :children => Front.to_dash(children)) | ||
return result | ||
end | ||
jl_children_signatures = ''' | ||
{funcname}(children::Any;kwargs...) | ||
{funcname}(children_maker::Function;kwargs...) | ||
''' | ||
|
||
jl_children_definitions = ''' | ||
{funcname}(children::Any; kwargs...) = {funcname}(;kwargs..., children = children) | ||
{funcname}(children_maker::Function; kwargs...) = {funcname}(children_maker(); kwargs...) | ||
''' # noqa:E501 | ||
''' | ||
|
||
jl_package_file_string = ''' | ||
module {package_name} | ||
using Dash | ||
using {base_package} | ||
|
||
const resources_path = realpath(joinpath( @__DIR__, "..", "deps")) | ||
const version = "{version}" | ||
|
||
{component_includes} | ||
|
||
function __init__() | ||
Dash.register_package( | ||
Dash.ResourcePkg( | ||
DashBase.register_package( | ||
DashBase.ResourcePkg( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not new here, but is it important that this be two nested calls? Could it be refactored to just: DashBase.register_package(
"{project_shortname}",
resources_path,
version = version,
[
{resources_dist}
]
) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @waralex points out we can do this later - not a major issue anyway. |
||
"{project_shortname}", | ||
resources_path, | ||
version = version, | ||
[ | ||
{resources_dist} | ||
] | ||
) | ||
|
||
) | ||
end | ||
end | ||
|
@@ -87,23 +79,24 @@ | |
{authors}version = "{version}" | ||
|
||
[deps] | ||
Dash = "{dash_uuid}" | ||
{base_package} = "{dash_uuid}" | ||
|
||
[compact] | ||
julia = "1.1" | ||
Dash = ">=0.1" | ||
julia = "1.2" | ||
{base_package} = ">=0.1" | ||
''' | ||
|
||
jl_component_include_string = 'include("{name}.jl")' | ||
|
||
jl_resource_tuple_string = '''Dash.Resource( | ||
jl_resource_tuple_string = '''DashBase.Resource( | ||
relative_package_path = {relative_package_path}, | ||
external_url = {external_url}, | ||
dynamic = {dynamic}, | ||
async = {async_string}, | ||
type = :{type} | ||
)''' | ||
|
||
core_packages = ['dash_html_components', 'dash_core_components', 'dash_table'] | ||
|
||
def jl_package_name(namestring): | ||
s = namestring.split("_") | ||
|
@@ -370,6 +363,14 @@ def nothing_or_string(v): | |
else 'nothing' | ||
) for resource in resources] | ||
|
||
def is_core_package(project_shortname): | ||
return project_shortname in core_packages | ||
|
||
def base_package_name(project_shortname): | ||
return "DashBase" if is_core_package(project_shortname) else "Dash" | ||
|
||
def base_package_uid(project_shortname): | ||
return jl_dash_base_uuid if is_core_package(project_shortname) else jl_base_uuid | ||
|
||
def generate_package_file(project_shortname, components, pkg_data, prefix): | ||
package_name = jl_package_name(project_shortname) | ||
|
@@ -391,15 +392,15 @@ def generate_package_file(project_shortname, components, pkg_data, prefix): | |
), | ||
resources_dist=resources_dist, | ||
version=project_ver, | ||
project_shortname=project_shortname | ||
project_shortname=project_shortname, | ||
base_package=base_package_name(project_shortname) | ||
|
||
) | ||
file_path = os.path.join("src", package_name + ".jl") | ||
with open(file_path, "w") as f: | ||
f.write(package_string) | ||
print("Generated {}".format(file_path)) | ||
|
||
|
||
def generate_toml_file(project_shortname, pkg_data): | ||
package_author = pkg_data.get("author", "") | ||
project_ver = pkg_data.get("version") | ||
|
@@ -414,14 +415,14 @@ def generate_toml_file(project_shortname, pkg_data): | |
package_uuid=package_uuid, | ||
version=project_ver, | ||
authors=authors_string, | ||
dash_uuid=jl_dash_uuid | ||
base_package=base_package_name(project_shortname), | ||
dash_uuid=base_package_uid(project_shortname), | ||
) | ||
file_path = "Project.toml" | ||
with open(file_path, "w") as f: | ||
f.write(toml_string) | ||
print("Generated {}".format(file_path)) | ||
|
||
|
||
def generate_class_string(name, props, description, project_shortname, prefix): | ||
# Ensure props are ordered with children first | ||
filtered_props = reorder_props(filter_props(props)) | ||
|
@@ -430,7 +431,7 @@ def generate_class_string(name, props, description, project_shortname, prefix): | |
|
||
docstring = create_docstring_jl( | ||
component_name=name, props=filtered_props, description=description | ||
).replace("\r\n", "\n") | ||
).replace("\r\n", "\n").replace('$', '\$') | ||
|
||
wclist = get_wildcards_jl(props) | ||
default_paramtext = "" | ||
|
@@ -453,6 +454,10 @@ def generate_class_string(name, props, description, project_shortname, prefix): | |
for p in prop_keys | ||
) | ||
|
||
has_children = "children" in prop_keys | ||
funcname = format_fn_name(prefix, name) | ||
children_signatures = jl_children_signatures.format(funcname=funcname) if has_children else "" | ||
children_definitions = jl_children_definitions.format(funcname=funcname) if has_children else "" | ||
return jl_component_string.format( | ||
funcname=format_fn_name(prefix, name), | ||
docstring=docstring, | ||
|
@@ -461,6 +466,8 @@ def generate_class_string(name, props, description, project_shortname, prefix): | |
wildcard_names=stringify_wildcards(wclist, no_symbol=True), | ||
element_name=name, | ||
module_name=project_shortname, | ||
children_signatures = children_signatures, | ||
children_definitions = children_definitions | ||
) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW on the Python side we could have used only
kwargs
like this but we chose to insert all the prop names explicitly in the signature (except wildcards of course) because it helps with autocompletion in IDEs. I have no idea if similar functionality exists in Julia, and anyway even if we do want to do this we can add it later.