Skip to content

Commit

Permalink
0.7.3 (#159)
Browse files Browse the repository at this point in the history
* ✨ Add `--list` for `pipen profile` to list the names of available profiles

* ✨ Add exception hook to show uncaught in log

* ✨ Add `on_job_cached` hook

* 🔖 0.7.3
  • Loading branch information
pwwang authored Apr 10, 2023
1 parent 3a632ed commit d101acf
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 81 deletions.
11 changes: 11 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## 0.7.3

- ✨ Add `--list` for `pipen profile` to list the names of available profiles
- ✨ Add exception hook to show uncaught in log
- ✨ Add `on_job_cached` hook

## 0.7.2

- ✨ Add `utils.mark` and `get_marked` to mark a process
Unlike plugin_opts, template_opts or envs, these marks are not inherited in subclasses

## 0.7.1

- ⬆️ Upgrade simplug to 0.2.3
Expand Down
11 changes: 11 additions & 0 deletions pipen/cli/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def __init__(
default="",
help="The name of the profile to show. Show all if not provided.",
)
subparser.add_argument(
"-l",
"--list",
action="store_true",
default=False,
help="List the names of all available profiles (-n won't work).",
)

def exec_command(self, args: Namespace) -> None:
"""Run the command"""
Expand All @@ -45,6 +52,10 @@ def exec_command(self, args: Namespace) -> None:
ignore_nonexist=True,
)

if args.list:
print("\n".join(ProfileConfig.profiles(config)))
return

print("Configurations loaded from:")
print("- pipen.defaults.CONFIG (python dictionary)")
for conffile in reversed(CONFIG_FILES):
Expand Down
10 changes: 10 additions & 0 deletions pipen/pluginmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ async def on_job_succeeded(proc: Proc, job: Job):
"""


@plugin.spec
async def on_job_cached(proc: Proc, job: Job):
"""When a job is cached.
Args:
proc: The process
job: The job
"""


@plugin.spec
async def on_job_failed(proc: Proc, job: Job):
"""When a job is done but failed.
Expand Down
1 change: 1 addition & 0 deletions pipen/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ async def run(self) -> None:
self.pbar.update_job_running()
self.pbar.update_job_succeeded()
job.status = JobStatus.FINISHED
await plugin.hooks.on_job_cached(self, job)
else:
await self.xqute.put(job)
if cached_jobs:
Expand Down
25 changes: 25 additions & 0 deletions pipen/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Provide some utilities"""
from __future__ import annotations

import sys
import logging
import textwrap
import typing
from itertools import groupby
from operator import itemgetter
from io import StringIO
Expand All @@ -21,6 +23,8 @@
Type,
)

import diot
import simplug
from rich.console import Console
from rich.logging import RichHandler as _RichHandler
from rich.table import Table
Expand Down Expand Up @@ -106,12 +110,33 @@ def _render_buffer(self, buffer: Iterable[Segment]) -> str:
omit_repeated_times=False, # rich 10+
markup=True,
log_time_format="%m-%d %H:%M:%S",
tracebacks_extra_lines=0,
tracebacks_suppress=[simplug, diot, typing],
)
_logger_handler.setFormatter(
logging.Formatter("[purple]%(plugin_name)-7s[/purple] %(message)s")
)


def _excepthook(
type_: Type[BaseException],
value: BaseException,
traceback: Any,
) -> None:
"""The excepthook for pipen, to show rich traceback"""
if type_ is KeyboardInterrupt: # pragma: no cover
logger.error("Interrupted by user")
return

logger.exception(
f"{type_.__name__}: {value}",
exc_info=(type_, value, traceback),
)


sys.excepthook = _excepthook


def get_logger(
name: str = LOGGER_NAME,
level: str | int = None,
Expand Down
2 changes: 1 addition & 1 deletion pipen/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Provide version of pipen"""

__version__ = "0.7.2"
__version__ = "0.7.3"
138 changes: 59 additions & 79 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"

[tool.poetry]
name = "pipen"
version = "0.7.2"
version = "0.7.3"
description = "A pipeline framework for python"
authors = [ "pwwang <[email protected]>",]
license = "MIT"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def test_help():
def test_profile_all():
out = cmdoutput(["pipen", "profile"])
assert "Note:" in out
out = cmdoutput(["pipen", "profile", "--list"])
assert "default" in out


def test_profile_default():
Expand Down

0 comments on commit d101acf

Please sign in to comment.