8000 modernize to f-string by stonebig · Pull Request #1170 · winpython/winpython · GitHub
[go: up one dir, main page]

Skip to content

modernize to f-string #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions winpython/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def get_special_folder_path(path_name):
0, csidl, False
)
raise ValueError(
"%s is an unknown path ID" % (path_name,)
f"{path_name} is an unknown path ID"
)


Expand Down Expand Up @@ -225,7 +225,7 @@ def create_winpython_start_menu_folder(current=True):
shutil.rmtree(path, onerror=onerror)
except WindowsError:
print(
"Directory %s could not be removed" % path,
f"Directory {path} could not be removed",
file=sys.stderr,
)
else:
Expand Down Expand Up @@ -371,13 +371,13 @@ def python_query(cmd, path):
"""Execute Python command using the Python interpreter located in *path*"""
the_exe = get_python_executable(path)
# debug2021-09-12
print('"%s" -c "%s"' % (the_exe, cmd), ' * ', path)
return exec_shell_cmd('"%s" -c "%s"' % (the_exe, cmd), path).splitlines()[0]
print(f'"{the_exe}" -c "{cmd}"', ' * ', path)
return exec_shell_cmd(f'"{the_exe}" -c "{cmd}"', path).splitlines()[0]

def python_execmodule(cmd, path):
"""Execute Python command using the Python interpreter located in *path*"""
the_exe = get_python_executable(path)
exec_shell_cmd('%s -m %s' % (the_exe, cmd), path)
exec_shell_cmd(f'{the_exe} -m {cmd}', path)


def get_python_infos(path):
Expand All @@ -389,8 +389,8 @@ def get_python_infos(path):
)
arch = {'True': 64, 'False': 32}.get(is_64, None)
ver = python_query(
"import sys; print('%d.%d' % (sys.version_info.major, "
"sys.version_info.minor))",
"import sys;print(f'{sys.version_info.major}.{sys.version_info.minor}')"
,
path,
)
if re.match(r'([0-9]*)\.([0-9]*)', ver) is None:
Expand All @@ -403,9 +403,8 @@ def get_python_long_version(path):
"""Return long version (X.Y.Z) for the Python distribution located in
*path*"""
ver = python_query(
"import sys; print('%d.%d.%d' % "
"(sys.version_info.major, sys.version_info.minor,"
"sys.version_info.micro))",
"import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')"
,
path,
)
if (
Expand Down Expand Up @@ -634,10 +633,10 @@ def extract_exe(fname, targetdir=None, verbose=False):
targetdir = _create_temp_dir()
extract = '7z.exe'
assert is_program_installed(extract), (
"Required program '%s' was not found" % extract
f"Required program '{extract}' was not found"
)
bname = Path(fname).name
args = ['x', '-o%s' % targetdir, '-aos', bname]
args = ['x', f'-o{targetdir}', '-aos', bname]
if verbose:
retcode = subprocess.call(
[extract] + args, cwd=str(Path(fname).parent)
Expand All @@ -653,8 +652,7 @@ def extract_exe(fname, targetdir=None, verbose=False):
retcode = p.returncode
if retcode != 0:
raise RuntimeError(
"Failed to extract %s (return code: %d)"
% (fname, retcode)
f"Failed to extract {fname} (return code: {retcode})"
)
return targetdir

Expand All @@ -676,7 +674,7 @@ def extract_archive(fname, targetdir=None, verbose=False):
obj = tarfile.open(fname, mode='r:gz')
else:
raise RuntimeError(
"Unsupported archive filename %s" % fname
f"Unsupported archive filename {fname}"
)
obj.extractall(path=targetdir)
return targetdir
Expand Down Expand Up @@ -727,7 +725,7 @@ def build_wininst(
archstr = (
'win32' if architecture == 32 else 'win-amd64'
)
cmd += ['--plat-name=%s' % archstr]
cmd += [f'--plat-name={archstr}']
cmd += [installer]
# root = a tmp dir in windows\tmp,
if verbose:
Expand Down Expand Up @@ -769,8 +767,7 @@ def build_wininst(
break
else:
raise RuntimeError(
"Build failed: not a pure Python package? %s"
% distdir
f"Build failed: not a pure Python package? {distdir}"
)
src_fname = str(Path(distdir) / distname)
if copy_to is None:
Expand All @@ -781,8 +778,7 @@ def build_wininst(
if verbose:
print(
(
"Move: %s --> %s"
% (src_fname, (dst_fname))
f"Move: {src_fname} --> {dst_fname}"
)
)
# remove tempo dir 'root' no more needed
Expand Down Expand Up @@ -821,14 +817,14 @@ def direct_pip_install(
stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate()
the_log = "%s" % stdout + "\n %s" % stderr
the_log = f"{stdout}" + f"\n {stderr}"

if (
' not find ' in the_log
or ' not found ' in the_log
):
print("Failed to Install: \n %s \n" % fname)
print("msg: %s" % the_log)
print(f"Failed to Install: \n {fname} \n")
print(f"msg: {the_log}")
raise RuntimeError
p.stdout.close()
p.stderr.close()
Expand All @@ -837,7 +833,7 @@ def direct_pip_install(
return src_fname
else:
if verbose:
print("Installed %s" % src_fname)
print(f"Installed {src_fname}")
return src_fname


Expand Down Expand Up @@ -877,7 +873,7 @@ def do_script(
p.stdout.close()
p.stderr.close()
if verbose:
print("Executed " % cmd)
print("Executed " , cmd)
return 'ok'


Expand Down
0