Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def error(self, *args, **kwargs):
logger.error(*args, **kwargs)
raise _SessionQuit()
def which(program, path):
"""Finds the full path to an executable."""
full_path = None
if path:
full_path = py.path.local.sysfind(program, paths=[path])
if full_path:
return full_path.strpath
full_path = py.path.local.sysfind(program)
if full_path:
return full_path.strpath
logger.error("Program {} not found.".format(program))
raise CommandFailed("Program {} not found".format(program))
path = path.decode("utf-8")
path = unicodedata.normalize("NFKD", path).encode("ascii", "ignore")
path = path.decode("ascii")
path = re.sub(r"[^\w\s-]", "-", path).strip().lower()
path = re.sub(r"[-\s]+", "-", path)
path = path.strip("-")
full_path = os.path.join(envdir, path)
if len(full_path) > 100 - len("bin/pythonX.Y"):
if len(envdir) < 100 - 9:
path = hashlib.sha1(path.encode("ascii")).hexdigest()[:8]
full_path = os.path.join(envdir, path)
logger.warning("The virtualenv name was hashed to avoid being too long.")
else:
logger.error(
"The virtualenv path {} is too long and will cause issues on "
"some environments. Use the --envdir path to modify where "
"nox stores virtualenvs.".format(full_path)
)
return full_path
path = unicodedata.normalize('NFKD', path).encode('ascii', 'ignore')
path = path.decode('ascii')
path = re.sub('[^\w\s-]', '-', path).strip().lower()
path = re.sub('[-\s]+', '-', path)
path = path.strip('-')
full_path = os.path.join(envdir, path)
if len(full_path) > 100 - len('bin/pythonX.Y'):
if len(envdir) < 100 - 9:
path = hashlib.sha1(path.encode('ascii')).hexdigest()[:8]
full_path = os.path.join(envdir, path)
logger.warning(
'The virtualenv name was hashed to avoid being too long.')
else:
logger.error(
'The virtualenv path {} is too long and will cause issues on '
'some environments. Use the --envdir path to modify where '
'nox stores virtualenvs.'.format(full_path))
return full_path
if success_codes is None:
success_codes = [0]
cmd, args = args[0], args[1:]
full_cmd = "{} {}".format(cmd, " ".join(args))
cmd_path = which(cmd, path)
if log:
logger.info(full_cmd)
is_external_tool = path is not None and not cmd_path.startswith(path)
if is_external_tool:
if external == "error":
logger.error(
"Error: {} is not installed into the virtualenv, it is located at {}. "
"Pass external=True into run() to explicitly allow this.".format(
cmd, cmd_path
)
)
raise CommandFailed("External program disallowed.")
elif external is False:
logger.warning(
"Warning: {} is not installed into the virtualenv, it is located at {}. This might cause issues! "
"Pass external=True into run() to silence this message.".format(
cmd, cmd_path
)
)
env = _clean_env(env)
full_cmd, return_code, ":" if silent else ""
)
)
if silent:
sys.stderr.write(output)
raise CommandFailed("Returned code {}".format(return_code))
if output:
logger.output(output)
return output if silent else True
except KeyboardInterrupt:
logger.error("Interrupted...")
raise
manifest (~.Manifest): The manifest of sessions to be run.
global_config (~nox.main.GlobalConfig): The global configuration.
Returns:
Union[~.Manifest,int]: ``3`` if a specified session is not found,
the manifest otherwise (to be sent to the next task).
"""
# Filter by the name of any explicit sessions.
# This can raise KeyError if a specified session does not exist;
# log this if it happens.
if global_config.sessions:
try:
manifest.filter_by_name(global_config.sessions)
except KeyError as exc:
logger.error("Error while collecting sessions.")
logger.error(exc.args[0])
return 3
# Filter by keywords.
# This function never errors, but may cause an empty list of sessions
# (which is an error condition later).
if global_config.keywords:
manifest.filter_by_keywords(global_config.keywords)
# Return the modified manifest.
return manifest