Skip to content
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

Run ruff format - scripts #9208

Draft
wants to merge 1 commit into
base: v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
22 changes: 13 additions & 9 deletions scripts/gen-ac-index
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
"""Generate the index used for the new auto-completion.
"""Generate the index used for the new auto-completion."""

"""
import os
import argparse

Expand All @@ -11,13 +10,18 @@ from awscli.autocomplete import generator

def main():
parser = argparse.ArgumentParser()
parser.add_argument('--include-builtin-index', action='store_true',
help=("Also generate builtin index as well as the "
"INDEX_LOCATION."))
parser.add_argument('--index-location', default=db.INDEX_FILE,
help=(
'Location to write the index file. '
'Defaults to ' + db.INDEX_FILE))
parser.add_argument(
'--include-builtin-index',
action='store_true',
help=("Also generate builtin index as well as the " "INDEX_LOCATION."),
)
parser.add_argument(
'--index-location',
default=db.INDEX_FILE,
help=(
'Location to write the index file. ' 'Defaults to ' + db.INDEX_FILE
),
)
args = parser.parse_args()
index_dir = os.path.dirname(os.path.abspath(args.index_location))
if not os.path.isdir(index_dir):
Expand Down
7 changes: 5 additions & 2 deletions scripts/gen-server-completions
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if you want to see the generated completion data without modifying existing
files.

"""

import argparse
import json
import sys
Expand All @@ -37,8 +38,10 @@ def generate_completion_data(args):
model = session.get_service_model(service_name)
completion_data = gen.generate_completion_descriptions(model)
out_filename = os.path.join(
BOTOCORE_DATA_PATH, service_name,
model.api_version, 'completions-1.json'
BOTOCORE_DATA_PATH,
service_name,
model.api_version,
'completions-1.json',
)
to_json = _pretty_json_dump(completion_data)
if args.only_print:
Expand Down
114 changes: 66 additions & 48 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import tempfile
from contextlib import contextmanager

PACKAGES_DIR = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'packages')
INSTALL_DIR = os.path.expanduser(os.path.join(
'~', '.local', 'lib', 'aws'))
os.path.dirname(os.path.abspath(__file__)), 'packages'
)
INSTALL_DIR = os.path.expanduser(os.path.join('~', '.local', 'lib', 'aws'))
GTE_PY37 = sys.version_info[:2] >= (3, 7)
UNSUPPORTED_PYTHON = (
(2,6),
(3,3),
(3,4),
(3,5),
(2, 6),
(3, 3),
(3, 4),
(3, 5),
)
INSTALL_ARGS = (
'--no-binary :all: --no-build-isolation --no-cache-dir --no-index '
Expand All @@ -45,19 +45,18 @@ class PythonDeprecationWarning(Warning):
Python version being used is scheduled to become unsupported
in an future release. See warning for specifics.
"""

pass


def _build_deprecations():
py_27_params = {
'date': 'July 15, 2021',
'blog_link': 'https://aws.amazon.com/blogs/developer/announcing-end-'
'of-support-for-python-2-7-in-aws-sdk-for-python-and-'
'aws-cli-v1/'
}
return {
(2,7): py_27_params
'of-support-for-python-2-7-in-aws-sdk-for-python-and-'
'aws-cli-v1/',
}
return {(2, 7): py_27_params}


DEPRECATED_PYTHON = _build_deprecations()
Expand All @@ -75,13 +74,15 @@ def cd(dirname):

def run(cmd):
sys.stdout.write("Running cmd: %s\n" % cmd)
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
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(
"Bad rc (%s) for cmd '%s': %s" % (p.returncode, cmd, output)
)
return stdout


Expand Down Expand Up @@ -123,15 +124,16 @@ 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(
('%s virtualenv.py --no-download ' '--python %s %s')
% (sys.executable, sys.executable, location)
)


def _get_package_tarball(package_dir, package_prefix):
package_filenames = sorted([p for p in os.listdir(package_dir)
if p.startswith(package_prefix)])
package_filenames = sorted(
[p for p in os.listdir(package_dir) if p.startswith(package_prefix)]
)
return package_filenames[-1]


Expand All @@ -145,8 +147,9 @@ def create_working_dir():


def pip_install_packages(install_dir):
cli_tarball = [p for p in os.listdir(PACKAGES_DIR)
if p.startswith('awscli')]
cli_tarball = [
p for p in os.listdir(PACKAGES_DIR) if p.startswith('awscli')
]
if len(cli_tarball) != 1:
message = (
"Multiple versions of the CLI were found in %s. Please clear "
Expand All @@ -161,8 +164,10 @@ 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(
'%s install %s --find-links file://%s %s'
% (pip_script, INSTALL_ARGS, PACKAGES_DIR, cli_tarball)
)


def _install_setup_deps(pip_script, setup_package_dir):
Expand All @@ -172,15 +177,19 @@ def _install_setup_deps(pip_script, setup_package_dir):
# so for now we're explicitly installing the one setup_requires package
# 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))
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))
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)
)
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)
)


def create_symlink(real_location, symlink_name):
Expand All @@ -197,17 +206,25 @@ def create_symlink(real_location, symlink_name):

def main():
parser = optparse.OptionParser()
parser.add_option('-i', '--install-dir', help="The location to install "
"the AWS CLI. The default value is ~/.local/lib/aws",
default=INSTALL_DIR)
parser.add_option('-b', '--bin-location', help="If this argument is "
"provided, then a symlink will be created at this "
"location that points to the aws executable. "
"This argument is useful if you want to put the aws "
"executable somewhere already on your path, e.g. "
"-b /usr/local/bin/aws. This is an optional argument. "
"If you do not provide this argument you will have to "
"add INSTALL_DIR/bin to your PATH.")
parser.add_option(
'-i',
'--install-dir',
help="The location to install "
"the AWS CLI. The default value is ~/.local/lib/aws",
default=INSTALL_DIR,
)
parser.add_option(
'-b',
'--bin-location',
help="If this argument is "
"provided, then a symlink will be created at this "
"location that points to the aws executable. "
"This argument is useful if you want to put the aws "
"executable somewhere already on your path, e.g. "
"-b /usr/local/bin/aws. This is an optional argument. "
"If you do not provide this argument you will have to "
"add INSTALL_DIR/bin to your PATH.",
)
py_version = sys.version_info[:2]
if py_version in UNSUPPORTED_PYTHON:
unsupported_python_msg = (
Expand Down Expand Up @@ -240,8 +257,9 @@ def main():
create_install_structure(working_dir, opts.install_dir)
pip_install_packages(opts.install_dir)
real_location = os.path.join(opts.install_dir, bin_path(), 'aws')
if opts.bin_location and create_symlink(real_location,
opts.bin_location):
if opts.bin_location and create_symlink(
real_location, opts.bin_location
):
print("You can now run: %s --version" % opts.bin_location)
else:
print("You can now run: %s --version" % real_location)
Expand Down
11 changes: 8 additions & 3 deletions scripts/install_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from utils import cd, bin_path, run, virtualenv_enabled

INSTALL_ARGS = "--no-build-isolation --no-cache-dir --no-index --prefer-binary "
INSTALL_ARGS = (
"--no-build-isolation --no-cache-dir --no-index --prefer-binary "
)
PINNED_PIP_VERSION = '24.0'
SETUP_DEPS = ("setuptools-", "setuptools_scm", "wheel", "hatchling")

Expand All @@ -17,7 +19,8 @@ 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
"Unable to find local package starting with %s prefix."
% package_prefix
)
# We only expect a single package from the downloader
return package_filenames[0]
Expand All @@ -41,7 +44,9 @@ def pip_install_packages(package_dir):

# Setup pip to support modern setuptools calls
pip_script = os.path.join(os.environ["VIRTUAL_ENV"], bin_path(), "pip")
local_python = os.path.join(os.environ["VIRTUAL_ENV"], bin_path(), "python")
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))
Expand Down
Loading
Loading