Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:return: Whether the .wily directory exists
:rtype: ``boolean``
"""
exists = (
pathlib.Path(config.cache_path).exists()
and pathlib.Path(config.cache_path).is_dir()
)
if not exists:
return False
index_path = pathlib.Path(config.cache_path) / "index.json"
if index_path.exists():
with open(index_path, "r") as out:
index = json.load(out)
if index["version"] != __version__:
# TODO: Inspect the versions properly.
logger.warning(
"Wily cache is old, you may incur errors until you rebuild the cache."
)
else:
logger.warning(
"Wily cache was not versioned, you may incur errors until you rebuild the cache."
)
create_index(config)
return True
pathlib.Path(config.cache_path).exists()
and pathlib.Path(config.cache_path).is_dir()
)
if not exists:
return False
index_path = pathlib.Path(config.cache_path) / "index.json"
if index_path.exists():
with open(index_path, "r") as out:
index = json.load(out)
if index["version"] != __version__:
# TODO: Inspect the versions properly.
logger.warning(
"Wily cache is old, you may incur errors until you rebuild the cache."
)
else:
logger.warning(
"Wily cache was not versioned, you may incur errors until you rebuild the cache."
)
create_index(config)
return True
Get the default metrics for a configuration.
:param config: The configuration
:type config: :class:`wily.config.WilyConfig`
:return: Return the list of default metrics in this index
:rtype: ``list`` of ``str``
"""
archivers = list_archivers(config)
default_metrics = []
for archiver in archivers:
index = get_archiver_index(config, archiver)
if len(index) == 0:
logger.warning("No records found in the index, no metrics available")
return []
operators = index[0]["operators"]
for operator in operators:
o = resolve_operator(operator)
if o.cls.default_metric_index is not None:
metric = o.cls.metrics[o.cls.default_metric_index]
default_metrics.append("{0}.{1}".format(o.cls.name, metric.name))
return default_metrics
for filename, details in dict(self.harvester.results).items():
results[filename] = {"detailed": {}, "total": {}}
total = 0 # running CC total
for instance in details:
if isinstance(instance, Class):
i = self._dict_from_class(instance)
elif isinstance(instance, Function):
i = self._dict_from_function(instance)
else:
if isinstance(instance, str) and instance == "error":
logger.debug(
f"Failed to run CC harvester on {filename} : {details['error']}"
)
continue
else:
logger.warning(
f"Unexpected result from Radon : {instance} of {type(instance)}. Please report on Github."
)
continue
results[filename]["detailed"][i["fullname"]] = i
del i["fullname"]
total += i["complexity"]
results[filename]["total"]["complexity"] = total
return results