From 7914432a68b3b2d2dd334782caac265042d8d11c Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Fri, 13 Nov 2020 15:25:52 +0000 Subject: [PATCH] fix appearance on Travis with headers and identifiers --- cibuildwheel/logger.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/cibuildwheel/logger.py b/cibuildwheel/logger.py index fcd77751..7ccc71ff 100644 --- a/cibuildwheel/logger.py +++ b/cibuildwheel/logger.py @@ -1,12 +1,13 @@ import os import time import sys +import re from typing import Optional, Union DEFAULT_FOLD_PATTERN = ('{name}', '') FOLD_PATTERNS = { 'azure': ('##[group]{name}', '##[endgroup]'), - 'travis': ('travis_fold:start:{name}', 'travis_fold:end:{name}'), + 'travis': ('travis_fold:start:{identifier}\n{name}', 'travis_fold:end:{identifier}'), 'github': ('::group::{name}', '::endgroup::{name}'), } @@ -107,16 +108,32 @@ class Logger: self._end_fold_group() self.active_fold_group_name = name fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, DEFAULT_FOLD_PATTERN)[0] + identifier = self._fold_group_identifier(name) - print(fold_start_pattern.format(name=self.active_fold_group_name)) + print(fold_start_pattern.format(name=self.active_fold_group_name, identifier=identifier)) def _end_fold_group(self): if self.active_fold_group_name: fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, DEFAULT_FOLD_PATTERN)[1] - print(fold_start_pattern.format(name=self.active_fold_group_name)) + identifier = self._fold_group_identifier(self.active_fold_group_name) + print(fold_start_pattern.format(name=self.active_fold_group_name, identifier=identifier)) sys.stdout.flush() self.active_fold_group_name = None + def _fold_group_identifier(self, name: str): + ''' + Travis doesn't like fold groups identifiers that have spaces in. This + method converts them to ascii identifiers + ''' + # whitespace to dashes + identifier = re.sub(r'\s+', '-', name) + # remove non-alphanum + identifier = re.sub(r'[^A-Za-z\d]+', r'', identifier) + # trim dashes + identifier = identifier.strip('-') + # lowercase + return identifier.lower() + @property def colors(self): if self.colors_enabled: