Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bad_resolve_archiver():
with pytest.raises(ValueError):
wily.archivers.resolve_archiver("baz")
def test_resolve_archiver():
archiver = wily.archivers.resolve_archiver("git")
assert archiver == wily.archivers.ARCHIVER_GIT
assert archiver.name == "git"
if config.path != DEFAULT_PATH:
targets = [str(Path(config.path) / Path(file)) for file in files]
else:
targets = files
# Expand directories to paths
files = [
os.path.relpath(fn, config.path)
for fn in radon.cli.harvest.iter_filenames(targets)
]
logger.debug(f"Targeting - {files}")
if not revision:
target_revision = state.index[state.default_archiver].last_revision
else:
rev = resolve_archiver(state.default_archiver).cls(config).find(revision)
logger.debug(f"Resolved {revision} to {rev.key} ({rev.message})")
try:
target_revision = state.index[state.default_archiver][rev.key]
except KeyError:
logger.error(
f"Revision {revision} is not in the cache, make sure you have run wily build."
)
exit(1)
logger.info(
f"Comparing current with {format_revision(target_revision.revision.key)} by {target_revision.revision.author_name} on {format_date(target_revision.revision.date)}."
)
# Convert the list of metrics to a list of metric instances
operators = {resolve_operator(metric.split(".")[0]) for metric in metrics}
metrics = [(metric.split(".")[0], resolve_metric(metric)) for metric in metrics]
:return: Sorted table of all files in path, sorted in order of metric.
"""
logger.debug("Running rank command")
data = []
operator, metric = resolve_metric_as_tuple(metric)
operator = operator.name
state = State(config)
if not revision_index:
target_revision = state.index[state.default_archiver].last_revision
else:
rev = resolve_archiver(state.default_archiver).cls(config).find(revision_index)
logger.debug(f"Resolved {revision_index} to {rev.key} ({rev.message})")
try:
target_revision = state.index[state.default_archiver][rev.key]
except KeyError:
logger.error(
f"Revision {revision_index} is not in the cache, make sure you have run wily build."
)
exit(1)
logger.info(
f"-----------Rank for {metric.description} for {format_revision(target_revision.revision.key)} by {target_revision.revision.author_name} on {format_date(target_revision.revision.date)}.------------"
)
if path is None:
files = target_revision.get_paths(config, state.default_archiver, operator)
logger.debug(f"Analysing {files}")
if operators:
logger.debug(f"Fixing operators to {operators}")
config.operators = operators.strip().split(",")
if archiver:
logger.debug(f"Fixing archiver to {archiver}")
config.archiver = archiver
if targets:
logger.debug(f"Fixing targets to {targets}")
config.targets = targets
build(
config=config,
archiver=resolve_archiver(config.archiver),
operators=resolve_operators(config.operators),
)
logger.info(
"Completed building wily history, run `wily report ` or `wily index` to see more."
)
:param config: The wily configuration.
:type config: :class:`WilyConfig`
:param archiver: The archiver (optional).
:type archiver: :class:`wily.archivers.Archiver`
"""
if archiver:
self.archivers = [archiver.name]
else:
self.archivers = cache.list_archivers(config)
logger.debug(f"Initialised state indexes for archivers {self.archivers}")
self.config = config
self.index = {}
for archiver in self.archivers:
self.index[archiver] = Index(self.config, resolve_archiver(archiver))
self.default_archiver = self.archivers[0]