Browse Source

commonize check printing

shut-new-model
Niklas Rosenstein 9 months ago
parent
commit
5a27941dca
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
4 changed files with 16 additions and 21 deletions
  1. + 11
    - 0
      src/shut/commands/commons/checks.py
  2. + 2
    - 10
      src/shut/commands/mono/checks.py
  3. + 2
    - 10
      src/shut/commands/pkg/checks.py
  4. + 1
    - 1
      src/shut/utils/io/virtual.py

+ 11
- 0
src/shut/commands/commons/checks.py

@ -22,6 +22,8 @@
from shut.checks import Check, CheckStatus
from typing import List
import termcolor
import time
import sys
def print_checks(
@ -60,6 +62,15 @@ def print_checks(
print()
def print_checks_all(name: str, checks: List[Check], seconds: float):
package_name = termcolor.colored(name, 'yellow')
print()
print_checks(checks, prefix=' ')
print()
print('run', len(checks), 'checks for package', package_name, 'in {:.3f}s'.format(seconds))
print()
def get_checks_status(checks: List[Check], warnings_as_errors: bool = False) -> int:
max_level = max(x.result.status for x in checks)
if max_level == CheckStatus.PASSED:

+ 2
- 10
src/shut/commands/mono/checks.py

@ -21,7 +21,7 @@
from shut.checks import CheckStatus, get_checks
from shut.commands import project
from shut.commands.commons.checks import print_checks, get_checks_status
from shut.commands.commons.checks import print_checks_all, get_checks_status
from shut.commands.mono import mono
from shut.model import MonorepoModel, Project
@ -53,13 +53,5 @@ def checks(warnings_as_errors):
monorepo = project.load(expect=MonorepoModel)
checks = sorted(get_checks(project, monorepo), key=lambda c: c.name)
seconds = time.perf_counter() - start_time
monorepo_name = termcolor.colored(monorepo.name, 'yellow')
print()
print_checks(checks, prefix=' ')
print()
print('run', len(checks), 'checks for repository', monorepo_name, 'in {:.3f}s'.format(seconds))
print()
print_checks_all(monorepo.name, checks, seconds)
sys.exit(get_checks_status(checks, warnings_as_errors))

+ 2
- 10
src/shut/commands/pkg/checks.py

@ -21,7 +21,7 @@
from shut.checks import CheckStatus, get_checks
from shut.commands import project
from shut.commands.commons.checks import print_checks, get_checks_status
from shut.commands.commons.checks import print_checks_all, get_checks_status
from shut.commands.pkg import pkg
from shut.model import PackageModel, Project
@ -53,13 +53,5 @@ def checks(warnings_as_errors):
package = project.load(expect=PackageModel)
checks = sorted(get_checks(project, package), key=lambda c: c.name)
seconds = time.perf_counter() - start_time
package_name = termcolor.colored(package.data.name, 'yellow')
print()
print_checks(checks, prefix=' ')
print()
print('run', len(checks), 'checks for package', package_name, 'in {:.3f}s'.format(seconds))
print()
print_checks_all(package.data.name, checks, seconds)
sys.exit(get_checks_status(checks, warnings_as_errors))

+ 1
- 1
src/shut/utils/io/virtual.py

@ -80,7 +80,7 @@ class VirtualFiles:
if not dry:
mode = '' if file_['text'] else 'b'
if create_directories:
os.makedirs(os.path.dirname(filename), exist_ok=True)
os.makedirs(os.path.dirname(filename) or '.', exist_ok=True)
if file_['inplace']:
with open(filename, 'w' + mode) as dst:
if exists:

Loading…
Cancel
Save