MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / collect_shell_variables

Function collect_shell_variables

src/packagedcode/bashparse.py:82–102  ·  view source on GitHub ↗

Return a tuple of (``shell variables``, ``errors``) from collecting top- level variables defined in bash script at ``location``. ``shell variables`` is a mapping of {name: value} ``errors`` a list of error message strings. Optionally ``resolve`` the variables with emulated she

(location, resolve=False, needed_variables=None)

Source from the content-addressed store, hash-verified

80
81
82def collect_shell_variables(location, resolve=False, needed_variables=None):
83 """
84 Return a tuple of (``shell variables``, ``errors``) from collecting top-
85 level variables defined in bash script at ``location``.
86
87 ``shell variables`` is a mapping of {name: value}
88 ``errors`` a list of error message strings.
89
90 Optionally ``resolve`` the variables with emulated shell parameter
91 expansion. If the set ``needed_variables`` is provided, only return
92 variables with a named present in this set and only report errors for
93 variables with a name listed in this set.
94 """
95 with open(location) as inp:
96 text = inp.read()
97
98 return collect_shell_variables_from_text_as_dict(
99 text=text,
100 resolve=resolve,
101 needed_variables=needed_variables,
102 )
103
104#
105# Convenience functions on parse tree labels

Callers 1

bashparse.pyFile · 0.85

Calls 2

readMethod · 0.45

Tested by

no test coverage detected