diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 1c2c681..e581bed 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -21,3 +21,5 @@ jobs: - run: curl https://skupper.io/install.sh | sh - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - run: ./plano test + env: + PLANO_COLOR: 1 diff --git a/.gitignore b/.gitignore index 04d68f4..f651c26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ /README.html +/htmlcov /.coverage diff --git a/.plano.py b/.plano.py index 693c66f..75abab5 100644 --- a/.plano.py +++ b/.plano.py @@ -17,6 +17,8 @@ # under the License. # +import skewer.tests + from skewer import * @command(passthrough=True) @@ -29,17 +31,14 @@ def test(verbose=False, quiet=False, passthrough_args=[]): if quiet: passthrough_args.append("--quiet") - args = " ".join(passthrough_args) - - import skewer.tests - PlanoTestCommand(skewer.tests).main(passthrough_args) + with working_env(PYTHONPATH="python"): + run(["plano-test", "-m", "skewer.tests"] + passthrough_args) @command -def coverage(): +def coverage(verbose=False, quiet=False): """ Run the tests and measure code coverage """ - check_program("coverage") with working_env(PYTHONPATH="python"): @@ -48,10 +47,11 @@ def coverage(): run("coverage report") run("coverage html") - print(f"file:{get_current_dir()}/htmlcov/index.html") + if not quiet: + print(f"file:{get_current_dir()}/htmlcov/index.html") @command -def render(): +def render(verbose=False, quiet=False): """ Render README.html from README.md """ @@ -59,12 +59,12 @@ def render(): run(f"pandoc -o README.html README.md") - print(f"file:{get_real_path('README.html')}") + if not quiet: + print(f"file:{get_real_path('README.html')}") @command def clean(): - remove(join("python", "__pycache__")) - remove(join("test-example", "python", "__pycache__")) + remove(find(".", "__pycache__")) remove("README.html") remove("htmlcov") remove(".coverage") diff --git a/external/plano-main/src/plano/_tests.py b/external/plano-main/src/plano/_tests.py index ebc3dcc..c16ff98 100644 --- a/external/plano-main/src/plano/_tests.py +++ b/external/plano-main/src/plano/_tests.py @@ -73,26 +73,26 @@ def __init__(self): self.parser.add_argument("--explode", action="store_true") self.parser.add_argument("--verbose", action="store_true") self.parser.add_argument("--quiet", action="store_true") - self.parser.add_argument("--init-only", action="store_true") def parse_args(self, args): return self.parser.parse_args(args) def init(self, args): - self.verbose = args.verbose self.interrupt = args.interrupt self.explode = args.explode + self.verbose = args.verbose + self.quiet = args.quiet def run(self): - if self.verbose: - print("Hello") - if self.interrupt: raise KeyboardInterrupt() if self.explode: raise PlanoError("Exploded") + if self.verbose: + print("Hello") + SomeCommand().main([]) SomeCommand().main(["--interrupt"]) @@ -1186,7 +1186,6 @@ def run_command(*args): run_command() run_command("--help") run_command("--quiet") - run_command("--init-only") with expect_system_exit(): run_command("no-such-command") diff --git a/external/plano-main/src/plano/command.py b/external/plano-main/src/plano/command.py index 82310f6..7bfe528 100644 --- a/external/plano-main/src/plano/command.py +++ b/external/plano-main/src/plano/command.py @@ -27,20 +27,14 @@ import traceback as _traceback class BaseCommand: - default_logging_level = "warning" - verbose_logging_level = "notice" - quiet_logging_level = "error" - - def __init__(self): - self.verbose = False - self.quiet = False - self.init_only = False - def parse_args(self, args): # pragma: nocover raise NotImplementedError() - def init(self, args): # pragma: nocover - pass + def configure_logging(self, args): + return "warning", None + + def init(self, args): + raise NotImplementedError() def run(self): # pragma: nocover raise NotImplementedError() @@ -53,21 +47,11 @@ def main(self, args=None): assert isinstance(args, _argparse.Namespace), args - level = self.default_logging_level - - if self.verbose: - level = self.verbose_logging_level - - if self.quiet: - level = self.quiet_logging_level + level, output = self.configure_logging(args) - with logging_enabled(level=level): + with logging_enabled(level=level, output=output): try: self.init(args) - - if self.init_only: - return - self.run() except KeyboardInterrupt: pass @@ -90,13 +74,7 @@ def __init__(self, **kwargs): _plano_command = None class PlanoCommand(BaseCommand): - default_logging_level = "notice" - verbose_logging_level = "debug" - quiet_logging_level = "error" - def __init__(self, module=None, description="Run commands defined as Python functions", epilog=None): - super().__init__() - self.module = module self.bound_commands = dict() self.running_commands = list() @@ -155,6 +133,16 @@ def parse_args(self, args): return args + def configure_logging(self, args): + if args.command is not None: + if args.verbose: + return "debug", None + + if args.quiet: + return "warning", None + + return "notice", None + def init(self, args): self.help = args.help @@ -163,10 +151,8 @@ def init(self, args): self.command_kwargs = dict() if args.command is not None: - # These args are taken from the subcommand self.verbose = args.verbose self.quiet = args.quiet - self.init_only = args.init_only for command in self.preceding_commands: command() @@ -199,8 +185,9 @@ def run(self): with Timer() as timer: self.selected_command(*self.command_args, **self.command_kwargs) - cprint("OK", color="green", file=_sys.stderr, end="") - cprint(" ({})".format(format_duration(timer.elapsed_time)), color="magenta", file=_sys.stderr) + if not self.quiet: + cprint("OK", color="green", file=_sys.stderr, end="") + cprint(" ({})".format(format_duration(timer.elapsed_time)), color="magenta", file=_sys.stderr) def _load_module(self, name): try: @@ -269,11 +256,9 @@ def _process_commands(self): help="Print detailed logging to the console") subparser.add_argument("--quiet", action="store_true", help="Print no logging to the console") - subparser.add_argument("--init-only", action="store_true", - help=_argparse.SUPPRESS) for param in command.parameters.values(): - if param.name in ("verbose", "quiet", "init_only"): + if param.name in ("verbose", "quiet"): continue if param.positional: @@ -431,20 +416,22 @@ def __call__(self, *args, **kwargs): app.running_commands.append(self) - dashes = "--- " * (len(app.running_commands) - 1) - display_args = list(self._get_display_args(args, kwargs)) + if not app.quiet: + dashes = "--- " * (len(app.running_commands) - 1) + display_args = list(self._get_display_args(args, kwargs)) - with console_color("magenta", file=_sys.stderr): - eprint("{}--> {}".format(dashes, self.name), end="") + with console_color("magenta", file=_sys.stderr): + eprint("{}--> {}".format(dashes, self.name), end="") - if display_args: - eprint(" ({})".format(", ".join(display_args)), end="") + if display_args: + eprint(" ({})".format(", ".join(display_args)), end="") - eprint() + eprint() self.function(*args, **kwargs) - cprint("{}<-- {}".format(dashes, self.name), color="magenta", file=_sys.stderr) + if not app.quiet: + cprint("{}<-- {}".format(dashes, self.name), color="magenta", file=_sys.stderr) app.running_commands.pop() diff --git a/external/plano-main/src/plano/test.py b/external/plano-main/src/plano/test.py index 8450889..999fa0e 100644 --- a/external/plano-main/src/plano/test.py +++ b/external/plano-main/src/plano/test.py @@ -29,8 +29,6 @@ class PlanoTestCommand(BaseCommand): def __init__(self, test_modules=[]): - super().__init__() - self.test_modules = test_modules if _inspect.ismodule(self.test_modules): @@ -59,8 +57,6 @@ def __init__(self, test_modules=[]): help="Print detailed logging to the console") self.parser.add_argument("--quiet", action="store_true", help="Print no logging to the console") - self.parser.add_argument("--init-only", action="store_true", - help=_argparse.SUPPRESS) def parse_args(self, args): return self.parser.parse_args(args) @@ -74,6 +70,8 @@ def init(self, args): self.timeout = args.timeout self.fail_fast = args.fail_fast self.iterations = args.iterations + self.verbose = args.verbose + self.quiet = args.quiet try: for name in args.module: