Skip to content

Commit

Permalink
[ci] Fix pre-commit errors (#6940)
Browse files Browse the repository at this point in the history
Issue: #

### Brief Summary
  • Loading branch information
feisuzhu authored Dec 21, 2022
1 parent d3877ce commit 8501dcf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
1 change: 1 addition & 0 deletions .github/workflows/scripts/ci_common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .bootstrap import early_init

early_init()
10 changes: 7 additions & 3 deletions .github/workflows/scripts/ci_common/dep.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-

# -- stdlib --
import shutil
import zipfile
from pathlib import Path
from urllib.parse import urlparse
import zipfile
import shutil

# -- third party --
import requests
Expand Down Expand Up @@ -84,7 +84,11 @@ def download_dep(url, outdir, *, strip=0, force=False):
with requests.get(url, stream=True) as r:
r.raise_for_status()
total_size = int(r.headers.get('content-length', 0))
prog = tqdm.tqdm(unit="B", unit_scale=True, unit_divisor=1024, total=total_size, desc=name)
prog = tqdm.tqdm(unit="B",
unit_scale=True,
unit_divisor=1024,
total=total_size,
desc=name)
with prog, open(local_cached, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
sz = f.write(chunk)
Expand Down
28 changes: 10 additions & 18 deletions .github/workflows/scripts/ci_common/escapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,25 @@ def esc(*x):


# The initial list of escape codes
escape_codes = {
'reset': esc('0'),
'bold': esc('01'),
'thin': esc('02')
}
escape_codes = {'reset': esc('0'), 'bold': esc('01'), 'thin': esc('02')}

# The color names
COLORS = [
'black',
'red',
'green',
'yellow',
'blue',
'purple',
'cyan',
'white'
]
COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'purple', 'cyan', 'white']

PREFIXES = [
# Foreground without prefix
('3', ''), ('01;3', 'bold_'), ('02;3', 'thin_'),
('3', ''),
('01;3', 'bold_'),
('02;3', 'thin_'),

# Foreground with fg_ prefix
('3', 'fg_'), ('01;3', 'fg_bold_'), ('02;3', 'fg_thin_'),
('3', 'fg_'),
('01;3', 'fg_bold_'),
('02;3', 'fg_thin_'),

# Background with bg_ prefix - bold/light works differently
('4', 'bg_'), ('10', 'bg_bold_'),
('4', 'bg_'),
('10', 'bg_bold_'),
]

for prefix, prefix_name in PREFIXES:
Expand Down
22 changes: 16 additions & 6 deletions .github/workflows/scripts/ci_common/misc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-

# -- stdlib --
from pathlib import Path
from typing import Callable
import inspect
import os
import platform
import sys
from pathlib import Path
from typing import Callable

# -- third party --
# -- own --
Expand All @@ -19,7 +19,8 @@ def is_manylinux2014() -> bool:
Are we in a manylinux2014 environment?
This means a particular CentOS docker image.
'''
return platform.system() == 'Linux' and Path('/etc/centos-release').exists()
return platform.system() == 'Linux' and Path(
'/etc/centos-release').exists()


def get_cache_home() -> Path:
Expand All @@ -41,15 +42,24 @@ def decorate(f: Callable) -> Callable:
C = escape_codes['bold_cyan']
R = escape_codes['bold_red']
N = escape_codes['reset']

def wrapper(*args, **kwargs):
_args = sig.bind(*args, **kwargs)
print(f'{C}:: -----BEGIN {msg}-----{N}'.format(**_args.arguments), file=sys.stderr, flush=True)
print(f'{C}:: -----BEGIN {msg}-----{N}'.format(**_args.arguments),
file=sys.stderr,
flush=True)
try:
ret = f(*args, **kwargs)
print(f'{C}:: -----END {msg}-----{N}'.format(**_args.arguments), file=sys.stderr, flush=True)
print(
f'{C}:: -----END {msg}-----{N}'.format(**_args.arguments),
file=sys.stderr,
flush=True)
return ret
except BaseException as e:
print(f'{R}!! -----EXCEPTION {msg}-----{N}'.format(**_args.arguments), file=sys.stderr, flush=True)
print(f'{R}!! -----EXCEPTION {msg}-----{N}'.format(
**_args.arguments),
file=sys.stderr,
flush=True)
raise

return wrapper
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scripts/ci_common/python.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-

# -- stdlib --
from pathlib import Path
from typing import Optional, Tuple
import os
import sys
from pathlib import Path
from typing import Optional, Tuple

# -- third party --
# -- own --
Expand Down

0 comments on commit 8501dcf

Please sign in to comment.