Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# * a directory called .prospector in the check path
# * the check path
# * prospector provided profiles
profile_path = config.profile_path
prospector_dir = os.path.join(path, '.prospector')
if os.path.exists(prospector_dir) and os.path.isdir(prospector_dir):
profile_path.append(prospector_dir)
profile_path.append(path)
profile_path.append(BUILTIN_PROFILE_PATH)
try:
forced_inherits = cmdline_implicit + extra_profiles
profile = ProspectorProfile.load(profile_name, profile_path, forced_inherits=forced_inherits)
except CannotParseProfile as cpe:
sys.stderr.write("Failed to run:\nCould not parse profile %s as it is not valid YAML\n%s\n" %
(cpe.filepath, cpe.get_parse_message()))
sys.exit(1)
except ProfileNotFound as nfe:
sys.stderr.write("Failed to run:\nCould not find profile %s. Search path: %s\n" %
(nfe.name, ':'.join(nfe.profile_path)))
sys.exit(1)
else:
return profile, strictness
else:
for path in profile_path:
for ext in ('yml', 'yaml'):
filepath = os.path.join(path, '%s.%s' % (name_or_path, ext))
if os.path.exists(filepath):
filename = filepath
break
if filename is None:
raise ProfileNotFound(name_or_path, profile_path)
with open(filename) as fct:
try:
return yaml.safe_load(fct) or {}
except yaml.parser.ParserError as parse_error:
raise CannotParseProfile(filename, parse_error)
def __init__(self, filepath, parse_error):
super(CannotParseProfile, self).__init__()
self.filepath = filepath
self.parse_error = parse_error