Skip to content

Commit

Permalink
0.9.7 (#168)
Browse files Browse the repository at this point in the history
* πŸ”§ Allow to inherit doc from base class for Pipen/Proc

* πŸ”– 0.9.7
  • Loading branch information
pwwang authored May 1, 2023
1 parent 25c3075 commit 3d60126
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 100 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.9.7

- πŸ”§ Allow to inherit doc from base class for Pipen/Proc

## 0.9.6

- 🎨 Let plugins change and create workdir
Expand Down
4 changes: 3 additions & 1 deletion pipen/pipen.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def __init__(
)

self.desc = (
desc or self.__class__.desc or desc_from_docstring(self.__class__)
desc
or self.__class__.desc
or desc_from_docstring(self.__class__, Pipen)
)
self.outdir = Path(
outdir or self.__class__.outdir or f"./{self.name}-output"
Expand Down
2 changes: 1 addition & 1 deletion pipen/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def __init__(self, pipeline: Pipen = None) -> None:
# Compute the properties
# otherwise, the property can be accessed directly from class vars
if self.desc is None:
self.desc: str = desc_from_docstring(self.__class__)
self.desc: str = desc_from_docstring(self.__class__, Proc)

if self.export is None:
self.export = bool(not self.nexts)
Expand Down
20 changes: 17 additions & 3 deletions pipen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from rich.segment import Segment
from rich.console import RenderableType

from .pipen import Pipen
from .proc import Proc


Expand Down Expand Up @@ -152,7 +153,10 @@ def get_logger(
logger = get_logger()


def desc_from_docstring(obj: Any) -> str:
def desc_from_docstring(
obj: Type[Pipen | Proc],
base: Type[Pipen | Proc],
) -> str:
"""Get the description from docstring
Only extract the summary.
Expand All @@ -163,8 +167,18 @@ def desc_from_docstring(obj: Any) -> str:
Returns:
The summary as desc
"""
if not obj.__doc__: # pragma: no cover
return None
if not obj.__doc__:
# If the docstring is empty, use the base's docstring
# Get the base from mro
bases = [
cls
for cls in obj.__mro__
if is_subclass(cls, base) and cls != base and cls != obj
]
if not bases:
return None

return desc_from_docstring(bases[0], base)

started: bool = False
out: List[str] = []
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.9.6"
__version__ = "0.9.7"
180 changes: 90 additions & 90 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions 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.9.6"
version = "0.9.7"
description = "A pipeline framework for python"
authors = [ "pwwang <[email protected]>",]
license = "MIT"
Expand All @@ -16,7 +16,7 @@ repository = "https://github.com/pwwang/pipen"
generate-setup-file = true

[tool.poetry.dependencies]
python = "^3.8" # align with datar/pandas
python = "^3.8"
liquidpy = "^0.8"
pandas = "^1.4"
enlighten = "^1"
Expand Down
7 changes: 5 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@ def test_get_mtime_dir():


def test_desc_from_docstring():
def obj1():
class Base:
...

class Obj1(Base):
"""
abc
def
"""

desc = desc_from_docstring(obj1)
desc = desc_from_docstring(Obj1, Base)
assert desc == "abc def"


Expand Down

0 comments on commit 3d60126

Please sign in to comment.