Skip to content

Commit ce758dc

Browse files
committed
add more docs
1 parent daea4c6 commit ce758dc

File tree

10 files changed

+198
-36
lines changed

10 files changed

+198
-36
lines changed

caf/cli/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
logging.getLogger('caf').setLevel(int(os.environ.get('CAF_DEBUG', logging.INFO)))
3030

3131

32-
@click.group(chain=True)
32+
@click.group()
3333
@click.pass_context
3434
def cli(ctx: click.Context) -> None:
3535
ctx.ensure_object(App)
@@ -38,6 +38,7 @@ def cli(ctx: click.Context) -> None:
3838
@cli.command()
3939
@click.pass_obj
4040
def init(app: App) -> None:
41+
"""Initialize a Git repository."""
4142
app.ensure_cafdir()
4243

4344

@@ -87,6 +88,7 @@ def run(
8788
maxerror: int,
8889
rulename: str,
8990
) -> None:
91+
"""Run a given rule."""
9092
rule = import_fullname(rulename)
9193
task_filter = TaskFilter(pattern, no_path=not path)
9294
exception_buffer = ExceptionBuffer(maxerror)
@@ -104,6 +106,7 @@ def run(
104106
@click.argument('rulename', metavar='RULE', envvar='CAF_RULE')
105107
@click.pass_obj
106108
def status(app: App, rulename: str, pattern: List[str]) -> None:
109+
"""Print status of tasks."""
107110
rule = import_fullname(rulename)
108111
sess = app.session(warn=False, readonly=True, full_restore=True)
109112
ncols = len(STATE_COLORS) + 1
@@ -144,6 +147,7 @@ def status(app: App, rulename: str, pattern: List[str]) -> None:
144147
@click.argument('rulename', metavar='RULE', envvar='CAF_RULE')
145148
@click.pass_obj
146149
def graph(app: App, rulename: str) -> None:
150+
"""Open a pdf with the task graph."""
147151
rule = import_fullname(rulename)
148152
sess = app.session(warn=False, readonly=True, full_restore=True)
149153
with sess:
@@ -169,6 +173,7 @@ def checkout(
169173
done: bool,
170174
copy: bool,
171175
) -> None:
176+
"""Checkout path-labeled tasks into a directory tree."""
172177
if blddir.exists() and force:
173178
shutil.rmtree(blddir)
174179
blddir.mkdir()

caf/rules/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .rules import Rule, HookedRule, with_hook, labelled
2-
from .dirtask import dir_task
2+
from .dirtask import dir_task, DirtaskTmpdir

caf/rules/dirtask.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737

3838

3939
class HashingPath(ABC):
40+
"""Represents a path that guarantees immutability."""
41+
4042
@property
4143
@abstractmethod
4244
def path(self) -> Path:
45+
"""the actual path"""
4346
...
4447

4548

@@ -104,6 +107,12 @@ def checkout_files(
104107

105108

106109
class DirtaskTmpdir:
110+
"""
111+
Context manager of a temporary directory that collects created files.
112+
113+
:param output_filter: true for files to be collected
114+
"""
115+
107116
def __init__(self, output_filter: Callable[[str], bool] = None) -> None:
108117
sess = Session.active()
109118
fmngr = sess.storage.get('dir_task:file_manager')
@@ -143,6 +152,10 @@ def __exit__(self, exc_type: Any, *args: Any) -> None:
143152
self._ctx.__exit__(exc_type, *args)
144153

145154
def result(self) -> DirTaskResult:
155+
"""
156+
The collection of files created in the temporary directory. This is
157+
available only after leaving the context.
158+
"""
146159
return self._outputs
147160

148161

@@ -151,6 +164,10 @@ def result(self) -> DirTaskResult:
151164
async def dir_task(
152165
exe: Union[HashingPath, bytes], inputs: Dict[str, Union[HashingPath, bytes, Path]]
153166
) -> DirTaskResult:
167+
"""
168+
Task rule with an executable and a collection of files as inputs and a
169+
collection of output files as output.
170+
"""
154171
dirtask_tmpdir = DirtaskTmpdir(lambda p: p != EXE_NAME and p not in inputs)
155172
with dirtask_tmpdir as tmpdir:
156173
checkout_files(tmpdir, exe, inputs)

caf/rules/rules.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
import inspect
5+
from functools import wraps
56
from typing import Any, Callable, TypeVar, Generic, Tuple, Optional, cast
67

78
from ..tasks import Task, Corofunc
@@ -25,6 +26,7 @@ def __init__(self, corofunc: Corofunc[_T]) -> None:
2526
raise CafError(f'Task function is not a coroutine: {corofunc}')
2627
self._corofunc = corofunc
2728
self._label: Optional[str] = None
29+
wraps(corofunc)(self)
2830

2931
def __call__(self, *args: Any, **kwargs: Any) -> Task[_T]:
3032
kwargs.setdefault('label', self._label)

caf/sci/aims/aims.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ def _func_hash(self) -> str:
2525

2626

2727
class Aims(Pluggable):
28+
"""Instances of this class are task factories that create directory tasks
29+
that represent calculations with FHI-aims.
30+
"""
31+
2832
def __init__(self) -> None:
2933
Pluggable.__init__(self)
3034
for factory in default_plugins:
3135
factory()(self)
3236

3337
def __call__(self, *, label: str = None, **kwargs: Any) -> Task[DirTaskResult]:
38+
"""Create an FHI-aims.
39+
40+
:param kwargs: processed by individual plugins
41+
"""
3442
self.run_plugins('process', kwargs, start=None)
3543
script = kwargs.pop('script').encode()
3644
inputs = {name: cont.encode() for name, cont in kwargs.pop('inputs')}
@@ -73,6 +81,9 @@ def process(self, kwargs: Dict[str, Any]) -> None:
7381

7482

7583
class SpeciesDefaults(AimsPlugin):
84+
"""Aims plugin that handles adding species defaults to control.in.
85+
"""
86+
7687
def __init__(self, mod: Callable[..., Any] = None) -> None:
7788
self._species_defs: Dict[Tuple[Path, str], Dict[str, Any]] = {}
7889
self._mod = mod

caf/sci/aims/parse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
@Rule
1414
async def parse_aims(outputs: Dict[str, bytes]) -> Any:
15+
"""Task rule with an output of :class:`caf.sci.aims.Aims` as input and a
16+
dictionary of parsed results as output.
17+
"""
1518
stdout = outputs['results.xml'].decode()
1619
parsed = parse_xml(io.StringIO(stdout))
1720
energies = {x['name']: x['value'][0] for x in parsed['energy']}

0 commit comments

Comments
 (0)