From f48a84d92f63b32f17cc3e9697c2a05811bd36d1 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Sun, 1 Nov 2020 11:43:28 +0000 Subject: [PATCH] Improve some formatting --- cibuildwheel/linux.py | 23 ++++++++++++++--------- cibuildwheel/logger.py | 30 ++++++++++++++++-------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 80ea93a0..500307b7 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -120,11 +120,16 @@ def build(options: BuildOptions) -> None: continue try: + log.step(f'Starting Docker image {docker_image}...') with DockerContainer(docker_image, simulate_32_bit=platform_tag.endswith('i686'), cwd=container_project_path) as docker: + log.step_end() + + log.step('Copying project into Docker...') docker.copy_into(Path.cwd(), container_project_path) + log.step_end() if options.before_all: - log.build_step('Running before_all...') + log.step('Running before_all...') env = docker.get_environment() env['PATH'] = f'/opt/python/cp38-cp38:{env["PATH"]}' @@ -133,7 +138,7 @@ def build(options: BuildOptions) -> None: before_all_prepared = prepare_command(options.before_all, project=container_project_path, package=container_package_dir) docker.call(['sh', '-c', before_all_prepared], env=env) - log.build_step_end() + log.step_end() for config in platform_configs: log.build_start(config.identifier) @@ -153,7 +158,7 @@ def build(options: BuildOptions) -> None: python_bin = config.path / 'bin' env['PATH'] = f'{python_bin}:{env["PATH"]}' - log.build_step('Setting up build environment...') + log.step('Setting up build environment...') env = options.environment.as_dictionary(env, executor=docker.environment_executor) @@ -169,11 +174,11 @@ def build(options: BuildOptions) -> None: exit(1) if options.before_build: - log.build_step('Running before_build...') + log.step('Running before_build...') before_build_prepared = prepare_command(options.before_build, project=container_project_path, package=container_package_dir) docker.call(['sh', '-c', before_build_prepared], env=env) - log.build_step('Building wheel...') + log.step('Building wheel...') temp_dir = PurePath('/tmp/cibuildwheel') built_wheel_dir = temp_dir / 'built_wheel' @@ -198,7 +203,7 @@ def build(options: BuildOptions) -> None: raise NonPlatformWheelError() if options.repair_command: - log.build_step('Repairing wheel...') + log.step('Repairing wheel...') repair_command_prepared = prepare_command(options.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir) docker.call(['sh', '-c', repair_command_prepared], env=env) else: @@ -207,7 +212,7 @@ def build(options: BuildOptions) -> None: repaired_wheels = docker.glob(repaired_wheel_dir, '*.whl') if options.test_command: - log.build_step('Testing wheel...') + log.step('Testing wheel...') # set up a virtual environment to install and test from, to make sure # there are no dependencies that were pulled in at build time. @@ -249,10 +254,10 @@ def build(options: BuildOptions) -> None: log.build_end() - log.build_step('Copying wheels back to host...') + log.step('Copying wheels back to host...') # copy the output back into the host docker.copy_out(container_output_dir, options.output_dir) - log.build_step_end() + log.step_end() except subprocess.CalledProcessError as error: print(f'Command {error.cmd} failed with code {error.returncode}. {error.stdout}') troubleshoot(options.package_dir, error) diff --git a/cibuildwheel/logger.py b/cibuildwheel/logger.py index 4dde6e6a..cdbaa762 100644 --- a/cibuildwheel/logger.py +++ b/cibuildwheel/logger.py @@ -25,9 +25,9 @@ class Logger: fold_mode: str colors_enabled: bool active_build_identifier: Optional[str] = None - build_start_time: Optional[float] = 0 - step_start_time: Optional[float] = 0 - active_fold_group_id: Optional[str] = None + build_start_time: Optional[float] = None + step_start_time: Optional[float] = None + active_fold_group_name: Optional[str] = None def __init__(self): if 'AZURE_HTTP_USER_AGENT' in os.environ: @@ -54,7 +54,7 @@ class Logger: c = self.colors print() print(f'{c.bold}Building {build_description_from_identifier(identifier)} wheel{c.end}') - print(f'Identifier: {identifier}') + print(f'Identifier: {c.bg_grey}{identifier}{c.end}') print() self.build_start_time = time.time() @@ -62,21 +62,23 @@ class Logger: def build_end(self): assert self.build_start_time is not None - self.build_step_end() + self.step_end() c = self.colors duration = time.time() - self.build_start_time + print() print(f'{c.green}Build {c.bg_grey}{self.active_build_identifier}{c.end}{c.green} completed in {duration:.2f}s{c.end}') print() print('---') + print() self.build_start_time = None - def build_step(self, step_description: str): - self.build_step_end() + def step(self, step_description: str): + self.step_end() self.step_start_time = time.time() self.start_fold_group(step_description) - def build_step_end(self): + def step_end(self): if self.step_start_time is not None: self.end_fold_group() c = self.colors @@ -86,16 +88,16 @@ class Logger: def start_fold_group(self, name: str): self.end_fold_group() - self.active_fold_group_id = re.sub(r'[^A-Za-z]', '', name) + self.active_fold_group_name = name fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, ('', ''))[0] - print(fold_start_pattern.format(name=self.active_fold_group_id)) + print(fold_start_pattern.format(name=self.active_fold_group_name)) print() def end_fold_group(self): - if self.active_fold_group_id: + if self.active_fold_group_name: fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, ('', ''))[1] - print(fold_start_pattern.format(name=self.active_fold_group_id)) - self.active_fold_group_id = None + print(fold_start_pattern.format(name=self.active_fold_group_name)) + self.active_fold_group_name = None @property def colors(self): @@ -139,7 +141,7 @@ class Colors(): bright_green = '\033[92m' white = '\033[37m\033[97m' - bg_grey = '\033[48;5;244m' + bg_grey = '\033[48;5;235m' bold = '\033[1m' faint = '\033[2m'