mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Some manual .format() -> f-strings
This commit is contained in:
parent
aefbe71765
commit
9000e9dd41
27 changed files with 133 additions and 173 deletions
|
|
@ -81,7 +81,7 @@ def install_environment(
|
|||
|
||||
def get_docker_user() -> str: # pragma: windows no cover
|
||||
try:
|
||||
return '{}:{}'.format(os.getuid(), os.getgid())
|
||||
return f'{os.getuid()}:{os.getgid()}'
|
||||
except AttributeError:
|
||||
return '1000:1000'
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ def docker_cmd() -> Tuple[str, ...]: # pragma: windows no cover
|
|||
# https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container-volumes-from
|
||||
# The `Z` option tells Docker to label the content with a private
|
||||
# unshared label. Only the current container can use a private volume.
|
||||
'-v', '{}:/src:rw,Z'.format(os.getcwd()),
|
||||
'-v', f'{os.getcwd()}:/src:rw,Z',
|
||||
'--workdir', '/src',
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ def assert_no_additional_deps(
|
|||
) -> None:
|
||||
if additional_deps:
|
||||
raise AssertionError(
|
||||
'For now, pre-commit does not support '
|
||||
'additional_dependencies for {}'.format(lang),
|
||||
f'For now, pre-commit does not support '
|
||||
f'additional_dependencies for {lang}',
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ def _envdir(prefix: Prefix, version: str) -> str:
|
|||
def get_env_patch(venv: str) -> PatchesT: # pragma: windows no cover
|
||||
if sys.platform == 'cygwin': # pragma: no cover
|
||||
_, win_venv, _ = cmd_output('cygpath', '-w', venv)
|
||||
install_prefix = r'{}\bin'.format(win_venv.strip())
|
||||
install_prefix = fr'{win_venv.strip()}\bin'
|
||||
lib_dir = 'lib'
|
||||
elif sys.platform == 'win32': # pragma: no cover
|
||||
install_prefix = bin_dir(venv)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ def _process_filename_at_once(pattern: Pattern[bytes], filename: str) -> int:
|
|||
if match:
|
||||
retv = 1
|
||||
line_no = contents[:match.start()].count(b'\n')
|
||||
output.write('{}:{}:'.format(filename, line_no + 1))
|
||||
output.write(f'{filename}:{line_no + 1}:')
|
||||
|
||||
matched_lines = match.group().split(b'\n')
|
||||
matched_lines[0] = contents.split(b'\n')[line_no]
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ def _find_by_py_launcher(
|
|||
version: str,
|
||||
) -> Optional[str]: # pragma: no cover (windows only)
|
||||
if version.startswith('python'):
|
||||
num = version[len('python'):]
|
||||
try:
|
||||
return cmd_output(
|
||||
'py', '-{}'.format(version[len('python'):]),
|
||||
'-c', 'import sys; print(sys.executable)',
|
||||
'py', f'-{num}', '-c', 'import sys; print(sys.executable)',
|
||||
)[1].strip()
|
||||
except CalledProcessError:
|
||||
pass
|
||||
|
|
@ -88,7 +88,7 @@ def get_default_version() -> str: # pragma: no cover (platform dependent)
|
|||
return exe
|
||||
|
||||
# Next try the `pythonX.X` executable
|
||||
exe = 'python{}.{}'.format(*sys.version_info)
|
||||
exe = f'python{sys.version_info[0]}.{sys.version_info[1]}'
|
||||
if find_executable(exe):
|
||||
return exe
|
||||
|
||||
|
|
@ -96,7 +96,8 @@ def get_default_version() -> str: # pragma: no cover (platform dependent)
|
|||
return exe
|
||||
|
||||
# Give a best-effort try for windows
|
||||
if os.path.exists(r'C:\{}\python.exe'.format(exe.replace('.', ''))):
|
||||
default_folder_name = exe.replace('.', '')
|
||||
if os.path.exists(fr'C:\{default_folder_name}\python.exe'):
|
||||
return exe
|
||||
|
||||
# We tried!
|
||||
|
|
@ -135,7 +136,8 @@ def norm_version(version: str) -> str:
|
|||
# If it is in the form pythonx.x search in the default
|
||||
# place on windows
|
||||
if version.startswith('python'):
|
||||
return r'C:\{}\python.exe'.format(version.replace('.', ''))
|
||||
default_folder_name = version.replace('.', '')
|
||||
return fr'C:\{default_folder_name}\python.exe'
|
||||
|
||||
# Otherwise assume it is a path
|
||||
return os.path.expanduser(version)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue