-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Provide string interpolation support for async/dynamic dep attributes in R #1048
Merged
Merged
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f32833c
:sparkles: async/dynamic support in R pkg deps
a40e246
:hocho: commented out line
c332a09
:see_no_evil: fix case errors and parens
eb18503
:see_no_evil: move async/dynamic to correct pos
744db9c
:sparkles: async/dynamic support in R pkg deps
1ca04e4
Merge branch '1042-async-rsupport' of github.com:plotly/dash into 104…
7643ecc
Merge branch 'dev' into 1042-async-rsupport
rpkyle 85a82ac
:necktie: satisfy linting overlords
ede3df4
Merge branch '1042-async-rsupport' of github.com:plotly/dash into 104…
269a1fa
:hocho: remove Authors block
2221282
:hocho: insert package version number
814022d
:hammer: use verbose :package: title and desc from YAML
54103c7
:sparkles: autodetect vignettes
a615eb2
fix package suggests autodefine
5a46be2
:see_no_evil: remove pdb
cc87f2e
:bug: specify title/desc if no yaml
3ff7607
:hocho: blank line if no VB, use get_async_type
f2171a7
check for author/maintainer address
03e7359
:hand: halt processing if fatal errors found
f53f7dc
autopopulate KeepSource
52a3394
remove error, auto-escape %
cb061bd
must auto-escape % in description too
1d5a112
:hocho: package-lock.json
45885a2
Merge branch 'dev' into 1042-async-rsupport
rpkyle b471d35
:hocho: remove examples from docstrings in R
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,14 +46,14 @@ | |
file = "deps"), meta = NULL, | ||
script = {script_name}, | ||
stylesheet = {css_name}, head = NULL, attachment = NULL, package = "{rpkgname}", | ||
all_files = FALSE), class = "html_dependency")""" # noqa:E501 | ||
all_files = FALSE{async_or_dynamic}), class = "html_dependency")""" # noqa:E501 | ||
|
||
frame_body_template = """`{project_shortname}` = structure(list(name = "{project_shortname}", | ||
version = "{project_ver}", src = list(href = NULL, | ||
file = "deps"), meta = NULL, | ||
script = {script_name}, | ||
stylesheet = {css_name}, head = NULL, attachment = NULL, package = "{rpkgname}", | ||
all_files = FALSE), class = "html_dependency")""" # noqa:E501 | ||
all_files = FALSE{async_or_dynamic}), class = "html_dependency")""" # noqa:E501 | ||
|
||
frame_close_template = """) | ||
return(deps_metadata) | ||
|
@@ -81,9 +81,8 @@ | |
""" | ||
|
||
description_template = """Package: {package_name} | ||
Title: {package_description} | ||
Title: {package_title} | ||
Version: {package_version} | ||
Authors @R: as.person(c({package_author})) | ||
Description: {package_description} | ||
Depends: R (>= 3.0.2){package_depends} | ||
Imports: {package_imports} | ||
|
@@ -93,6 +92,7 @@ | |
BugReports: {package_issues} | ||
Encoding: UTF-8 | ||
LazyData: true | ||
{vignette_builder} | ||
Author: {package_author_no_email} | ||
Maintainer: {maintainer} | ||
""" | ||
|
@@ -276,18 +276,23 @@ def generate_js_metadata(pkg_data, project_shortname): | |
# pylint: disable=consider-using-enumerate | ||
if len(alldist) > 1: | ||
for dep in range(len(alldist)): | ||
rpp = alldist[dep]["relative_package_path"] | ||
curr_dep = alldist[dep] | ||
rpp = curr_dep["relative_package_path"] | ||
|
||
async_or_dynamic = check_async_type(curr_dep) | ||
|
||
if "dash_" in rpp: | ||
dep_name = rpp.split(".")[0] | ||
else: | ||
dep_name = "{}".format(project_shortname) | ||
project_ver = str(dep) | ||
|
||
if "css" in rpp: | ||
css_name = "'{}'".format(rpp) | ||
script_name = 'NULL' | ||
else: | ||
script_name = "'{}'".format(rpp) | ||
css_name = 'NULL' | ||
|
||
function_frame += [ | ||
frame_element_template.format( | ||
dep_name=dep_name, | ||
|
@@ -296,23 +301,30 @@ def generate_js_metadata(pkg_data, project_shortname): | |
project_shortname=project_shortname, | ||
script_name=script_name, | ||
css_name=css_name, | ||
async_or_dynamic=async_or_dynamic, | ||
) | ||
] | ||
function_frame_body = ",\n".join(function_frame) | ||
elif len(alldist) == 1: | ||
rpp = alldist[0]["relative_package_path"] | ||
dep = alldist[0] | ||
rpp = dep["relative_package_path"] | ||
|
||
async_or_dynamic = check_async_type(dep) | ||
|
||
if "css" in rpp: | ||
css_name = "'{}'".format(rpp) | ||
script_name = "NULL" | ||
else: | ||
script_name = "'{}'".format(rpp) | ||
css_name = "NULL" | ||
|
||
function_frame_body = frame_body_template.format( | ||
project_shortname=project_shortname, | ||
project_ver=project_ver, | ||
rpkgname=rpkgname, | ||
script_name=script_name, | ||
css_name=css_name, | ||
async_or_dynamic=async_or_dynamic, | ||
) | ||
|
||
function_string = "".join( | ||
|
@@ -322,6 +334,24 @@ def generate_js_metadata(pkg_data, project_shortname): | |
return function_string | ||
|
||
|
||
# determine whether dependency uses async or dynamic flag | ||
# then return the properly formatted string if so, i.e. | ||
# " async = TRUE,". a dependency can have async or | ||
# dynamic elements, neither of these, but never both. | ||
def check_async_type(dep): | ||
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. Would suggest renaming to 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. fixed in 3ff7607 |
||
async_or_dynamic = "" | ||
for key in dep.keys(): | ||
if (key in ['async', 'dynamic']): | ||
keyval = dep[key] | ||
if not isinstance(keyval, bool): | ||
keyval = "'{}'".format(keyval.lower()) | ||
else: | ||
keyval = str(keyval).upper() | ||
async_or_dynamic = \ | ||
", {} = {}".format(key, keyval) | ||
return async_or_dynamic | ||
|
||
|
||
# This method wraps code within arbitrary LaTeX-like tags, which are used | ||
# by R's internal help parser for constructing man pages | ||
def wrap(tag, code): | ||
|
@@ -509,7 +539,17 @@ def generate_rpkg( | |
|
||
package_name = snake_case_to_camel_case(project_shortname) | ||
lib_name = pkg_data.get("name") | ||
package_description = pkg_data.get("description", "") | ||
|
||
if rpkg_data is not None: | ||
if rpkg_data.get("pkg_help_title"): | ||
package_title = rpkg_data.get("pkg_help_title", | ||
pkg_data.get("description", | ||
"")) | ||
Marc-Andre-Rivet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if rpkg_data.get("pkg_help_description"): | ||
package_description = rpkg_data.get("pkg_help_description", | ||
pkg_data.get("description", | ||
"")) | ||
|
||
package_version = pkg_data.get("version", "0.0.1") | ||
|
||
# remove leading and trailing commas | ||
|
@@ -565,6 +605,13 @@ def generate_rpkg( | |
for rpackage in rpackage_list: | ||
packages_string += "\nimport({})\n".format(rpackage) | ||
|
||
if os.path.exists("vignettes"): | ||
vignette_builder = "VignetteBuilder: knitr" | ||
if not "knitr" and "rmarkdown" in package_suggests: | ||
package_suggests += ", knitr, rmarkdown".lstrip(", ") | ||
else: | ||
vignette_builder = "" | ||
|
||
pkghelp_stub_path = os.path.join("man", package_name + "-package.Rd") | ||
|
||
# generate the internal (not exported to the user) functions which | ||
|
@@ -582,6 +629,7 @@ def generate_rpkg( | |
|
||
description_string = description_template.format( | ||
package_name=package_name, | ||
package_title=package_title, | ||
package_description=package_description, | ||
package_version=package_version, | ||
package_author=package_author, | ||
|
@@ -591,6 +639,7 @@ def generate_rpkg( | |
package_license=package_license, | ||
package_url=package_url, | ||
package_issues=package_issues, | ||
vignette_builder=vignette_builder, | ||
package_author_no_email=package_author_no_email, | ||
maintainer=maintainer, | ||
) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not part of this change, but I'm having trouble understanding why we process an array of length one differently from an array of length N
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.
The code doesn't really make much sense as written, but that's because I had trouble getting it to work with
enumerate
when I wrote it a year ago. I had only been programming in Python for a week or two, so this code is pretty much a giant pile of 💩. It needs some love and refactoring, no disagreement there.