Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support output_dir override #170 #171

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions dcm2bids/scaffold/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import shutil
import importlib.resources as resources
from typing import Optional
from ..utils import write_txt


Expand Down Expand Up @@ -34,27 +35,28 @@ def _get_arguments():
return args


def scaffold():
def scaffold(output_dir_override: Optional[str] = None):
"""scaffold entry point"""
args = _get_arguments()
output_dir_ = output_dir_override if output_dir_override is not None else args.output_dir

for _ in ["code", "derivatives", "sourcedata"]:
os.makedirs(os.path.join(args.output_dir, _), exist_ok=True)
os.makedirs(os.path.join(output_dir_, _), exist_ok=True)

for _ in [
"dataset_description.json",
"participants.json",
"participants.tsv",
"README",
]:
dest = os.path.join(args.output_dir, _)
dest = os.path.join(output_dir_, _)
with resources.path(__name__, _) as src:
shutil.copyfile(src, dest)

with resources.path(__name__, "CHANGES") as changes_template:
with open(changes_template) as _:
data = _.read().format(datetime.date.today().strftime("%Y-%m-%d"))
write_txt(
os.path.join(args.output_dir, "CHANGES"),
os.path.join(output_dir_, "CHANGES"),
data.split("\n")[:-1],
)