Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def to_set(self, values):
if isinstance(values, str):
values = [v.strip() for v in values.split(",")]
values = list(map(self._option._in, lbuild.utils.listify(values)))
return values
def find_any(self, queries, types=None):
nodes = set()
for query in utils.listify(queries):
result = self._resolve_partial(query, None)
if result is None:
raise le.LbuildParserNodeNotFoundException(self, query, types)
nodes |= set(result)
if types:
types = utils.listify(types)
nodes = [n for n in nodes if any(n.type == t for t in types)]
return list(nodes)
def collector_values(self, key, default=None, filterfunc=None, unique=True):
if default is None:
collector = self.collectors[key]
else:
collector = self.collectors.get(key)
if collector is not None:
return collector.values(default, filterfunc, unique)
else:
return lbuild.utils.listify(default)
def load_functions_from_file(repository, filename: str, required, optional=None, local=None):
filename = os.path.realpath(filename)
localpath = os.path.dirname(filename)
if not os.path.isfile(filename):
raise FileNotFoundError(filename)
if local is None:
local = {}
local.update({
'localpath': RelocatePath(localpath),
'repopath': RelocatePath(repository._filepath),
'listify': lu.listify,
'listrify': lu.listrify,
'uniquify': lu.uniquify,
'FileReader': LocalFileReaderFactory(localpath),
'ValidateException': le.LbuildValidateException,
'Module': lbuild.module.ModuleBase,
'Query': lbuild.query.Query,
'EnvironmentQuery': lbuild.query.EnvironmentQuery,
'StringCollector': lbuild.collector.StringCollector,
'PathCollector': lbuild.collector.PathCollector,
'BooleanCollector': lbuild.collector.BooleanCollector,
'NumericCollector': lbuild.collector.NumericCollector,
'EnumerationCollector': lbuild.collector.EnumerationCollector,
'CallableCollector': lbuild.collector.CallableCollector,
self._dependencies = []
self._build_order = 0
self._description = ""
# All _update()-able traits: defaults
self._available_default = True
self._selected_default = True
self._format_description_default = lbuild.format.format_description
self._format_short_description_default = lbuild.format.format_short_description
# All _update()-able traits: defaults
self._available = (self._type != BaseNode.Type.MODULE)
self._selected = True
self._format_description = self._format_description_default
self._format_short_description = self._format_short_description_default
self._ignore_patterns = lbuild.utils.DEFAULT_IGNORE_PATTERNS
self._filters = lbuild.filter.DEFAULT_FILTERS
def validate(path, empty_ok=False):
if empty_ok and len(path) == 0:
return True
if not lbuild.utils.is_pathname_valid(path):
return False
return True
def values(self, default=None, filterfunc=None, unique=True):
if filterfunc is None:
values = [v for vs in self._values.values() for v in vs]
else:
values = []
for context, vals in self._values.items():
if filterfunc(context):
values.extend(vals)
if unique:
values = list(OrderedDict.fromkeys(values))
if default is not None and not values:
values = lbuild.utils.listify(default)
return values
def load_repositories(self, repofilenames=None):
repofiles = set(os.path.realpath(p) for p in utils.listify(repofilenames))
parsed = set()
while True:
# flatten configuration and collect repositories
self._config_flat = self._config.flatten()
repofiles = (repofiles | set(self._config_flat.repositories)) - parsed
if not len(repofiles) + len(parsed):
raise le.LbuildConfigNoReposException(self)
parsed |= repofiles
# Parse only new repositories
for repofile in repofiles:
repo = self.parse_repository(repofile)
# nothing more to extend
if not self._config_flat._extends:
def wrap_ignore(path, files):
ignored = lbuild.utils.ignore_patterns(*self.__module._ignore_patterns)(path, files)
ignored.add(self.__module._filename)
if ignore:
ignored |= set(ignore(path, files))
return ignored