forked from cpp-lln-lab/bidsMReye
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethods.py
More file actions
69 lines (52 loc) · 1.74 KB
/
methods.py
File metadata and controls
69 lines (52 loc) · 1.74 KB
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
62
63
64
65
66
67
68
69
"""Write method section."""
from __future__ import annotations
import shutil
import warnings
from pathlib import Path
from bidsmreye._version import __version__
from bidsmreye.defaults import available_models, default_model
from bidsmreye.report import TEMPLATES_DIR, return_jinja_env
from bidsmreye.utils import create_dir_for_file
def methods(
output_dir: str | Path | None = None,
model: str | None = None,
qc_only: bool = False,
) -> Path:
"""Write method section.
:param output_dir: Defaults to Path(".")
:type output_dir: Union[str, Path], optional
:param model: Defaults to None.
:type model: str, optional
:return: Output file name.
:rtype: Path
"""
if output_dir is None:
output_dir = Path()
if isinstance(output_dir, str):
output_dir = Path(output_dir)
output_dir = output_dir / "logs"
output_file = output_dir / "CITATION.md"
create_dir_for_file(output_file)
bib_file = str(Path(__file__).parent / "templates" / "CITATION.bib")
shutil.copy(bib_file, output_dir)
if not model:
model = default_model()
is_known_model = False
is_default_model = False
if model in available_models():
is_known_model = True
if model == default_model():
is_default_model = True
if not is_known_model:
warnings.warn(f"{model} is not a known model name.", stacklevel=3)
env = return_jinja_env(searchpath=TEMPLATES_DIR)
template = env.get_template("CITATION.jinja")
output = template.render(
version=__version__,
model=model,
is_default_model=is_default_model,
is_known_model=is_known_model,
qc_only=qc_only,
)
output_file.write_text(output)
return output_file