mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-14 17:41:45 +04:00
Merge pull request #3093 from pre-commit/removeprefix
python 3.9+: use removeprefix
This commit is contained in:
commit
7dc0a59ee5
4 changed files with 10 additions and 8 deletions
|
|
@ -65,7 +65,7 @@ def _find_by_py_launcher(
|
||||||
version: str,
|
version: str,
|
||||||
) -> str | None: # pragma: no cover (windows only)
|
) -> str | None: # pragma: no cover (windows only)
|
||||||
if version.startswith('python'):
|
if version.startswith('python'):
|
||||||
num = version[len('python'):]
|
num = version.removeprefix('python')
|
||||||
cmd = ('py', f'-{num}', '-c', 'import sys; print(sys.executable)')
|
cmd = ('py', f'-{num}', '-c', 'import sys; print(sys.executable)')
|
||||||
env = dict(os.environ, PYTHONIOENCODING='UTF-8')
|
env = dict(os.environ, PYTHONIOENCODING='UTF-8')
|
||||||
try:
|
try:
|
||||||
|
|
@ -124,7 +124,7 @@ def _sys_executable_matches(version: str) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
info = tuple(int(p) for p in version[len('python'):].split('.'))
|
info = tuple(int(p) for p in version.removeprefix('python').split('.'))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ def install_environment(
|
||||||
|
|
||||||
packages_to_install: set[tuple[str, ...]] = {('--path', '.')}
|
packages_to_install: set[tuple[str, ...]] = {('--path', '.')}
|
||||||
for cli_dep in cli_deps:
|
for cli_dep in cli_deps:
|
||||||
cli_dep = cli_dep[len('cli:'):]
|
cli_dep = cli_dep.removeprefix('cli:')
|
||||||
package, _, crate_version = cli_dep.partition(':')
|
package, _, crate_version = cli_dep.partition(':')
|
||||||
if crate_version != '':
|
if crate_version != '':
|
||||||
packages_to_install.add((package, '--version', crate_version))
|
packages_to_install.add((package, '--version', crate_version))
|
||||||
|
|
|
||||||
|
|
@ -349,8 +349,9 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory, store):
|
||||||
# We should run both the legacy and pre-commit hooks
|
# We should run both the legacy and pre-commit hooks
|
||||||
ret, output = _get_commit_output(tempdir_factory)
|
ret, output = _get_commit_output(tempdir_factory)
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert output.startswith('legacy hook\n')
|
legacy = 'legacy hook\n'
|
||||||
NORMAL_PRE_COMMIT_RUN.assert_matches(output[len('legacy hook\n'):])
|
assert output.startswith(legacy)
|
||||||
|
NORMAL_PRE_COMMIT_RUN.assert_matches(output.removeprefix(legacy))
|
||||||
|
|
||||||
|
|
||||||
def test_legacy_overwriting_legacy_hook(tempdir_factory, store):
|
def test_legacy_overwriting_legacy_hook(tempdir_factory, store):
|
||||||
|
|
@ -375,8 +376,9 @@ def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory, store):
|
||||||
# We should run both the legacy and pre-commit hooks
|
# We should run both the legacy and pre-commit hooks
|
||||||
ret, output = _get_commit_output(tempdir_factory)
|
ret, output = _get_commit_output(tempdir_factory)
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert output.startswith('legacy hook\n')
|
legacy = 'legacy hook\n'
|
||||||
NORMAL_PRE_COMMIT_RUN.assert_matches(output[len('legacy hook\n'):])
|
assert output.startswith(legacy)
|
||||||
|
NORMAL_PRE_COMMIT_RUN.assert_matches(output.removeprefix(legacy))
|
||||||
|
|
||||||
|
|
||||||
def test_install_with_existing_non_utf8_script(tmpdir, store):
|
def test_install_with_existing_non_utf8_script(tmpdir, store):
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ def test_db_repo_name(store):
|
||||||
|
|
||||||
def test_local_resources_reflects_reality():
|
def test_local_resources_reflects_reality():
|
||||||
on_disk = {
|
on_disk = {
|
||||||
res[len('empty_template_'):]
|
res.removeprefix('empty_template_')
|
||||||
for res in os.listdir('pre_commit/resources')
|
for res in os.listdir('pre_commit/resources')
|
||||||
if res.startswith('empty_template_')
|
if res.startswith('empty_template_')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue