From 6c37a4d7f430d7d006856de1026f6e3e84533270 Mon Sep 17 00:00:00 2001 From: Kenneth Daily Date: Mon, 23 Dec 2024 09:55:30 -0800 Subject: [PATCH] Run ruff check --fix --unsafe-fixes --- scripts/gen-server-completions | 4 ++-- scripts/install | 32 +++++++++++--------------- scripts/install_deps.py | 7 +++--- scripts/make-bundle | 26 +++++++++------------ scripts/new-change | 9 ++++---- scripts/performance/benchmark_utils.py | 2 +- scripts/regenerate-lock-files | 2 +- scripts/utils.py | 7 +++--- 8 files changed, 38 insertions(+), 51 deletions(-) diff --git a/scripts/gen-server-completions b/scripts/gen-server-completions index 335e685cec75..17b824da4802 100755 --- a/scripts/gen-server-completions +++ b/scripts/gen-server-completions @@ -42,8 +42,8 @@ def generate_completion_data(args): ) to_json = _pretty_json_dump(completion_data) if args.only_print: - print("File: %s" % out_filename) - print("Contents:\n%s\n" % to_json) + print(f"File: {out_filename}") + print(f"Contents:\n{to_json}\n") else: _write_data_to_file(out_filename, to_json) diff --git a/scripts/install b/scripts/install index 6875a3af0bb0..d82f5fe4ba74 100755 --- a/scripts/install +++ b/scripts/install @@ -73,14 +73,13 @@ def cd(dirname): def run(cmd): - sys.stdout.write("Running cmd: %s\n" % cmd) + sys.stdout.write(f"Running cmd: {cmd}\n") p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.returncode != 0: output = (stdout + stderr).decode("utf-8") - raise BadRCError("Bad rc (%s) for cmd '%s': %s" % ( - p.returncode, cmd, output)) + raise BadRCError(f"Bad rc ({p.returncode}) for cmd '{cmd}': {output}") return stdout @@ -107,7 +106,7 @@ def _create_virtualenv_internal(location, working_dir): # On py3 we use the built in venv to create our virtualenv. # There's a bug with sys.executable on external virtualenv # that causes installation failures. - run('%s -m venv %s' % (sys.executable, location)) + run(f'{sys.executable} -m venv {location}') def _create_virtualenv_external(location, working_dir): @@ -122,10 +121,8 @@ def _create_virtualenv_external(location, working_dir): # We know that virtualenv is the only dir in this directory # so we can listdir()[0] it. with cd(os.listdir('.')[0]): - run(('%s virtualenv.py --no-download ' - '--python %s %s') % (sys.executable, - sys.executable, - location)) + run(f'{sys.executable} virtualenv.py --no-download ' + f'--python {sys.executable} {location}') def _get_package_tarball(package_dir, package_prefix): @@ -160,8 +157,7 @@ def pip_install_packages(install_dir): _install_setup_deps(pip_script, '.') with cd(PACKAGES_DIR): - run('%s install %s --find-links file://%s %s' % ( - pip_script, INSTALL_ARGS, PACKAGES_DIR, cli_tarball)) + run(f'{pip_script} install {INSTALL_ARGS} --find-links file://{PACKAGES_DIR} {cli_tarball}') def _install_setup_deps(pip_script, setup_package_dir): @@ -172,19 +168,17 @@ def _install_setup_deps(pip_script, setup_package_dir): # we need. This comes from python-dateutils. setuptools_scm_tarball = _get_package_tarball( setup_package_dir, 'setuptools_scm') - run('%s install --no-binary :all: --no-cache-dir --no-index ' - '--find-links file://%s %s' % ( - pip_script, setup_package_dir, setuptools_scm_tarball)) + run(f'{pip_script} install --no-binary :all: --no-cache-dir --no-index ' + f'--find-links file://{setup_package_dir} {setuptools_scm_tarball}') wheel_tarball = _get_package_tarball( setup_package_dir, 'wheel') - run('%s install --no-binary :all: --no-cache-dir --no-index ' - '--find-links file://%s %s' % ( - pip_script, setup_package_dir, wheel_tarball)) + run(f'{pip_script} install --no-binary :all: --no-cache-dir --no-index ' + f'--find-links file://{setup_package_dir} {wheel_tarball}') def create_symlink(real_location, symlink_name): if os.path.isfile(symlink_name): - print("Symlink already exists: %s" % symlink_name) + print(f"Symlink already exists: {symlink_name}") print("Removing symlink.") os.remove(symlink_name) symlink_dir_name = os.path.dirname(symlink_name) @@ -241,9 +235,9 @@ def main(): real_location = os.path.join(opts.install_dir, bin_path(), 'aws') if opts.bin_location and create_symlink(real_location, opts.bin_location): - print("You can now run: %s --version" % opts.bin_location) + print(f"You can now run: {opts.bin_location} --version") else: - print("You can now run: %s --version" % real_location) + print(f"You can now run: {real_location} --version") finally: shutil.rmtree(working_dir) diff --git a/scripts/install_deps.py b/scripts/install_deps.py index 39db22085a35..529e7972c9b7 100644 --- a/scripts/install_deps.py +++ b/scripts/install_deps.py @@ -17,7 +17,7 @@ def get_package_tarball(package_dir, package_prefix): ) if len(package_filenames) == 0: raise InstallationError( - "Unable to find local package starting with %s prefix." % package_prefix + f"Unable to find local package starting with {package_prefix} prefix." ) # We only expect a single package from the downloader return package_filenames[0] @@ -26,8 +26,7 @@ def get_package_tarball(package_dir, package_prefix): def install_local_package(package_dir, package, pip_script="pip"): with cd(package_dir): run( - "%s install %s --find-links file://%s %s" - % (pip_script, INSTALL_ARGS, package_dir, package) + f"{pip_script} install {INSTALL_ARGS} --find-links file://{package_dir} {package}" ) @@ -44,7 +43,7 @@ def pip_install_packages(package_dir): local_python = os.path.join(os.environ["VIRTUAL_ENV"], bin_path(), "python") # Windows can't replace a running pip.exe, so we need to work around - run("%s -m pip install pip==%s" % (local_python, PINNED_PIP_VERSION)) + run(f"{local_python} -m pip install pip=={PINNED_PIP_VERSION}") # Install or update prerequisite build packages setup_requires_dir = os.path.join(package_dir, "setup") diff --git a/scripts/make-bundle b/scripts/make-bundle index 915e4dea0255..86553a131d72 100755 --- a/scripts/make-bundle +++ b/scripts/make-bundle @@ -55,14 +55,13 @@ def cd(dirname): def run(cmd): - sys.stdout.write("Running cmd: %s\n" % cmd) + sys.stdout.write(f"Running cmd: {cmd}\n") p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() rc = p.wait() if p.returncode != 0: - raise BadRCError("Bad rc (%s) for cmd '%s': %s" % ( - rc, cmd, stderr + stdout)) + raise BadRCError(f"Bad rc ({rc}) for cmd '{cmd}': {stderr + stdout}") return stdout @@ -80,17 +79,14 @@ def create_scratch_dir(): def download_package_tarballs(dirname, packages): with cd(dirname): for package, package_version in packages: - run('%s -m pip download %s==%s %s' % ( - sys.executable, package, package_version, PIP_DOWNLOAD_ARGS - )) + run(f'{sys.executable} -m pip download {package}=={package_version} {PIP_DOWNLOAD_ARGS}') def download_cli_deps(scratch_dir): awscli_dir = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) with cd(scratch_dir): - run('pip download -c %s %s %s' % ( - CONSTRAINTS_FILE, PIP_DOWNLOAD_ARGS, awscli_dir)) + run(f'pip download -c {CONSTRAINTS_FILE} {PIP_DOWNLOAD_ARGS} {awscli_dir}') def _remove_cli_zip(scratch_dir): @@ -105,7 +101,7 @@ def add_cli_sdist(scratch_dir): if os.path.exists(os.path.join(awscli_dir, 'dist')): shutil.rmtree(os.path.join(awscli_dir, 'dist')) with cd(awscli_dir): - run('%s setup.py sdist' % sys.executable) + run(f'{sys.executable} setup.py sdist') filename = os.listdir('dist')[0] shutil.move(os.path.join('dist', filename), os.path.join(scratch_dir, filename)) @@ -136,10 +132,10 @@ def verify_preconditions(): # The pip version looks like: # 'pip 1.4.1 from ....' pip_version = run( - '%s -m pip --version' % sys.executable).strip().split()[1] + f'{sys.executable} -m pip --version').strip().split()[1] # Virtualenv version just has the version string: '1.14.5\n' virtualenv_version = run( - '%s -m virtualenv --version' % sys.executable).strip() + f'{sys.executable} -m virtualenv --version').strip() _min_version_required('9.0.1', pip_version, 'pip') _min_version_required('15.1.0', virtualenv_version, 'virtualenv') @@ -152,15 +148,15 @@ def _min_version_required(min_version, actual_version, name): for min_version_part, actual_version_part in zip(min_split, actual_split): if int(actual_version_part) >= int(min_version_part): return - raise ValueError("%s requires at least version %s, but version %s was " - "found." % (name, min_version, actual_version)) + raise ValueError(f"{name} requires at least version {min_version}, but version {actual_version} was " + "found.") def main(): verify_preconditions() scratch_dir = create_scratch_dir() package_dir = os.path.join(scratch_dir, 'packages') - print("Bundle dir at: %s" % scratch_dir) + print(f"Bundle dir at: {scratch_dir}") download_package_tarballs( package_dir, packages=EXTRA_RUNTIME_DEPS, @@ -180,7 +176,7 @@ def main(): add_cli_sdist(package_dir) create_bootstrap_script(scratch_dir) zip_filename = zip_dir(scratch_dir) - print("Zipped bundle installer is at: %s" % zip_filename) + print(f"Zipped bundle installer is at: {zip_filename}") if __name__ == '__main__': diff --git a/scripts/new-change b/scripts/new-change index 8b4905147318..853c324e46da 100755 --- a/scripts/new-change +++ b/scripts/new-change @@ -118,7 +118,7 @@ def get_values_from_editor(args): f.flush() env = os.environ editor = env.get('VISUAL', env.get('EDITOR', 'vim')) - p = subprocess.Popen('%s %s' % (editor, f.name), shell=True) + p = subprocess.Popen(f'{editor} {f.name}', shell=True) p.communicate() with open(f.name) as f: filled_in_contents = f.read() @@ -132,8 +132,7 @@ def replace_issue_references(parsed, repo_name): def linkify(match): number = match.group()[1:] return ( - '`%s `__' % ( - match.group(), repo_name, number)) + f'`{match.group()} `__') new_description = re.sub('#\d+', linkify, description) parsed['description'] = new_description @@ -154,10 +153,10 @@ def write_new_change(parsed_values): type_name=parsed_values['type'], summary=short_summary) possible_filename = os.path.join( - dirname, '%s-%s.json' % (filename, str(random.randint(1, 100000)))) + dirname, f'{filename}-{str(random.randint(1, 100000))}.json') while os.path.isfile(possible_filename): possible_filename = os.path.join( - dirname, '%s-%s.json' % (filename, str(random.randint(1, 100000)))) + dirname, f'{filename}-{str(random.randint(1, 100000))}.json') with open(possible_filename, 'w') as f: f.write(json.dumps(parsed_values, indent=2) + "\n") diff --git a/scripts/performance/benchmark_utils.py b/scripts/performance/benchmark_utils.py index da48ae372d81..e53ad031ffed 100644 --- a/scripts/performance/benchmark_utils.py +++ b/scripts/performance/benchmark_utils.py @@ -189,7 +189,7 @@ def benchmark_command(command, benchmark_script, summarize_script, try: for i in range(num_iterations): - out_file = 'performance%s.csv' % i + out_file = f'performance{i}.csv' out_file = os.path.join(performance_dir, out_file) benchmark_args = [ benchmark_script, command, '--output-file', out_file diff --git a/scripts/regenerate-lock-files b/scripts/regenerate-lock-files index 4ce278cf7cf3..4e1fe4bae16b 100755 --- a/scripts/regenerate-lock-files +++ b/scripts/regenerate-lock-files @@ -55,7 +55,7 @@ class LockFileBuilder: output_path = self._full_output_path(output) self._delete_file(output_path) args = self._pip_compile_args(sources, output_path) - result = self._pip_compile(args, allow_unsafe) + self._pip_compile(args, allow_unsafe) self._overwrite_paths(output_path) def _full_output_path(self, output: Path) -> Path: diff --git a/scripts/utils.py b/scripts/utils.py index 3d5bfaa8c722..9cf0c41d85dd 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -15,7 +15,7 @@ class BadRCError(Exception): def run(cmd, cwd=None, env=None, echo=True): if echo: - sys.stdout.write("Running cmd: %s\n" % cmd) + sys.stdout.write(f"Running cmd: {cmd}\n") kwargs = { 'shell': True, 'stdout': subprocess.PIPE, @@ -31,8 +31,7 @@ def run(cmd, cwd=None, env=None, echo=True): stdout, stderr = p.communicate() output = stdout.decode('utf-8') + stderr.decode('utf-8') if p.returncode != 0: - raise BadRCError("Bad rc (%s) for cmd '%s': %s" % ( - p.returncode, cmd, output)) + raise BadRCError(f"Bad rc ({p.returncode}) for cmd '{cmd}': {output}") return output @@ -83,7 +82,7 @@ def virtualenv_enabled(): def update_metadata(dirname, **kwargs): - print('Update metadata values %s' % kwargs) + print(f'Update metadata values {kwargs}') metadata_file = os.path.join(dirname, 'awscli', 'data', 'metadata.json') with open(metadata_file) as f: metadata = json.load(f)