• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

maurergroup / dfttoolkit / 11901427337

18 Nov 2024 09:28PM UTC coverage: 22.226% (+0.5%) from 21.747%
11901427337

push

github

39bfaa
web-flow
Merge pull request #15 from maurergroup/run_utils_enhancements

Run utils enhancements

- Made run_utils decorator more user friendly. Arguments are now optionally and specified in the decorator rather than the function being decoraed
- Added tests for run_utils
- Minor docstring improvements 
- CI will now only build docs on PR, and will deploy on push

733 of 3298 relevant lines covered (22.23%)

0.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
dfttoolkit/utils/run_utils.py
1
import os.path
1✔
2
from functools import wraps
1✔
3

4

5
def no_repeat(
1✔
6
    original_func=None,
7
    *,
8
    output_file: str = "aims.out",
9
    calc_dir: str = "./",
10
    force: bool = False,
11
):
12
    """
13
    Don't repeat the calculation if aims.out exists in the calculation directory.
14

15
    Parameters
16
    ----------
17
    output_file : str, default='aims.out'
18
        The name of the output file to check for.
19
    calc_dir : str, default="./"
20
        The directory where the calculation is performed
21
    force : bool, default=False
22
        If True, the calculation is performed even if aims.out exists in the calculation
23
        directory.
24

25
    Raises
26
    -------
27
    ValueError
28
        if the `calc_dir` kwarg is not a directory
29
    """
30

31
    def _no_repeat(func):
1✔
32
        @wraps(func)
1✔
33
        def wrapper(*args, **kwargs):
1✔
34
            if not os.path.isdir(calc_dir):
1✔
35
                raise ValueError(f"{calc_dir} is not a directory.")
1✔
36
            if force:
1✔
37
                return func(*args, **kwargs)
1✔
38
            if not os.path.isfile(f"{calc_dir}/{output_file}"):
1✔
39
                return func(*args, **kwargs)
1✔
40
            else:
41
                print(f"aims.out already exists in {calc_dir}. Skipping calculation.")
1✔
42

43
        return wrapper
1✔
44

45
    if original_func:
1✔
46
        return _no_repeat(original_func)
×
47

48
    return _no_repeat
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc