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

Lint and format - exe/* backends/* doc/* #9207

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
24 changes: 14 additions & 10 deletions backends/build_system/awscli_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,19 @@ def _site_packages(self) -> str:
# On windows the getsitepackages can return the root venv dir.
# So instead of just taking the first entry, we need to take the
# first entry that contains the string "site-packages" in the path.
site_path = [path for path in json.loads(
subprocess.check_output(
[
self.python_exe,
"-c",
"import site, json; print(json.dumps(site.getsitepackages()))",
]
site_path = [
path
for path in json.loads(
subprocess.check_output(
[
self.python_exe,
"-c",
"import site, json; print(json.dumps(site.getsitepackages()))",
]
)
.decode()
.strip()
)
.decode()
.strip()
) if "site-packages" in path][0]
if "site-packages" in path
][0]
return site_path
12 changes: 9 additions & 3 deletions backends/build_system/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@
REQUIREMENTS_DIR = ROOT_DIR / "requirements"
BOOTSTRAP_REQUIREMENTS = REQUIREMENTS_DIR / "bootstrap.txt"
DOWNLOAD_DEPS_BOOTSTRAP = REQUIREMENTS_DIR / "download-deps" / "bootstrap.txt"
DOWNLOAD_DEPS_BOOTSTRAP_LOCK = REQUIREMENTS_DIR / "download-deps" / f"bootstrap-{LOCK_SUFFIX}"
DOWNLOAD_DEPS_BOOTSTRAP_LOCK = (
REQUIREMENTS_DIR / "download-deps" / f"bootstrap-{LOCK_SUFFIX}"
)
PORTABLE_EXE_REQUIREMENTS = REQUIREMENTS_DIR / "portable-exe-extras.txt"
PORTABLE_EXE_REQUIREMENTS_LOCK = REQUIREMENTS_DIR / "download-deps" / f"portable-exe-{LOCK_SUFFIX}"
SYSTEM_SANDBOX_REQUIREMENTS_LOCK = REQUIREMENTS_DIR / "download-deps" / f"system-sandbox-{LOCK_SUFFIX}"
PORTABLE_EXE_REQUIREMENTS_LOCK = (
REQUIREMENTS_DIR / "download-deps" / f"portable-exe-{LOCK_SUFFIX}"
)
SYSTEM_SANDBOX_REQUIREMENTS_LOCK = (
REQUIREMENTS_DIR / "download-deps" / f"system-sandbox-{LOCK_SUFFIX}"
)

# Auto-complete index
AC_INDEX = ROOT_DIR / "awscli" / "data" / "ac.index"
Expand Down
11 changes: 7 additions & 4 deletions backends/build_system/exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
import os
from dataclasses import dataclass, field

from constants import EXE_ASSETS_DIR, PYINSTALLER_DIR, DISTRIBUTION_SOURCE_EXE, PYINSTALLER_EXE_NAME
from constants import (
EXE_ASSETS_DIR,
PYINSTALLER_DIR,
DISTRIBUTION_SOURCE_EXE,
PYINSTALLER_EXE_NAME,
)
from utils import Utils
from awscli_venv import AwsCliVenv

Expand Down Expand Up @@ -52,12 +57,10 @@ def _update_metadata(self):
distribution_source=DISTRIBUTION_SOURCE_EXE,
)
for distinfo in self._utils.glob(
'**/*.dist-info',
root=self._final_dist_dir
'**/*.dist-info', root=self._final_dist_dir
):
self._utils.rmtree(os.path.join(self._final_dist_dir, distinfo))


def _ensure_no_existing_build_dir(self):
if self._utils.isdir(self._dist_dir):
self._utils.rmtree(self._dist_dir)
Expand Down
9 changes: 7 additions & 2 deletions backends/build_system/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
{path} %*
"""


class Uninstaller:
def __init__(self, utils: Utils = None):
if utils is None:
Expand All @@ -36,7 +37,9 @@ def uninstall(self, install_dir: str, bin_dir: str):
self._utils.rmtree(install_dir)
for exe in CLI_SCRIPTS:
exe_path = os.path.join(bin_dir, exe)
if self._utils.islink(exe_path) or self._utils.path_exists(exe_path):
if self._utils.islink(exe_path) or self._utils.path_exists(
exe_path
):
self._utils.remove(exe_path)


Expand Down Expand Up @@ -78,7 +81,9 @@ def _install_executables(self, install_dir, bin_dir):

def _install_executables_on_windows(self, install_dir, bin_dir):
filepath = os.path.join(bin_dir, "aws.cmd")
content = WINDOWS_CMD_TEMPLATE.format(path=os.path.join(install_dir, "aws.exe"))
content = WINDOWS_CMD_TEMPLATE.format(
path=os.path.join(install_dir, "aws.exe")
)
self._utils.write_file(filepath, content)

def _symlink_executables(self, install_dir, bin_dir):
Expand Down
29 changes: 18 additions & 11 deletions backends/build_system/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def __init__(self, unmet_deps, in_venv, reason=None):
f"{package} (required: {required.constraints}) "
f"(version installed: {actual_version})\n"
)
pip_install_command_args.append(f'{package}{required.string_constraints()}')
pip_install_command_args.append(
f'{package}{required.string_constraints()}'
)

if reason:
msg += f"\n{reason}\n"
Expand Down Expand Up @@ -100,7 +102,9 @@ def _meets_constraint(self, version, constraint) -> bool:
if not match:
raise RuntimeError(f"Unknown version specifier {constraint}")
comparison, constraint_version = match.group('comparison', 'version')
version, constraint_version = self._normalize(version, constraint_version)
version, constraint_version = self._normalize(
version, constraint_version
)

compare_fn = COMPARISONS.get(comparison)
if not compare_fn:
Expand All @@ -120,7 +124,9 @@ def _normalize(self, v1: str, v2: str):
def __eq__(self, other):
if other is None:
return False
return (self.name == other.name and self.constraints == other.constraints)
return (
self.name == other.name and self.constraints == other.constraints
)

def string_constraints(self):
return ','.join(self.constraints)
Expand All @@ -138,7 +144,7 @@ def parse_requirements(lines_list):
if line.startswith('#'):
continue
if ' #' in line:
line = line[:line.find(' #')]
line = line[: line.find(' #')]
if line.endswith('\\'):
line = line[:-2].strip()
try:
Expand Down Expand Up @@ -184,17 +190,14 @@ def get_install_requires():
def get_flit_core_unmet_exception():
in_venv = sys.prefix != sys.base_prefix
with open(BOOTSTRAP_REQUIREMENTS, 'r') as f:
flit_core_req = [
l for l in f.read().split('\n')
if 'flit_core' in l
]
flit_core_req = [l for l in f.read().split('\n') if 'flit_core' in l]
return UnmetDependenciesException(
[('flit_core', None, list(parse_requirements(flit_core_req))[0])],
in_venv,
reason=(
'flit_core is needed ahead of time in order to parse the '
'rest of the requirements.'
)
),
)


Expand Down Expand Up @@ -248,7 +251,9 @@ def copy_directory(self, src: str, dst: str):

def update_metadata(self, dirname, **kwargs):
print("Update metadata values %s" % kwargs)
metadata_file = os.path.join(dirname, "awscli", "data", "metadata.json")
metadata_file = os.path.join(
dirname, "awscli", "data", "metadata.json"
)
with open(metadata_file) as f:
metadata = json.load(f)
for key, value in kwargs.items():
Expand All @@ -261,5 +266,7 @@ def create_venv(self, name: str, with_pip: bool = True):

def get_script_header(self, python_exe_path: str) -> str:
if IS_WINDOWS:
return f'@echo off & "{python_exe_path}" -x "%~f0" %* & goto :eof\n'
return (
f'@echo off & "{python_exe_path}" -x "%~f0" %* & goto :eof\n'
)
return f"#!{python_exe_path}\n"
4 changes: 1 addition & 3 deletions backends/build_system/validate_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@

ROOT = Path(__file__).parents[2]
PYPROJECT = ROOT / "pyproject.toml"
BUILD_REQS_RE = re.compile(
r"requires = \[([\s\S]+?)\]\s", re.MULTILINE
)
BUILD_REQS_RE = re.compile(r"requires = \[([\s\S]+?)\]\s", re.MULTILINE)
EXTRACT_DEPENDENCIES_RE = re.compile(r'"(.+)"')


Expand Down
2 changes: 2 additions & 0 deletions backends/pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
is that it builds the auto-complete index and injects it into the wheel
built by flit prior to returning.
"""

import re
import contextlib
import hashlib
Expand Down Expand Up @@ -150,6 +151,7 @@ def _should_copy(path):
return False
return True


def read_sdist_extras():
with open(ROOT_DIR / "pyproject.toml", "r") as f:
data = f.read()
Expand Down
5 changes: 2 additions & 3 deletions doc/source/bootstrapdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import sys

RST_GENERATION_SCRIPT = 'htmlgen'
script_path = os.path.join(os.path.dirname(__file__),
RST_GENERATION_SCRIPT)
script_path = os.path.join(os.path.dirname(__file__), RST_GENERATION_SCRIPT)
os.environ['PATH'] += ':.'
rc = subprocess.call("python "+ script_path, shell=True, env=os.environ)
rc = subprocess.call("python " + script_path, shell=True, env=os.environ)
if rc != 0:
sys.stderr.write("Failed to generate documentation!\n")
sys.exit(2)
Loading
Loading