Write an internal (not exported) R function to return all JS dependencies as required by dash. Parameters ---------- project_shortname = hyphenated string, e.g. dash-html-components Returns -------
(pkg_data, project_shortname, has_wildcards)
| 486 | |
| 487 | |
| 488 | def write_js_metadata(pkg_data, project_shortname, has_wildcards): |
| 489 | """Write an internal (not exported) R function to return all JS |
| 490 | dependencies as required by dash. |
| 491 | |
| 492 | Parameters |
| 493 | ---------- |
| 494 | project_shortname = hyphenated string, e.g. dash-html-components |
| 495 | |
| 496 | Returns |
| 497 | ------- |
| 498 | """ |
| 499 | function_string = generate_js_metadata( |
| 500 | pkg_data=pkg_data, project_shortname=project_shortname |
| 501 | ) |
| 502 | file_name = "internal.R" |
| 503 | |
| 504 | # the R source directory for the package won't exist on first call |
| 505 | # create the R directory if it is missing |
| 506 | if not os.path.exists("R"): |
| 507 | os.makedirs("R") |
| 508 | |
| 509 | file_path = os.path.join("R", file_name) |
| 510 | with open(file_path, "w", encoding="utf-8") as f: |
| 511 | f.write(function_string) |
| 512 | if has_wildcards: |
| 513 | f.write(wildcard_helper) |
| 514 | |
| 515 | # now copy over all JS dependencies from the (Python) components dir |
| 516 | # the inst/lib directory for the package won't exist on first call |
| 517 | # create this directory if it is missing |
| 518 | if os.path.exists("inst/deps"): |
| 519 | shutil.rmtree("inst/deps") |
| 520 | |
| 521 | os.makedirs("inst/deps") |
| 522 | |
| 523 | for rel_dirname, _, filenames in os.walk(project_shortname): |
| 524 | for filename in filenames: |
| 525 | extension = os.path.splitext(filename)[1] |
| 526 | |
| 527 | if extension in [".py", ".pyc", ".json"]: |
| 528 | continue |
| 529 | |
| 530 | target_dirname = os.path.join( |
| 531 | os.path.join( |
| 532 | "inst/deps/", os.path.relpath(rel_dirname, project_shortname) |
| 533 | ) |
| 534 | ) |
| 535 | |
| 536 | if not os.path.exists(target_dirname): |
| 537 | os.makedirs(target_dirname) |
| 538 | |
| 539 | shutil.copy(os.path.join(rel_dirname, filename), target_dirname) |
| 540 | |
| 541 | |
| 542 | # pylint: disable=R0914, R0913, R0912, R0915 |
no test coverage detected
searching dependent graphs…