MCPcopy
hub / github.com/plotly/dash / make_namespace_exports

Function make_namespace_exports

dash/development/_r_components_generation.py:788–848  ·  view source on GitHub ↗
(components, prefix)

Source from the content-addressed store, hash-verified

786
787
788def make_namespace_exports(components, prefix):
789 export_string = ""
790 for component in components:
791 if (
792 not component.endswith("-*")
793 and str(component) not in r_keywords
794 and str(component) not in ["setProps", "children"]
795 ):
796 export_string += "export({}{})\n".format(prefix, component)
797
798 # the following lines enable rudimentary support for bundling in
799 # R functions that are not automatically generated by the transpiler
800 # such that functions contained in the R subdirectory are exported,
801 # so long as they are not in utils.R.
802 rfilelist = []
803 omitlist = ["utils.R", "internal.R"] + [
804 "{}{}.R".format(prefix, component) for component in components
805 ]
806 fnlist = []
807
808 for script in os.listdir("R"):
809 if script.endswith(".R") and script not in omitlist:
810 rfilelist += [os.path.join("R", script)]
811
812 for rfile in rfilelist:
813 with open(rfile, "r", encoding="utf-8") as script:
814 s = script.read()
815
816 # remove comments
817 s = re.sub("#.*$", "", s, flags=re.M)
818
819 # put the whole file on one line
820 s = s.replace("\n", " ").replace("\r", " ")
821
822 # empty out strings, in case of unmatched block terminators
823 s = re.sub(r"'([^'\\]|\\'|\\[^'])*'", "''", s)
824 s = re.sub(r'"([^"\\]|\\"|\\[^"])*"', '""', s)
825
826 # empty out block terminators () and {}
827 # so we don't catch nested functions, or functions as arguments
828 # repeat until it stops changing, in case of multiply nested blocks
829 prev_len = len(s) + 1
830 while len(s) < prev_len:
831 prev_len = len(s)
832 s = re.sub(r"\(([^()]|\(\))*\)", "()", s)
833 s = re.sub(r"\{([^{}]|\{\})*\}", "{}", s)
834
835 # now, in whatever is left, look for functions
836 matches = re.findall(
837 # in R, either = or <- may be used to create and assign objects
838 r"([^A-Za-z0-9._]|^)([A-Za-z0-9._]+)\s*(=|<-)\s*function",
839 s,
840 )
841 for match in matches:
842 fn = match[1]
843 # Allow users to mark functions as private by prefixing with .
844 if fn[0] != "." and fn not in fnlist:
845 fnlist.append(fn)

Callers 2

test_r_exportsFunction · 0.90
generate_exportsFunction · 0.85

Calls 3

subMethod · 0.80
formatMethod · 0.45
appendMethod · 0.45

Tested by 1

test_r_exportsFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…