From 1eb9d494c79bc560fbd126cbe9e52f8f6f7772c5 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 14 Nov 2020 19:51:15 +0100 Subject: [PATCH] not specific to Orientation class --- python/damask/_orientation.py | 44 +++++++++++------------------------ python/damask/util.py | 20 ++++++++++++++-- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index e0a00e0a0..c849b0d89 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -4,7 +4,7 @@ from . import Rotation from . import util from . import mechanics -__parameter_doc__ = \ +_parameter_doc = \ """lattice : str Either a crystal family out of [triclinic, monoclinic, orthorhombic, tetragonal, hexagonal, cubic] or a Bravais lattice out of [aP, mP, mS, oP, oS, oI, oF, tP, tI, hP, cP, cI, cF]. @@ -27,22 +27,6 @@ __parameter_doc__ = \ """ -def extend_docstring(): - """Decorator: Append Orientation parameter documentation to function's docstring.""" - def _decorator(func): - func.__doc__ += __parameter_doc__ - return func - return _decorator - - -def extended_docstring(f): - """Decorator: Combine Orientation parameter documentation with another function's docstring.""" - def _decorator(func): - func.__doc__ = f.__doc__ + __parameter_doc__ - return func - return _decorator - - class Orientation(Rotation): """ Representation of crystallographic orientation as combination of rotation and either crystal family or Bravais lattice. @@ -128,7 +112,7 @@ class Orientation(Rotation): } - @extend_docstring() + @util.extend_docstring(_parameter_doc) def __init__(self, rotation = None, lattice = None, @@ -279,73 +263,73 @@ class Orientation(Rotation): @classmethod - @extended_docstring(Rotation.from_random) + @util.extended_docstring(Rotation.from_random,_parameter_doc) def from_random(cls,**kwargs): return cls(rotation=Rotation.from_random(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_quaternion) + @util.extended_docstring(Rotation.from_quaternion,_parameter_doc) def from_quaternion(cls,**kwargs): return cls(rotation=Rotation.from_quaternion(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_Eulers) + @util.extended_docstring(Rotation.from_Eulers,_parameter_doc) def from_Eulers(cls,**kwargs): return cls(rotation=Rotation.from_Eulers(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_axis_angle) + @util.extended_docstring(Rotation.from_axis_angle,_parameter_doc) def from_axis_angle(cls,**kwargs): return cls(rotation=Rotation.from_axis_angle(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_basis) + @util.extended_docstring(Rotation.from_basis,_parameter_doc) def from_basis(cls,**kwargs): return cls(rotation=Rotation.from_basis(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_matrix) + @util.extended_docstring(Rotation.from_matrix,_parameter_doc) def from_matrix(cls,**kwargs): return cls(rotation=Rotation.from_matrix(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_Rodrigues) + @util.extended_docstring(Rotation.from_Rodrigues,_parameter_doc) def from_Rodrigues(cls,**kwargs): return cls(rotation=Rotation.from_Rodrigues(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_homochoric) + @util.extended_docstring(Rotation.from_homochoric,_parameter_doc) def from_homochoric(cls,**kwargs): return cls(rotation=Rotation.from_homochoric(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_cubochoric) + @util.extended_docstring(Rotation.from_cubochoric,_parameter_doc) def from_cubochoric(cls,**kwargs): return cls(rotation=Rotation.from_cubochoric(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_spherical_component) + @util.extended_docstring(Rotation.from_spherical_component,_parameter_doc) def from_spherical_component(cls,**kwargs): return cls(rotation=Rotation.from_spherical_component(**kwargs),**kwargs) @classmethod - @extended_docstring(Rotation.from_fiber_component) + @util.extended_docstring(Rotation.from_fiber_component,_parameter_doc) def from_fiber_component(cls,**kwargs): return cls(rotation=Rotation.from_fiber_component(**kwargs),**kwargs) @classmethod - @extend_docstring() + @util.extend_docstring(_parameter_doc) def from_directions(cls,uvw,hkl,**kwargs): """ Initialize orientation object from two crystallographic directions. diff --git a/python/damask/util.py b/python/damask/util.py index fa983d64e..d1b3ed842 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -26,8 +26,8 @@ __all__=[ 'return_message', 'extendableOption', 'execution_stamp', - 'shapeshifter', - 'shapeblender', + 'shapeshifter', 'shapeblender', + 'extend_docstring', 'extended_docstring' ] #################################################################################################### @@ -302,6 +302,22 @@ def shapeblender(a,b): return a + b[i:] +def extend_docstring(general): + """Decorator: Append Orientation parameter documentation to function's docstring.""" + def _decorator(func): + func.__doc__ += general + return func + return _decorator + + +def extended_docstring(f,general): + """Decorator: Combine Orientation parameter documentation with another function's docstring.""" + def _decorator(func): + func.__doc__ = f.__doc__ + general + return func + return _decorator + + #################################################################################################### # Classes ####################################################################################################