Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
config = Config.get()
args = Arguments(sys.argv[1:]).parse()
if "usage" in args:
Arguments.print_usage(args["full"])
sys.exit(args["code"])
if args["code"] != 0:
sys.exit(args["code"])
processes = args["processes"]
targets = args["targets"]
no_tips = args["no-tips"]
# Detect paths, remove duplicates, and sort for deterministic results.
vprint("Detecting python files..")
paths = [abspath(p) for p in args["paths"]]
def parse(self):
if len(self.__args) == 0:
return {"code": 1, "usage": True, "full": False}
config = Config.get()
path_pos = 0
processes = cpu_count()
targets = []
hidden = False
versions = False
no_tips = False
for i in range(len(self.__args)):
arg = self.__args[i].lower()
if arg == "-h" or arg == "--help":
return {"code": 0, "usage": True, "full": True}
if arg == "--version":
print(VERSION)
exit(0)
if arg == "-q":
config.set_quiet(True)
path_pos += 1
def verbose_print(msg, level):
c = Config.get()
if c.verbose() >= level and not c.quiet():
print(msg)
def __init__(self, config=None):
super(SourceVisitor, self).__init__()
if config is None:
self.__config = Config.get()
else:
self.__config = config
self.__modules = []
self.__members = []
self.__printv2 = False
self.__printv3 = False
self.__format27 = False # If format is used so that it requires 2.7+, like '{}' etc.
self.__longv2 = False
self.__bytesv3 = False
self.__fstrings = False
self.__fstrings_self_doc = False
self.__bool_const = False
self.__annotations = False
self.__var_annotations = False
self.__coroutines = False
def nprint(msg):
if not Config.get().quiet():
print(msg)
def combine_versions(list1, list2):
assert len(list1) == len(list2)
assert len(list1) == 2
if not Config.get().ignore_incomp() and\
((list1[0] is None and list1[1] is not None and list2[0] is not None and list2[1] is None) or
(list1[0] is not None and list1[1] is None and list2[0] is None and list2[1] is not None)):
raise InvalidVersionException("Versions could not be combined: {} and {}".format(list1, list2))
res = []
# Convert integers and floats into version tuples.
def fixup(v):
if isinstance(v, int):
return (v, 0)
elif isinstance(v, float):
return float_version(v)
return v
for i in range(len(list1)):
v1 = fixup(list1[i])
v2 = fixup(list2[i])
def process(self, paths, processes=cpu_count()):
pool = Pool(processes=processes)
mins = [(0, 0), (0, 0)]
incomp = False
config = Config.get()
def print_incomp(path):
if not config.ignore_incomp():
nprint("File with incompatible versions: {}".format(path))
unique_versions = set()
all_backports = set()
for proc_res in pool.imap(process_individual, ((path, config) for path in paths)):
# Ignore paths that didn't contain python code.
if proc_res is None:
continue
if proc_res.mins is None:
incomp = True
print_incomp(proc_res.path)
continue
def __init__(self):
if not Config.__instance:
self.reset()
Config.__instance = self
def get():
if not Config.__instance:
Config()
return Config.__instance