Skip to content

Commit

Permalink
Merge pull request #171 from GMerakis/patch-1
Browse files Browse the repository at this point in the history
Thank you @GMerakis for this PR. I think this will be the last PR and release before jumping to dcm2bids 3.0.0 with a cleaner and more flexible API.
Support output_dir override #170
  • Loading branch information
arnaudbore authored Jun 17, 2022
2 parents 217bdfb + a761cc6 commit c6fb2ca
Showing 1 changed file with 6 additions and 4 deletions.
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],
)

0 comments on commit c6fb2ca

Please sign in to comment.