Skip to content

Commit

Permalink
Run ruff check --fix --unsafe-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaily committed Dec 23, 2024
1 parent 077f65f commit 6c37a4d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 51 deletions.
4 changes: 2 additions & 2 deletions scripts/gen-server-completions
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
32 changes: 13 additions & 19 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions scripts/install_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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}"
)


Expand All @@ -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")
Expand Down
26 changes: 11 additions & 15 deletions scripts/make-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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):
Expand All @@ -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))
Expand Down Expand Up @@ -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')

Expand All @@ -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,
Expand All @@ -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__':
Expand Down
9 changes: 4 additions & 5 deletions scripts/new-change
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -132,8 +132,7 @@ def replace_issue_references(parsed, repo_name):
def linkify(match):
number = match.group()[1:]
return (
'`%s <https://github.com/%s/issues/%s>`__' % (
match.group(), repo_name, number))
f'`{match.group()} <https://github.com/{repo_name}/issues/{number}>`__')

new_description = re.sub('#\d+', linkify, description)
parsed['description'] = new_description
Expand All @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion scripts/performance/benchmark_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/regenerate-lock-files
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6c37a4d

Please sign in to comment.