fix appearance on Travis with headers and identifiers
This commit is contained in:
+20
-3
@@ -1,12 +1,13 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
DEFAULT_FOLD_PATTERN = ('{name}', '')
|
DEFAULT_FOLD_PATTERN = ('{name}', '')
|
||||||
FOLD_PATTERNS = {
|
FOLD_PATTERNS = {
|
||||||
'azure': ('##[group]{name}', '##[endgroup]'),
|
'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}'),
|
'github': ('::group::{name}', '::endgroup::{name}'),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,16 +108,32 @@ class Logger:
|
|||||||
self._end_fold_group()
|
self._end_fold_group()
|
||||||
self.active_fold_group_name = name
|
self.active_fold_group_name = name
|
||||||
fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, DEFAULT_FOLD_PATTERN)[0]
|
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):
|
def _end_fold_group(self):
|
||||||
if self.active_fold_group_name:
|
if self.active_fold_group_name:
|
||||||
fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, DEFAULT_FOLD_PATTERN)[1]
|
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()
|
sys.stdout.flush()
|
||||||
self.active_fold_group_name = None
|
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
|
@property
|
||||||
def colors(self):
|
def colors(self):
|
||||||
if self.colors_enabled:
|
if self.colors_enabled:
|
||||||
|
|||||||
Reference in New Issue
Block a user