MCPcopy Index your code
hub / github.com/plotly/dash / write_js_metadata

Function write_js_metadata

dash/development/_r_components_generation.py:488–539  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

486
487
488def 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

Callers 1

generate_rpkgFunction · 0.85

Calls 4

generate_js_metadataFunction · 0.85
walkMethod · 0.80
existsMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…