Skip to content

Commit

Permalink
0.7.0 (#156)
Browse files Browse the repository at this point in the history
* ⬆️ Update liquidpy to 0.8

* 🎨 Put procgroup in Proc.__meta__, which is not inherited when subclassing

* ⚡️ Do not mutate Proc.__doc__ when subclassing

* ⚡️ Use mro to detect parent class of a Proc

* 🔖 0.7.0
  • Loading branch information
pwwang authored Mar 29, 2023
1 parent 1c4724f commit 1ab9fc3
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 97 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if __name__ == "__main__":
[09/13/21 04:23:37] I main _ ____/__/ / _ ____/_ /___ _ /| /
[09/13/21 04:23:37] I main /_/ /___/ /_/ /_____/ /_/ |_/
[09/13/21 04:23:37] I main
[09/13/21 04:23:37] I main version: 0.6.0
[09/13/21 04:23:37] I main version: 0.7.0
[09/13/21 04:23:37] I main
[09/13/21 04:23:37] I main ╭═════════════════════════════ MYPIPELIN ═══════════════════════════════╮
[09/13/21 04:23:37] I main ║ # procs = 2 ║
Expand Down
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## 0.7.0

- ⬆️ Update liquidpy to 0.8
- ✨ Add `Proc.__meta__` that will not be inherited when subclassing
- 🎨 Put `procgroup` in `Proc.__meta__`
- ⚡️ Do not mutate `Proc.__doc__` when subclassing
- ⚡️ Use mro to detect parent class of a Proc

## 0.6.4

- 🔀 Set desc from docstring if not given for pipelines
Expand Down
40 changes: 21 additions & 19 deletions pipen/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@

if TYPE_CHECKING: # pragma: no cover
from .pipen import Pipen
from .procgroup import ProcGroup


class ProcMeta(ABCMeta):
Expand Down Expand Up @@ -179,7 +178,10 @@ class Proc(ABC, metaclass=ProcMeta):
nexts: Sequence[Type[Proc]] = None
output_data: Any = None
workdir: PathLike = None
__procgroup__: ProcGroup | None = None
# metadata that marks the process
# Can also be used for plugins
# It's not inheirted
__meta__: Mapping[str, Any] = None

@classmethod
def from_proc(
Expand Down Expand Up @@ -272,36 +274,36 @@ def from_proc(

kwargs["__doc__"] = proc.__doc__
out = type(name, (proc,), kwargs)
out.__procgroup__ = None
return out

def __init_subclass__(cls) -> None:
"""Do the requirements inferring since we need them to build up the
process relationship
"""
# Use __mro__?
parent = cls.__bases__[-1]
base = [
mro
for mro in cls.__mro__
if issubclass(mro, Proc) and mro is not Proc and mro is not cls
]
parent = base[0] if base else None
# cls.requires = cls._compute_requires()
# triggers cls.__setattr__() to compute requires
cls.nexts = []
cls.requires = cls.requires

if cls.name is None or cls.name == parent.name:
if cls.name is None or (parent and cls.name == parent.name):
cls.name = cls.__name__

if cls.__doc__ is None:
cls.__doc__ = (
parent.__doc__
if parent is not Proc
else "Undescribed process."
)

cls.envs = update_dict(parent.envs, cls.envs)
cls.plugin_opts = update_dict(parent.plugin_opts, cls.plugin_opts)
cls.envs = update_dict(parent.envs if parent else None, cls.envs)
cls.plugin_opts = update_dict(
parent.plugin_opts if parent else None,
cls.plugin_opts,
)
cls.scheduler_opts = update_dict(
parent.scheduler_opts, cls.scheduler_opts
parent.scheduler_opts if parent else {},
cls.scheduler_opts,
)
cls.__procgroup__ = None
cls.__meta__ = {"procgroup": None}

def __init__(self, pipeline: Pipen = None) -> None:
"""Constructor
Expand Down Expand Up @@ -676,8 +678,8 @@ def _compute_script(self) -> Template:
def _log_info(self):
"""Log some basic information of the process"""
title = (
f"{self.__procgroup__.name}/{self.name}"
if self.__procgroup__
f"{self.__meta__['procgroup'].name}/{self.name}"
if self.__meta__["procgroup"]
else self.name
)
panel = Panel(
Expand Down
4 changes: 2 additions & 2 deletions pipen/procgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def add_proc(
)

setattr(self_or_method, proc.name, proc)
proc.__procgroup__ = self_or_method
proc.__meta__["procgroup"] = self_or_method # type: ignore
if not proc.requires:
self_or_method.starts.append(proc)
self_or_method.procs[proc.name] = proc
Expand All @@ -152,7 +152,7 @@ def wrapper(self):
"(either a subclass or an instance of Proc)"
)

proc.__procgroup__ = self
proc.__meta__["procgroup"] = self
if not proc.requires:
self.starts.append(proc)
self.procs[proc.name] = proc
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.6.4"
__version__ = "0.7.0"
Loading

0 comments on commit 1ab9fc3

Please sign in to comment.