def main(argv: Optional[Sequence[str]] = None) -> int: parser = argparse.ArgumentParser() autofix_lib.add_fixer_args(parser) args = parser.parse_args(argv) autofix_lib.assert_importable('pre_commit', install='pre-commit') # pre-commit 1.0.0: introduces migrate-config # pre-commit 1.0.1: exit code fix # pre-commit 1.7.0: sha -> rev autofix_lib.require_version_gte('pre-commit', '1.7.0') repos, config, commit, autofix_settings = autofix_lib.from_cli( args, find_repos=find_repos, msg='Ran pre-commit migrate-config.', branch_name='pre-commit-migrate-config', ) with tmp_pre_commit_home(): autofix_lib.fix( repos, apply_fix=apply_fix, check_fix=check_fix, config=config, commit=commit, autofix_settings=autofix_settings, ) return 0
def main(argv: Optional[Sequence[str]] = None) -> int: parser = argparse.ArgumentParser() autofix_lib.add_fixer_args(parser) args = parser.parse_args(argv) autofix_lib.assert_importable('pre_commit', install='pre-commit') autofix_lib.require_version_gte('pre-commit', '1.7.0') repos, config, commit, autofix_settings = autofix_lib.from_cli( args, find_repos=find_repos, msg='Migrate to official pycqa/flake8 hooks repo', branch_name='pre-commit-flake8-migrate', ) with tmp_pre_commit_home(): autofix_lib.fix( repos, apply_fix=apply_fix, check_fix=check_fix, config=config, commit=commit, autofix_settings=autofix_settings, ) return 0
def main(argv: Sequence[str] | None = None) -> int: parser = argparse.ArgumentParser() autofix_lib.add_fixer_args(parser) args = parser.parse_args(argv) autofix_lib.assert_importable('pre_commit', install='pre-commit') autofix_lib.require_version_gte('pre-commit', '1.7.0') repos, config, commit, autofix_settings = autofix_lib.from_cli( args, find_repos=find_repos, msg='Migrate from autopep8-wrapper to mirrors-autopep8', branch_name='pre-commit-autopep8-migrate', ) with tmp_pre_commit_home(): autofix_lib.fix( repos, apply_fix=apply_fix, check_fix=check_fix, config=config, commit=commit, autofix_settings=autofix_settings, ) return 0
def test_tmp_pre_commit_home_existing_env_variable(): with mock.patch.dict(os.environ, {'PRE_COMMIT_HOME': '/'}, clear=True): with tmp_pre_commit_home(): tmp_home = os.environ['PRE_COMMIT_HOME'] assert tmp_home != '/' assert os.path.exists(tmp_home) assert os.environ['PRE_COMMIT_HOME'] == '/' assert not os.path.exists(tmp_home)
def test_tmp_pre_commit_home_no_env_variable(): with mock.patch.dict(os.environ, clear=True): with tmp_pre_commit_home(): assert os.path.exists(os.environ['PRE_COMMIT_HOME']) assert 'PRE_COMMIT_HOME' not in os.environ