/
examples_helper.py
executable file
·61 lines (47 loc) · 1.64 KB
/
examples_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
"""Copy the openff-toolkit examples suite to a local directory"""
import argparse
from os import environ
from pathlib import Path
from shutil import copytree, ignore_patterns
class NoExamplesLibraryError(Exception):
"""Slightly more descriptive error for when the examples library is not found"""
def __init__(self):
message = "\n".join(
(
"Could not find examples library.",
"",
"Is the openff-toolkit-examples Conda package installed?",
)
)
super().__init__(message)
def main():
"""Entrypoint for the script"""
parser = argparse.ArgumentParser(description=__doc__)
default_target = "./examples/"
parser.add_argument(
"--target",
default=default_target,
type=Path,
help=f"Target directory to store the examples suite. Defaults to {default_target}",
)
parser.add_argument(
"--include-deprecated",
action="store_true",
help="Copy over deprecated examples in addition to current examples",
)
args = parser.parse_args()
if args.include_deprecated:
copytree_ignore = None
else:
copytree_ignore = ignore_patterns("deprecated")
target_path = args.target
library_path = Path(environ["CONDA_PREFIX"]) / "share/openff-toolkit/examples"
try:
copytree(library_path, target_path, ignore=copytree_ignore)
except FileNotFoundError as err:
if Path(err.filename) == library_path and err.filename2 is None:
raise NoExamplesLibraryError() from err
raise err
if __name__ == "__main__":
main()