MCPcopy
hub / github.com/bndr/pipreqs / init

Function init

pipreqs/pipreqs.py:434–519  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

432
433
434def init(args):
435 encoding = args.get('--encoding')
436 extra_ignore_dirs = args.get('--ignore')
437 follow_links = not args.get('--no-follow-links')
438 input_path = args['<path>']
439 if input_path is None:
440 input_path = os.path.abspath(os.curdir)
441
442 if extra_ignore_dirs:
443 extra_ignore_dirs = extra_ignore_dirs.split(',')
444
445 path = (args["--savepath"] if args["--savepath"] else
446 os.path.join(input_path, "requirements.txt"))
447 if (not args["--print"]
448 and not args["--savepath"]
449 and not args["--force"]
450 and os.path.exists(path)):
451 logging.warning("requirements.txt already exists, "
452 "use --force to overwrite it")
453 return
454
455 candidates = get_all_imports(input_path,
456 encoding=encoding,
457 extra_ignore_dirs=extra_ignore_dirs,
458 follow_links=follow_links)
459 candidates = get_pkg_names(candidates)
460 logging.debug("Found imports: " + ", ".join(candidates))
461 pypi_server = "https://pypi.python.org/pypi/"
462 proxy = None
463 if args["--pypi-server"]:
464 pypi_server = args["--pypi-server"]
465
466 if args["--proxy"]:
467 proxy = {'http': args["--proxy"], 'https': args["--proxy"]}
468
469 if args["--use-local"]:
470 logging.debug(
471 "Getting package information ONLY from local installation.")
472 imports = get_import_local(candidates, encoding=encoding)
473 else:
474 logging.debug("Getting packages information from Local/PyPI")
475 local = get_import_local(candidates, encoding=encoding)
476
477 # check if candidate name is found in
478 # the list of exported modules, installed locally
479 # and the package name is not in the list of local module names
480 # it add to difference
481 difference = [x for x in candidates if
482 # aggregate all export lists into one
483 # flatten the list
484 # check if candidate is in exports
485 x.lower() not in [y for x in local for y in x['exports']]
486 and
487 # check if candidate is package names
488 x.lower() not in [x['name'] for x in local]]
489
490 imports = local + get_imports_info(difference,
491 proxy=proxy,

Callers 1

mainFunction · 0.85

Calls 9

get_all_importsFunction · 0.85
get_pkg_namesFunction · 0.85
get_import_localFunction · 0.85
get_imports_infoFunction · 0.85
diffFunction · 0.85
cleanFunction · 0.85
dynamic_versioningFunction · 0.85
output_requirementsFunction · 0.85

Tested by

no test coverage detected