From 708e82d67ffcbcd78140a2fc4bd1e673fba77054 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 19 Jun 2019 13:40:54 -0400 Subject: [PATCH 01/34] :pencil2: append dash_ to wildcards validator fn --- dash/development/_r_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 3589407596..be72e81b3b 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -163,7 +163,7 @@ def generate_class_string(name, props, project_shortname, prefix): if any("-*" in key for key in prop_keys): wildcards = ", ..." wildcard_declaration = ( - "\n wildcard_names = names(assert_valid_wildcards(...))\n" + "\n wildcard_names = names(dash_assert_valid_wildcards(...))\n" ) wildcard_names = ", wildcard_names" From 4e7194197068cb4185068d49f462dd2bba8c29b6 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 19 Jun 2019 14:34:19 -0400 Subject: [PATCH 02/34] :bug: remove duplicated fn name in usage --- dash/development/_r_components_generation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index be72e81b3b..b87cf7b4a8 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -346,14 +346,13 @@ def write_help_file(name, props, description, prefix): # in R, the online help viewer does not properly wrap lines for # the usage string -- we will hard wrap at 80 characters using # textwrap.fill, starting from the beginning of the usage string - argtext = prefix + name + "({})".format(default_argtext) file_path = os.path.join('man', file_name) with open(file_path, 'w') as f: f.write(help_string.format( funcname=format_fn_name(prefix, name), name=name, - default_argtext=textwrap.fill(argtext, + default_argtext=textwrap.fill(default_argtext, width=80, break_long_words=False), item_text=item_text, From 63e8132d162c5a0a14fca88bd4438eb338195bbc Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 19 Jun 2019 15:17:57 -0400 Subject: [PATCH 03/34] added pkg help desc for dashTable --- dash/development/_r_components_generation.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index b87cf7b4a8..791c451059 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -83,7 +83,7 @@ Authors @R: as.person(c({package_author})) Description: {package_description} Depends: R (>= 3.0.2){package_depends} -Imports: dash{package_imports} +Imports: {package_imports} Suggests: {package_suggests} License: {package_license} URL: {package_url} @@ -539,7 +539,7 @@ def generate_rpkg( f2.write(rbuild_ignore_string) # Write package stub files for R online help, generate if - # dashHtmlComponents or dashCoreComponents; makes it easy + # dashHtmlComponents, dashTable, or dashCoreComponents; makes it easy # for R users to bring up main package help page pkg_help_header = "" @@ -559,6 +559,15 @@ def generate_rpkg( written and maintained by the Dash team, is available in\n\ the dashCoreComponents package. The source for this package\n\ is on GitHub: plotly/dash-core-components." + if package_name in ["dashTable"]: + pkg_help_header = "Core Interactive Table Component for Dash" + pkg_help_desc = "Dash DataTable is an interactive table component\n\ +designed for viewing, editing, and exploring large datasets. DataTable is\n\ +rendered with standard, semantic HTML markup, which makes it\n\ +accessible, responsive, and easy to style. This component was written\n\ +from scratch in React.js specifically for the Dash community. Its API\n\ +was designed to be ergonomic and its behavior is completely customizable\n\ +through its properties." description_string = description_template.format( package_name=package_name, From 363c95ee0c040aaa15c48627b62e76de25c7c2ae Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 19 Jun 2019 15:26:43 -0400 Subject: [PATCH 04/34] :hocho: leading comma in DESC fields --- dash/development/_r_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 791c451059..9b5dbd61a3 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -477,7 +477,7 @@ def generate_rpkg( package_depends = ", " + package_depends.strip(",").lstrip() if package_imports: - package_imports = ", " + package_imports.strip(",").lstrip() + package_imports = package_imports.strip(",").lstrip() if package_suggests: package_suggests = package_suggests.strip(",").lstrip() From 2cb4739c9347a283d591605b8660ca5522f6770c Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 19 Jun 2019 17:42:31 -0400 Subject: [PATCH 05/34] append dash_ to filter_null --- dash/development/_r_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 9b5dbd61a3..1b0eba64ce 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -26,7 +26,7 @@ package = '{package_name}' ) - component$props <- filter_null(component$props) + component$props <- dash_filter_null(component$props) structure(component, class = c('dash_component', 'list')) }} From 9ba7c6ad1d077944899d24f06512639ab8795dc4 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 19 Jun 2019 18:24:21 -0400 Subject: [PATCH 06/34] :sparkles: add maintainer option --- dash/development/_r_components_generation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 1b0eba64ce..6281f3b838 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -91,7 +91,7 @@ Encoding: UTF-8 LazyData: true Author: {package_author_no_email} -Maintainer: {package_author} +Maintainer: {maintainer} """ rbuild_ignore_string = r"""# ignore JS config files/folders @@ -505,6 +505,8 @@ def generate_rpkg( package_author_no_email = package_author.split(" <")[0] + " [aut]" + maintainer = pkg_data.get("maintainer", pkg_data.get("author")) + if not (os.path.isfile("LICENSE") or os.path.isfile("LICENSE.txt")): package_license = pkg_data.get("license", "") else: @@ -581,6 +583,7 @@ def generate_rpkg( package_url=package_url, package_issues=package_issues, package_author_no_email=package_author_no_email, + maintainer=maintainer, ) with open("DESCRIPTION", "w") as f3: From 3111a091b9175856609a102e2038add3e53ddf25 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 19 Jun 2019 19:58:46 -0400 Subject: [PATCH 07/34] :sparkles: add component helpers to internal.R --- dash/development/_r_components_generation.py | 30 +++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 6281f3b838..0047dcae25 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -163,7 +163,7 @@ def generate_class_string(name, props, project_shortname, prefix): if any("-*" in key for key in prop_keys): wildcards = ", ..." wildcard_declaration = ( - "\n wildcard_names = names(dash_assert_valid_wildcards(...))\n" + "\n wildcard_names = names(dash::dash_assert_valid_wildcards(...))\n" ) wildcard_names = ", wildcard_names" @@ -416,6 +416,33 @@ def write_js_metadata(pkg_data, project_shortname): ) file_name = "internal.R" + # import dash_filter_null and dash_assert_valid_wildcards + component_helpers = """ +dash_filter_null <- function (x) +{ + if (length(x) == 0 || !is.list(x)) + return(x) + x[!vapply(x, is.null, logical(1))] +} + +dash_assert_valid_wildcards <- function (attrib = list("data", "aria"), ...) +{ + args <- list(...) + validation_results <- lapply(names(args), function(x) { + grepl(paste0("^", attrib, "-[a-zA-Z0-9]{1,}$", collapse = "|"), + x) + }) + if (FALSE %in% validation_results) { + stop(sprintf("The following wildcards are not currently valid in Dash: '%s'", + paste(names(args)[grepl(FALSE, unlist(validation_results))], + collapse = ", ")), call. = FALSE) + } + else { + return(args) + } +} +""" # noqa:E501 + # the R source directory for the package won't exist on first call # create the R directory if it is missing if not os.path.exists("R"): @@ -424,6 +451,7 @@ def write_js_metadata(pkg_data, project_shortname): file_path = os.path.join("R", file_name) with open(file_path, "w") as f: f.write(function_string) + f.write(component_helpers) # now copy over all JS dependencies from the (Python) components dir # the inst/lib directory for the package won't exist on first call From 8e29ca1a2332b90c6bff7cb6bb120af5e1771ccf Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 19 Jun 2019 20:02:05 -0400 Subject: [PATCH 08/34] :pencil2: update .Rbuildignore --- dash/development/_r_components_generation.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 0047dcae25..b363c85d0e 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -103,6 +103,11 @@ .builderrc .eslintrc .npmignore +.editorconfig +.eslintignore +.prettierrc +.circleci +.github # demo folder has special meaning in R # this should hopefully make it still From 320e52ec74d16d1888ceb58f2cac808b1edc8aaa Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Thu, 20 Jun 2019 09:21:34 -0400 Subject: [PATCH 09/34] :hocho: filter_null, :hammer: internal.R --- dash/development/_r_components_generation.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index b363c85d0e..311fbdac2f 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -18,16 +18,18 @@ # code below r_component_string = """{funcname} <- function({default_argtext}{wildcards}) {{ {wildcard_declaration} + props <- list({default_paramtext}{wildcards}) + if (length(props) > 0) { + props <- props[!vapply(props, is.null, logical(1))] + } component <- list( - props = list({default_paramtext}{wildcards}), + props = props, type = '{name}', namespace = '{project_shortname}', propNames = c({prop_names}{wildcard_names}), package = '{package_name}' ) - component$props <- dash_filter_null(component$props) - structure(component, class = c('dash_component', 'list')) }} """ # noqa:E501 @@ -423,13 +425,6 @@ def write_js_metadata(pkg_data, project_shortname): # import dash_filter_null and dash_assert_valid_wildcards component_helpers = """ -dash_filter_null <- function (x) -{ - if (length(x) == 0 || !is.list(x)) - return(x) - x[!vapply(x, is.null, logical(1))] -} - dash_assert_valid_wildcards <- function (attrib = list("data", "aria"), ...) { args <- list(...) From 02afe2af901cf0cef3864f35c33fe5994cf04778 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Thu, 20 Jun 2019 14:43:59 -0400 Subject: [PATCH 10/34] :sparkles: add get_wildcards_r method --- dash/development/_r_components_generation.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 311fbdac2f..8aa26ccd31 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -860,3 +860,13 @@ def create_prop_docstring_r(prop_name, type_object, required, description, ': {}'.format(description) if description != '' else '' ), is_required='required' if required else 'optional') + + +def get_wildcards_r(prop_keys): + wildcards = "" + wildcards += ", ".join("'{}'".format(p) + for p in prop_keys if "*" in p) + + if wildcards == "": + wildcards = "NULL" + return wildcards From 9cee1d33a30c4ed9b0be432addd46dca8eec042f Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Thu, 20 Jun 2019 14:44:46 -0400 Subject: [PATCH 11/34] :shirt: remove whitespace --- dash/development/_r_components_generation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 8aa26ccd31..6512cef57e 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -425,16 +425,16 @@ def write_js_metadata(pkg_data, project_shortname): # import dash_filter_null and dash_assert_valid_wildcards component_helpers = """ -dash_assert_valid_wildcards <- function (attrib = list("data", "aria"), ...) +dash_assert_valid_wildcards <- function (attrib = list("data", "aria"), ...) { args <- list(...) validation_results <- lapply(names(args), function(x) { - grepl(paste0("^", attrib, "-[a-zA-Z0-9]{1,}$", collapse = "|"), + grepl(paste0("^", attrib, "-[a-zA-Z0-9]{1,}$", collapse = "|"), x) }) if (FALSE %in% validation_results) { - stop(sprintf("The following wildcards are not currently valid in Dash: '%s'", - paste(names(args)[grepl(FALSE, unlist(validation_results))], + stop(sprintf("The following wildcards are not currently valid in Dash: '%s'", + paste(names(args)[grepl(FALSE, unlist(validation_results))], collapse = ", ")), call. = FALSE) } else { From 0f4ed2dee884a6eacd225b8978f6b2ee270613e2 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Thu, 20 Jun 2019 14:45:22 -0400 Subject: [PATCH 12/34] :see_no_evil: fix missing doubled braces for R --- dash/development/_r_components_generation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 6512cef57e..46d490aa78 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -19,9 +19,9 @@ r_component_string = """{funcname} <- function({default_argtext}{wildcards}) {{ {wildcard_declaration} props <- list({default_paramtext}{wildcards}) - if (length(props) > 0) { + if (length(props) > 0) {{ props <- props[!vapply(props, is.null, logical(1))] - } + }} component <- list( props = props, type = '{name}', From 6eb6f0457a27cae747707937ed6c9bc2225ca85e Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Thu, 20 Jun 2019 15:12:25 -0400 Subject: [PATCH 13/34] :hammer: documentation for dynamic WCs --- dash/development/_r_components_generation.py | 31 ++++++++------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 46d490aa78..85b2c9349e 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -166,18 +166,18 @@ def generate_class_string(name, props, project_shortname, prefix): wildcards = "" wildcard_declaration = "" wildcard_names = "" + default_paramtext = "" + default_argtext = "" + accepted_wildcards = "" if any("-*" in key for key in prop_keys): + accepted_wildcards = get_wildcards_r(prop_keys) wildcards = ", ..." - wildcard_declaration = ( - "\n wildcard_names = names(dash::dash_assert_valid_wildcards(...))\n" - ) + wildcard_declaration = """ + wildcard_names = names(dash_assert_valid_wildcards(attrib = list({}), ...)) +""".format(accepted_wildcards.replace("-*", "")) # noqa:E501 wildcard_names = ", wildcard_names" - default_paramtext = "" - default_argtext = "" - default_wildcards = "" - # Produce a string with all property names other than WCs prop_names = ", ".join( "'{}'".format(p) @@ -185,16 +185,6 @@ def generate_class_string(name, props, project_shortname, prefix): if "*" not in p and p not in ["setProps"] ) - # in R, we set parameters with no defaults to NULL - # Here we'll do that if no default value exists - default_wildcards += ", ".join("'{}'".format(p) - for p in prop_keys if "*" in p) - - if default_wildcards == "": - default_wildcards = "NULL" - else: - default_wildcards = "c({})".format(default_wildcards) - # Filter props to remove those we don't want to expose for item in prop_keys[:]: if item.endswith("-*") or item in r_keywords or item == "setProps": @@ -330,6 +320,9 @@ def write_help_file(name, props, description, prefix): has_wildcards = any("-*" in key for key in prop_keys) + if has_wildcards: + wildcards = get_wildcards_r(prop_keys) + # Filter props to remove those we don't want to expose for item in prop_keys[:]: if item.endswith("-*") or item in r_keywords or item == "setProps": @@ -347,8 +340,10 @@ def write_help_file(name, props, description, prefix): ) if has_wildcards: - item_text += '\n\n\\item{...}{wildcards: `data-*` or `aria-*`}' default_argtext += ', ...' + item_text += """ +\n\n\\item{{...}}{{wildcards allowed have the form: `{}`}} +""".format(wildcards) # in R, the online help viewer does not properly wrap lines for # the usage string -- we will hard wrap at 80 characters using From b104e7a7437118abe02eee57e62bc74c662b923d Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Thu, 20 Jun 2019 15:39:43 -0400 Subject: [PATCH 14/34] :bug: fix missing quotation marks --- dash/development/_r_components_generation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 85b2c9349e..9abae633e9 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -44,7 +44,7 @@ version = "{project_ver}", src = list(href = NULL, file = "deps"), meta = NULL, script = {script_name}, -stylesheet = {css_name}, head = NULL, attachment = NULL, package = "{rpkgname}", +stylesheet = "{css_name}", head = NULL, attachment = NULL, package = "{rpkgname}", all_files = FALSE), class = "html_dependency")""" # noqa:E501 frame_body_template = """`{project_shortname}` = structure(list(name = "{project_shortname}", @@ -275,10 +275,10 @@ def generate_js_metadata(pkg_data, project_shortname): elif len(alldist) == 1: rpp = alldist[0]["relative_package_path"] if "css" in rpp: - css_name = rpp + css_name = "'{}'".format(rpp) script_name = "NULL" else: - script_name = rpp + script_name = "'{}'".format(rpp) css_name = "NULL" function_frame_body = frame_body_template.format( project_shortname=project_shortname, From fcd82a52a52584e50f6ceef4d43f9d39df10805f Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Thu, 20 Jun 2019 17:22:10 -0400 Subject: [PATCH 15/34] use key.endswith --- dash/development/_r_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 9abae633e9..47ec68f594 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -318,7 +318,7 @@ def write_help_file(name, props, description, prefix): prop_keys = list(props.keys()) - has_wildcards = any("-*" in key for key in prop_keys) + has_wildcards = any(key.endswith("-*") for key in prop_keys) if has_wildcards: wildcards = get_wildcards_r(prop_keys) From 1578e9ac76316be72f211e2a318ee764707243b4 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Thu, 20 Jun 2019 17:23:02 -0400 Subject: [PATCH 16/34] use p.endswith --- dash/development/_r_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 47ec68f594..4b353a10a3 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -860,7 +860,7 @@ def create_prop_docstring_r(prop_name, type_object, required, description, def get_wildcards_r(prop_keys): wildcards = "" wildcards += ", ".join("'{}'".format(p) - for p in prop_keys if "*" in p) + for p in prop_keys if p.endswith("-*")) if wildcards == "": wildcards = "NULL" From c6a013a15eb90a5cc1cf939d4f711133800bd255 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Thu, 20 Jun 2019 17:23:59 -0400 Subject: [PATCH 17/34] check WCs before f.write --- dash/development/_r_components_generation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 4b353a10a3..49cfe851f2 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -446,7 +446,8 @@ def write_js_metadata(pkg_data, project_shortname): file_path = os.path.join("R", file_name) with open(file_path, "w") as f: f.write(function_string) - f.write(component_helpers) + if has_wildcards: + f.write(component_helpers) # now copy over all JS dependencies from the (Python) components dir # the inst/lib directory for the package won't exist on first call From 8f50b8a17d064ac7da28de182235340e2ea3be43 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 21 Jun 2019 10:50:18 -0400 Subject: [PATCH 18/34] :paw_prints: relocate component_helpers to template section --- dash/development/_r_components_generation.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 49cfe851f2..5e2ab9243f 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -152,6 +152,25 @@ }} """ +component_helpers = """ +dash_assert_valid_wildcards <- function (attrib = list("data", "aria"), ...) +{ + args <- list(...) + validation_results <- lapply(names(args), function(x) { + grepl(paste0("^", attrib, "-[a-zA-Z0-9]{1,}$", collapse = "|"), + x) + }) + if (FALSE %in% validation_results) { + stop(sprintf("The following wildcards are not currently valid in Dash: '%s'", + paste(names(args)[grepl(FALSE, unlist(validation_results))], + collapse = ", ")), call. = FALSE) + } + else { + return(args) + } +} +""" # noqa:E501 + # pylint: disable=R0914 def generate_class_string(name, props, project_shortname, prefix): From 628e00da065395e57c9ced58a5ae271cd3af7205 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 21 Jun 2019 10:52:24 -0400 Subject: [PATCH 19/34] :sparkles: initial use of YAML for R :package: config --- dash/development/_r_components_generation.py | 47 +++++--------------- dash/development/component_generator.py | 15 ++++++- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 5e2ab9243f..7437adae60 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -136,16 +136,15 @@ \\docType{{package}} \\name{{{package_name}-package}} \\alias{{{package_name}}} -\\title{{{pkg_help_header}}} +\\title{{{pkg_help_title}}} \\description{{ -{pkg_help_desc} -}} \\seealso{{ Useful links: \\itemize{{ \\item \\url{{https://github.com/plotly/{lib_name}}} \\item Report bugs at \\url{{https://github.com/plotly/{lib_name}/issues}} }} +{pkg_help_description} }} \\author{{ \\strong{{Maintainer}}: {package_author} @@ -487,6 +486,7 @@ def write_js_metadata(pkg_data, project_shortname): # pylint: disable=R0914, R0913, R0912, R0915 def generate_rpkg( pkg_data, + rpkg_data, project_shortname, export_string, package_depends, @@ -499,8 +499,12 @@ def generate_rpkg( Parameters ---------- pkg_data + rpkg_data project_shortname export_string + package_depends + package_imports + package_suggests Returns ------- @@ -583,37 +587,6 @@ def generate_rpkg( with open(".Rbuildignore", "w") as f2: f2.write(rbuild_ignore_string) - # Write package stub files for R online help, generate if - # dashHtmlComponents, dashTable, or dashCoreComponents; makes it easy - # for R users to bring up main package help page - pkg_help_header = "" - - if package_name in ["dashHtmlComponents"]: - pkg_help_header = "Vanilla HTML Components for Dash" - pkg_help_desc = "Dash is a web application framework that\n\ -provides pure Python and R abstraction around HTML, CSS, and\n\ -JavaScript. Instead of writing HTML or using an HTML\n\ -templating engine, you compose your layout using R\n\ -functions within the dashHtmlComponents package. The\n\ -source for this package is on GitHub:\n\ -plotly/dash-html-components." - if package_name in ["dashCoreComponents"]: - pkg_help_header = "Core Interactive UI Components for Dash" - pkg_help_desc = "Dash ships with supercharged components for\n\ -interactive user interfaces. A core set of components,\n\ -written and maintained by the Dash team, is available in\n\ -the dashCoreComponents package. The source for this package\n\ -is on GitHub: plotly/dash-core-components." - if package_name in ["dashTable"]: - pkg_help_header = "Core Interactive Table Component for Dash" - pkg_help_desc = "Dash DataTable is an interactive table component\n\ -designed for viewing, editing, and exploring large datasets. DataTable is\n\ -rendered with standard, semantic HTML
markup, which makes it\n\ -accessible, responsive, and easy to style. This component was written\n\ -from scratch in React.js specifically for the Dash community. Its API\n\ -was designed to be ergonomic and its behavior is completely customizable\n\ -through its properties." - description_string = description_template.format( package_name=package_name, package_description=package_description, @@ -635,8 +608,8 @@ def generate_rpkg( if pkg_help_header != "": pkghelp = pkghelp_stub.format( package_name=package_name, - pkg_help_header=pkg_help_header, - pkg_help_desc=pkg_help_desc, + pkg_help_title=rpkg_data.get("pkg_help_title"), + pkg_help_description=rpkg_data.get("pkg_help_description"), lib_name=lib_name, package_author=package_author, ) @@ -668,6 +641,7 @@ def generate_exports( components, metadata, pkg_data, + rpkg_data, prefix, package_depends, package_imports, @@ -718,6 +692,7 @@ def generate_exports( # locally or directly from GitHub generate_rpkg( pkg_data, + rpkg_data, project_shortname, export_string, package_depends, diff --git a/dash/development/component_generator.py b/dash/development/component_generator.py index e1c916a465..ae5b8b0f2d 100644 --- a/dash/development/component_generator.py +++ b/dash/development/component_generator.py @@ -2,6 +2,7 @@ from collections import OrderedDict import json +import yaml import sys import subprocess import shlex @@ -103,6 +104,14 @@ def generate_components( os.makedirs('man') if not os.path.exists('R'): os.makedirs('R') + if os.path.isfile("dash-info.yaml"): + yamldata = open("dash-info.yaml", 'r') + else: + print( + "Error: dash-info.yaml missing; R package metadata not loaded", + file=sys.stderr + ) + sys.exit(1) generator_methods.append( functools.partial(write_class_file, prefix=prefix)) @@ -120,6 +129,7 @@ def generate_components( if rprefix is not None: with open('package.json', 'r') as f: jsondata_unicode = json.load(f, object_pairs_hook=OrderedDict) + rpkg_data = yaml.safe_load(yamldata) if sys.version_info[0] >= 3: pkg_data = jsondata_unicode else: @@ -130,11 +140,14 @@ def generate_components( components, metadata, pkg_data, + rpkg_data, prefix, rdepends, rimports, rsuggests, - ) + ) + else: + rpkgdata = None def cli(): From 4e2b859f87d954758e51bcaf8b063bd9f4f1cfe5 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 21 Jun 2019 10:52:55 -0400 Subject: [PATCH 20/34] use maintainer if available --- dash/development/_r_components_generation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 7437adae60..332952af8a 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -147,7 +147,7 @@ {pkg_help_description} }} \\author{{ -\\strong{{Maintainer}}: {package_author} +\\strong{{Maintainer}}: {maintainer} }} """ @@ -611,7 +611,7 @@ def generate_rpkg( pkg_help_title=rpkg_data.get("pkg_help_title"), pkg_help_description=rpkg_data.get("pkg_help_description"), lib_name=lib_name, - package_author=package_author, + maintainer=maintainer, ) with open(pkghelp_stub_path, "w") as f4: f4.write(pkghelp) From 393ab8b515f82ff0046d4e397b6d551187c99929 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 21 Jun 2019 10:55:43 -0400 Subject: [PATCH 21/34] :hammer: add + to create config files if nonexistent --- dash/development/_r_components_generation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 332952af8a..a0ba3b5836 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -579,12 +579,12 @@ def generate_rpkg( # this avoids having to generate an RData file from within Python. write_js_metadata(pkg_data=pkg_data, project_shortname=project_shortname) - with open("NAMESPACE", "w") as f: + with open("NAMESPACE", "w+") as f: f.write(import_string) f.write(export_string) f.write(packages_string) - with open(".Rbuildignore", "w") as f2: + with open(".Rbuildignore", "w+") as f2: f2.write(rbuild_ignore_string) description_string = description_template.format( @@ -602,7 +602,7 @@ def generate_rpkg( maintainer=maintainer, ) - with open("DESCRIPTION", "w") as f3: + with open("DESCRIPTION", "w+") as f3: f3.write(description_string) if pkg_help_header != "": From 5c1a10498e07c43715e68ef8d9050d38dcbb5ff0 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 21 Jun 2019 10:56:05 -0400 Subject: [PATCH 22/34] :hocho: links, redundant given DESCRIPTION --- dash/development/_r_components_generation.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index a0ba3b5836..937772b96d 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -138,12 +138,6 @@ \\alias{{{package_name}}} \\title{{{pkg_help_title}}} \\description{{ -\\seealso{{ -Useful links: -\\itemize{{ - \\item \\url{{https://github.com/plotly/{lib_name}}} - \\item Report bugs at \\url{{https://github.com/plotly/{lib_name}/issues}} -}} {pkg_help_description} }} \\author{{ From 7a8da3b26a8a951f5c3f0bd98bbee414a5e8388f Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 21 Jun 2019 10:56:24 -0400 Subject: [PATCH 23/34] remove blank line --- dash/development/component_generator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dash/development/component_generator.py b/dash/development/component_generator.py index ae5b8b0f2d..9c05e9f6af 100644 --- a/dash/development/component_generator.py +++ b/dash/development/component_generator.py @@ -134,7 +134,6 @@ def generate_components( pkg_data = jsondata_unicode else: pkg_data = byteify(jsondata_unicode) - generate_exports( project_shortname, components, From 2d31fdcbcb52bb83e3a1701918e0c99258626e56 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 21 Jun 2019 12:26:20 -0400 Subject: [PATCH 24/34] :hocho: component_handlers --- dash/development/_r_components_generation.py | 23 +------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 937772b96d..c231e157a8 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -430,26 +430,6 @@ def write_js_metadata(pkg_data, project_shortname): ) file_name = "internal.R" - # import dash_filter_null and dash_assert_valid_wildcards - component_helpers = """ -dash_assert_valid_wildcards <- function (attrib = list("data", "aria"), ...) -{ - args <- list(...) - validation_results <- lapply(names(args), function(x) { - grepl(paste0("^", attrib, "-[a-zA-Z0-9]{1,}$", collapse = "|"), - x) - }) - if (FALSE %in% validation_results) { - stop(sprintf("The following wildcards are not currently valid in Dash: '%s'", - paste(names(args)[grepl(FALSE, unlist(validation_results))], - collapse = ", ")), call. = FALSE) - } - else { - return(args) - } -} -""" # noqa:E501 - # the R source directory for the package won't exist on first call # create the R directory if it is missing if not os.path.exists("R"): @@ -458,8 +438,7 @@ def write_js_metadata(pkg_data, project_shortname): file_path = os.path.join("R", file_name) with open(file_path, "w") as f: f.write(function_string) - if has_wildcards: - f.write(component_helpers) + f.write(component_helpers) # now copy over all JS dependencies from the (Python) components dir # the inst/lib directory for the package won't exist on first call From 857bb919d06994228d3d6d704bb1e96510c3bd85 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 21 Jun 2019 12:28:41 -0400 Subject: [PATCH 25/34] :see_no_evil: fix check for pkg description --- dash/development/_r_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index c231e157a8..05f8f83257 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -578,7 +578,7 @@ def generate_rpkg( with open("DESCRIPTION", "w+") as f3: f3.write(description_string) - if pkg_help_header != "": + if rpkg_data.get("pkg_help_description"): pkghelp = pkghelp_stub.format( package_name=package_name, pkg_help_title=rpkg_data.get("pkg_help_title"), From f0bfd078d8b03912a37fc43c02b5fbdcb0676ffc Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 21 Jun 2019 22:06:22 -0400 Subject: [PATCH 26/34] :bug: fix quotation bug in template --- dash/development/_r_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 05f8f83257..08eca717c9 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -44,7 +44,7 @@ version = "{project_ver}", src = list(href = NULL, file = "deps"), meta = NULL, script = {script_name}, -stylesheet = "{css_name}", head = NULL, attachment = NULL, package = "{rpkgname}", +stylesheet = {css_name}, head = NULL, attachment = NULL, package = "{rpkgname}", all_files = FALSE), class = "html_dependency")""" # noqa:E501 frame_body_template = """`{project_shortname}` = structure(list(name = "{project_shortname}", From 862fe704027a0bb35fed5c5723ec42b46bf48ab1 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 26 Jun 2019 15:24:19 -0400 Subject: [PATCH 27/34] turn missing YaML error into warning --- dash/development/_r_components_generation.py | 23 ++++++++++---------- dash/development/component_generator.py | 14 +++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 08eca717c9..b768217916 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -265,7 +265,7 @@ def generate_js_metadata(pkg_data, project_shortname): if "dash_" in rpp: dep_name = rpp.split(".")[0] else: - dep_name = "{}_{}".format(project_shortname, str(dep)) + dep_name = "{}".format(project_shortname) project_ver = str(dep) if "css" in rpp: css_name = "'{}'".format(rpp) @@ -578,16 +578,17 @@ def generate_rpkg( with open("DESCRIPTION", "w+") as f3: f3.write(description_string) - if rpkg_data.get("pkg_help_description"): - pkghelp = pkghelp_stub.format( - package_name=package_name, - pkg_help_title=rpkg_data.get("pkg_help_title"), - pkg_help_description=rpkg_data.get("pkg_help_description"), - lib_name=lib_name, - maintainer=maintainer, - ) - with open(pkghelp_stub_path, "w") as f4: - f4.write(pkghelp) + if rpkg_data is not None: + if rpkg_data.get("pkg_help_description"): + pkghelp = pkghelp_stub.format( + package_name=package_name, + pkg_help_title=rpkg_data.get("pkg_help_title"), + pkg_help_description=rpkg_data.get("pkg_help_description"), + lib_name=lib_name, + maintainer=maintainer, + ) + with open(pkghelp_stub_path, "w") as f4: + f4.write(pkghelp) # This converts a string from snake case to camel case diff --git a/dash/development/component_generator.py b/dash/development/component_generator.py index 9c05e9f6af..52eb823673 100644 --- a/dash/development/component_generator.py +++ b/dash/development/component_generator.py @@ -56,6 +56,8 @@ def generate_components( is_windows = sys.platform == "win32" + yamldata = None + extract_path = pkg_resources.resource_filename("dash", "extract-meta.js") reserved_patterns = '|'.join('^{}$'.format(p) for p in reserved_words) @@ -105,13 +107,12 @@ def generate_components( if not os.path.exists('R'): os.makedirs('R') if os.path.isfile("dash-info.yaml"): - yamldata = open("dash-info.yaml", 'r') + yamldata = open("dash-info.yaml") else: print( - "Error: dash-info.yaml missing; R package metadata not loaded", + "Warning: dash-info.yaml missing; package metadata not loaded", file=sys.stderr ) - sys.exit(1) generator_methods.append( functools.partial(write_class_file, prefix=prefix)) @@ -129,7 +130,10 @@ def generate_components( if rprefix is not None: with open('package.json', 'r') as f: jsondata_unicode = json.load(f, object_pairs_hook=OrderedDict) - rpkg_data = yaml.safe_load(yamldata) + if yamldata is not None: + rpkg_data = yaml.safe_load(yamldata) + else: + rpkg_data = None if sys.version_info[0] >= 3: pkg_data = jsondata_unicode else: @@ -144,7 +148,7 @@ def generate_components( rdepends, rimports, rsuggests, - ) + ) else: rpkgdata = None From e35f040c112dd36642b9d1b235781a8d3451e130 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Fri, 28 Jun 2019 20:49:58 -0400 Subject: [PATCH 28/34] warn on R keyword prop removal --- dash/development/_r_components_generation.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index e863f929d5..79c791d26d 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -8,6 +8,7 @@ import importlib import textwrap import re +import warnings from ._all_keywords import r_keywords from ._py_components_generation import reorder_props @@ -199,8 +200,14 @@ def generate_class_string(name, props, project_shortname, prefix): # Filter props to remove those we don't want to expose for item in prop_keys[:]: - if item.endswith("-*") or item in r_keywords or item == "setProps": + if item.endswith("-*") or item == "setProps": + prop_keys.remove(item) + elif item in r_keywords: prop_keys.remove(item) + warnings.warn(( + 'WARNING: prop "{}" in component "{}" is an R keyword' + ' - REMOVED FROM THE R COMPONENT' + ).format(item, name)) default_argtext += ", ".join("{}=NULL".format(p) for p in prop_keys) From 15cbea84e4be40125b7ef3302de32ee6ec0fa92f Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Fri, 28 Jun 2019 21:22:38 -0400 Subject: [PATCH 29/34] include dash_assert_valid_wildcards only when necessary --- dash/development/_r_components_generation.py | 22 ++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 79c791d26d..e5b02db3a5 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -146,7 +146,7 @@ }} """ -component_helpers = """ +wildcard_helper = """ dash_assert_valid_wildcards <- function (attrib = list("data", "aria"), ...) { args <- list(...) @@ -183,7 +183,7 @@ def generate_class_string(name, props, project_shortname, prefix): default_argtext = "" accepted_wildcards = "" - if any("-*" in key for key in prop_keys): + if any(key.endswith("-*") for key in prop_keys): accepted_wildcards = get_wildcards_r(prop_keys) wildcards = ", ..." wildcard_declaration = """ @@ -419,7 +419,7 @@ def write_class_file(name, print("Generated {}".format(file_name)) -def write_js_metadata(pkg_data, project_shortname): +def write_js_metadata(pkg_data, project_shortname, has_wildcards): """ Write an internal (not exported) R function to return all JS dependencies as required by dash. @@ -445,7 +445,8 @@ def write_js_metadata(pkg_data, project_shortname): file_path = os.path.join("R", file_name) with open(file_path, "w") as f: f.write(function_string) - f.write(component_helpers) + if has_wildcards: + f.write(wildcard_helper) # now copy over all JS dependencies from the (Python) components dir # the inst/lib directory for the package won't exist on first call @@ -471,7 +472,8 @@ def generate_rpkg( export_string, package_depends, package_imports, - package_suggests + package_suggests, + has_wildcards, ): """ Generate documents for R package creation @@ -557,7 +559,7 @@ def generate_rpkg( # generate the internal (not exported to the user) functions which # supply the JavaScript dependencies to the dash package. # this avoids having to generate an RData file from within Python. - write_js_metadata(pkg_data=pkg_data, project_shortname=project_shortname) + write_js_metadata(pkg_data, project_shortname, has_wildcards) with open("NAMESPACE", "w+") as f: f.write(import_string) @@ -668,6 +670,13 @@ def generate_exports( export_string += "\n".join("export({})".format(function) for function in fnlist) + # Look for wildcards in the metadata + has_wildcards = False + for component_data in metadata.values(): + if any(key.endswith('-*') for key in component_data['props']): + has_wildcards = True + break + # now, bundle up the package information and create all the requisite # elements of an R package, so that the end result is installable either # locally or directly from GitHub @@ -679,6 +688,7 @@ def generate_exports( package_depends, package_imports, package_suggests, + has_wildcards, ) From 4bea826b2c450d6d72d1382c3baeaf334a2a1ab2 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Fri, 28 Jun 2019 21:28:19 -0400 Subject: [PATCH 30/34] tweaks to regex and failure message in dash_assert_valid_wildcards --- dash/development/_r_components_generation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index e5b02db3a5..7cb65d0215 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -151,11 +151,11 @@ { args <- list(...) validation_results <- lapply(names(args), function(x) { - grepl(paste0("^", attrib, "-[a-zA-Z0-9]{1,}$", collapse = "|"), + grepl(paste0("^(", paste0(attrib, collapse="|"), ")-[a-zA-Z0-9_-]+$"), x) }) if (FALSE %in% validation_results) { - stop(sprintf("The following wildcards are not currently valid in Dash: '%s'", + stop(sprintf("The following props are not valid in this component: '%s'", paste(names(args)[grepl(FALSE, unlist(validation_results))], collapse = ", ")), call. = FALSE) } From 23d8b7931a6cf1fb1bd68d744e8b2a24bbfb4d97 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Fri, 28 Jun 2019 21:54:50 -0400 Subject: [PATCH 31/34] lint --- dash/development/_r_components_generation.py | 65 ++++++++------------ dash/development/component_generator.py | 2 - 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 7cb65d0215..47058b0af5 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -163,7 +163,17 @@ return(args) } } -""" # noqa:E501 +""" # noqa:E501 + +wildcard_template = """ + wildcard_names = names(dash_assert_valid_wildcards(attrib = list({}), ...)) +""" + +wildcard_help_template = """ + + +\\item{{...}}{{wildcards allowed have the form: `{}`}} +""" # pylint: disable=R0914 @@ -186,9 +196,9 @@ def generate_class_string(name, props, project_shortname, prefix): if any(key.endswith("-*") for key in prop_keys): accepted_wildcards = get_wildcards_r(prop_keys) wildcards = ", ..." - wildcard_declaration = """ - wildcard_names = names(dash_assert_valid_wildcards(attrib = list({}), ...)) -""".format(accepted_wildcards.replace("-*", "")) # noqa:E501 + wildcard_declaration = wildcard_template.format( + accepted_wildcards.replace("-*", "") + ) wildcard_names = ", wildcard_names" # Produce a string with all property names other than WCs @@ -337,11 +347,6 @@ def write_help_file(name, props, description, prefix): prop_keys = list(props.keys()) - has_wildcards = any(key.endswith("-*") for key in prop_keys) - - if has_wildcards: - wildcards = get_wildcards_r(prop_keys) - # Filter props to remove those we don't want to expose for item in prop_keys[:]: if item.endswith("-*") or item in r_keywords or item == "setProps": @@ -350,19 +355,17 @@ def write_help_file(name, props, description, prefix): default_argtext += ", ".join("{}=NULL".format(p) for p in prop_keys) item_text += "\n\n".join( - "\\item{{{}}}{{{}{}}}".format(p, - print_r_type( - props[p]["type"] - ), - props[p]["description"]) + "\\item{{{}}}{{{}{}}}".format( + p, + print_r_type(props[p]["type"]), + props[p]["description"] + ) for p in prop_keys ) - if has_wildcards: + if any(key.endswith("-*") for key in prop_keys): default_argtext += ', ...' - item_text += """ -\n\n\\item{{...}}{{wildcards allowed have the form: `{}`}} -""".format(wildcards) + item_text += wildcard_help_template.format(get_wildcards_r(prop_keys)) # in R, the online help viewer does not properly wrap lines for # the usage string -- we will hard wrap at 80 characters using @@ -381,11 +384,7 @@ def write_help_file(name, props, description, prefix): )) -def write_class_file(name, - props, - description, - project_shortname, - prefix=None): +def write_class_file(name, props, description, project_shortname, prefix=None): props = reorder_props(props=props) # generate the R help pages for each of the Dash components that we @@ -393,20 +392,12 @@ def write_class_file(name, # we may eventually be able to generate similar documentation using # doxygen and an R plugin, but for now we'll just do it on our own # from within Python - write_help_file( - name, - props, - description, - prefix - ) + write_help_file(name, props, description, prefix) import_string =\ "# AUTO GENERATED FILE - DO NOT EDIT\n\n" class_string = generate_class_string( - name, - props, - project_shortname, - prefix + name, props, project_shortname, prefix ) file_name = format_fn_name(prefix, name) + ".R" @@ -511,7 +502,7 @@ def generate_rpkg( if package_suggests: package_suggests = package_suggests.strip(",").lstrip() - if "bugs" in pkg_data.keys(): + if "bugs" in pkg_data: package_issues = pkg_data["bugs"].get("url", "") else: package_issues = "" @@ -521,7 +512,7 @@ def generate_rpkg( file=sys.stderr, ) - if "homepage" in pkg_data.keys(): + if "homepage" in pkg_data: package_url = pkg_data.get("homepage", "") else: package_url = "" @@ -636,9 +627,7 @@ def generate_exports( if ( not component.endswith("-*") and str(component) not in r_keywords - and str(component) not in ["setProps", - "children", - "dashEvents"] + and str(component) not in ["setProps", "children"] ): export_string += "export({}{})\n".format(prefix, component) diff --git a/dash/development/component_generator.py b/dash/development/component_generator.py index 52eb823673..04286a1a6c 100644 --- a/dash/development/component_generator.py +++ b/dash/development/component_generator.py @@ -149,8 +149,6 @@ def generate_components( rimports, rsuggests, ) - else: - rpkgdata = None def cli(): From 1c56d9ab7b135bbc1ce0c8e7f14bb6b6aa503f88 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Fri, 28 Jun 2019 22:09:39 -0400 Subject: [PATCH 32/34] add PyYAML dep --- requires-install.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requires-install.txt b/requires-install.txt index 61b19f0cf0..3a9d71da36 100644 --- a/requires-install.txt +++ b/requires-install.txt @@ -1,4 +1,5 @@ Flask>=0.12 +PyYAML>=5.1.1 flask-compress plotly dash_renderer==1.0.0 @@ -15,4 +16,4 @@ selenium percy requests[security] beautifulsoup4 -waitress \ No newline at end of file +waitress From e029904faa1b6fef95d7fd77846ee5c88112e2b9 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Fri, 28 Jun 2019 22:33:39 -0400 Subject: [PATCH 33/34] lint & simplify component_generator --- dash/development/component_generator.py | 51 +++++++++++-------------- requires-ci.txt | 3 +- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/dash/development/component_generator.py b/dash/development/component_generator.py index 04286a1a6c..9c8abef3d3 100644 --- a/dash/development/component_generator.py +++ b/dash/development/component_generator.py @@ -2,7 +2,6 @@ from collections import OrderedDict import json -import yaml import sys import subprocess import shlex @@ -12,6 +11,7 @@ import functools import pkg_resources +import yaml from ._r_components_generation import write_class_file from ._r_components_generation import generate_exports @@ -51,9 +51,6 @@ def generate_components( project_shortname = project_shortname.replace("-", "_").rstrip("/\\") - if rprefix is not None: - prefix = rprefix - is_windows = sys.platform == "win32" yamldata = None @@ -92,12 +89,7 @@ def generate_components( ) sys.exit(1) - jsondata_unicode = json.loads(out.decode(), object_pairs_hook=OrderedDict) - - if sys.version_info[0] >= 3: - metadata = jsondata_unicode - else: - metadata = byteify(jsondata_unicode) + metadata = safe_json_loads(out.decode()) generator_methods = [generate_class_file] @@ -106,15 +98,8 @@ def generate_components( os.makedirs('man') if not os.path.exists('R'): os.makedirs('R') - if os.path.isfile("dash-info.yaml"): - yamldata = open("dash-info.yaml") - else: - print( - "Warning: dash-info.yaml missing; package metadata not loaded", - file=sys.stderr - ) generator_methods.append( - functools.partial(write_class_file, prefix=prefix)) + functools.partial(write_class_file, prefix=rprefix)) components = generate_classes_files( project_shortname, @@ -128,29 +113,39 @@ def generate_components( generate_imports(project_shortname, components) if rprefix is not None: - with open('package.json', 'r') as f: - jsondata_unicode = json.load(f, object_pairs_hook=OrderedDict) - if yamldata is not None: + if os.path.isfile("dash-info.yaml"): + with open("dash-info.yaml") as yamldata: rpkg_data = yaml.safe_load(yamldata) - else: - rpkg_data = None - if sys.version_info[0] >= 3: - pkg_data = jsondata_unicode - else: - pkg_data = byteify(jsondata_unicode) + else: + rpkg_data = None + print( + "Warning: dash-info.yaml missing; package metadata not loaded", + file=sys.stderr + ) + + with open('package.json', 'r') as f: + pkg_data = safe_json_loads(f.read()) + generate_exports( project_shortname, components, metadata, pkg_data, rpkg_data, - prefix, + rprefix, rdepends, rimports, rsuggests, ) +def safe_json_loads(s): + jsondata_unicode = json.loads(s, object_pairs_hook=OrderedDict) + if sys.version_info[0] >= 3: + return jsondata_unicode + return byteify(jsondata_unicode) + + def cli(): parser = argparse.ArgumentParser( prog="dash-generate-components", diff --git a/requires-ci.txt b/requires-ci.txt index 7533eca412..fec63ac1ee 100644 --- a/requires-ci.txt +++ b/requires-ci.txt @@ -3,7 +3,8 @@ dash-dangerously-set-inner-html six mock flake8 +PyYAML>=5.1.1 pylint==1.9.4;python_version<"3.7" pylint==2.3.1;python_version=="3.7" astroid==2.2.5;python_version=="3.7" -virtualenv;python_version=="2.7" \ No newline at end of file +virtualenv;python_version=="2.7" From 77d6580147a6bd9a3cfd350fb7f573e6729e01b5 Mon Sep 17 00:00:00 2001 From: byron Date: Tue, 2 Jul 2019 15:00:50 -0400 Subject: [PATCH 34/34] :arrow_down: lower pytest version until the proper fix in flask 1.0.3 is released --- requires-install.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requires-install.txt b/requires-install.txt index 3a9d71da36..0d073f583b 100644 --- a/requires-install.txt +++ b/requires-install.txt @@ -1,4 +1,4 @@ -Flask>=0.12 +Flask>=1.0.2 PyYAML>=5.1.1 flask-compress plotly @@ -8,7 +8,7 @@ dash-html-components==1.0.0 dash-table==4.0.0 # dash.testing -pytest +pytest<5.0.0 pytest-sugar pytest-mock lxml