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

Function generate_js_metadata

dash/development/_r_components_generation.py:245–338  ·  view source on GitHub ↗

Dynamically generate R function to supply JavaScript and CSS dependency information required by the dash package for R. Parameters ---------- project_shortname = component library name, in snake case Returns ------- function_string = complete R function code to provide

(pkg_data, project_shortname)

Source from the content-addressed store, hash-verified

243
244# pylint: disable=R0914
245def generate_js_metadata(pkg_data, project_shortname):
246 """Dynamically generate R function to supply JavaScript and CSS dependency
247 information required by the dash package for R.
248
249 Parameters
250 ----------
251 project_shortname = component library name, in snake case
252
253 Returns
254 -------
255 function_string = complete R function code to provide component features
256 """
257 # make sure the module we're building is available to Python,
258 # even if it hasn't been installed yet
259 sys.path.insert(0, os.getcwd())
260 mod = importlib.import_module(project_shortname)
261
262 alldist = getattr(mod, "_js_dist", []) + getattr(mod, "_css_dist", [])
263
264 project_ver = pkg_data.get("version")
265
266 rpkgname = snake_case_to_camel_case(project_shortname)
267
268 # since _js_dist may suggest more than one dependency, need
269 # a way to iterate over all dependencies for a given set.
270 # here we define an opening, element, and closing string --
271 # if the total number of dependencies > 1, we can concatenate
272 # them and write a list object in R with multiple elements
273 function_frame_open = frame_open_template.format(rpkgname=rpkgname)
274
275 function_frame = []
276 function_frame_body = []
277
278 # pylint: disable=consider-using-enumerate
279 if len(alldist) > 1:
280 for dep in range(len(alldist)):
281 curr_dep = alldist[dep]
282 rpp = curr_dep.get("relative_package_path", "")
283 if not rpp:
284 continue
285
286 async_or_dynamic = get_async_type(curr_dep)
287
288 if "dash_" in rpp:
289 dep_name = rpp.split(".")[0]
290 else:
291 dep_name = "{}".format(project_shortname)
292
293 if "css" in rpp:
294 css_name = "'{}'".format(rpp)
295 script_name = "NULL"
296 else:
297 script_name = "'{}'".format(rpp)
298 css_name = "NULL"
299
300 function_frame += [
301 frame_element_template.format(
302 dep_name=dep_name,

Callers 1

write_js_metadataFunction · 0.85

Calls 5

snake_case_to_camel_caseFunction · 0.85
get_async_typeFunction · 0.85
insertMethod · 0.45
getMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…