def check(args): if not Path("Pipfile").exists(): fatal_error("Pipfile not found") if not Path("setup.py").exists(): fatal_error("setup.py not found") if args.lockfile: local_packages, remote_packages = lockfile_parser.get_default_packages( Path("Pipfile.lock")) else: local_packages, remote_packages = pipfile_parser.get_default_packages( Path("Pipfile")) if local_packages and not args.ignore_local: package_names = ", ".join(local_packages) fatal_error( "local package found in default dependency: %s.\nDo you mean to make it dev dependency " % package_names) with open("setup.py") as setup_file: setup_code = setup_file.read() try: ( install_requires, dependency_links, ) = setup_parser.get_install_requires_dependency_links(setup_code) except (ValueError, SyntaxError) as e: fatal_error(str(e)) # fatal_error is a NoReturn function, pycharm gets confused # noinspection PyUnboundLocalVariable checker = InconsistencyChecker(install_requires, dependency_links, remote_packages, args.strict) reports = [] checks = ( checker.check_install_requires_conflict, checker.check_dependency_links_conflict, checker.check_lacking_install_requires, checker.check_lacking_dependency_links, ) for check_item in checks: try: reports += check_item() except ValueError as e: print(e, file=stderr) fatal_error("dependency check failed") if len(reports) == 0: congratulate(msg_formatter.checked_no_problem()) else: fatal_error(reports)
def test_check_file_strict( capsys, tmp_path, shared_datadir, source_pipfile_dirname ): # type: (Any, Path, Path, str) -> None """ when --strict flag is passed. compatible but not identical versioning should fail """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) with cwd(tmp_path): with pytest.raises(SystemExit) as e: cmd(argv=["", "check", "--strict"]) assert e.value.code == 1 cmd(argv=["", "check"]) captured = capsys.readouterr() assert msg_formatter.checked_no_problem() in captured.out
def test_check_file_ignore_local( capsys, tmp_path, shared_datadir, source_pipfile_dirname ): # type: (Any, Path, Path, str) -> None """ when Pipfile.lock is missing, return code should be one """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py") with cwd(tmp_path): with pytest.raises(SystemExit) as e: cmd(argv=["", "check"]) assert e.value.code == 1 cmd(argv=["", "check", "--ignore-local"]) captured = capsys.readouterr() assert msg_formatter.checked_no_problem() in captured.out