|
| 1 | +import pathlib |
| 2 | + |
| 3 | +import click |
| 4 | + |
| 5 | +from mpcontribs.lux.cli.display.tree import visualize_scaffold |
| 6 | +from mpcontribs.lux.cli.project.utils import build_scaffold |
| 7 | + |
| 8 | + |
| 9 | +@click.command() |
| 10 | +@click.option("--user-space", default=None) |
| 11 | +@click.option("--projects", multiple=True, default=None) |
| 12 | +@click.option("--structure", type=click.Choice(["directory", "module"]), default=None) |
| 13 | +@click.option("--include-analysis", is_flag=True, default=True) |
| 14 | +@click.option("--include-pipeline", is_flag=True, default=True) |
| 15 | +@click.option("--include-readme", is_flag=True, default=True) |
| 16 | +@click.option("--extra-reqs", is_flag=True, default=True) |
| 17 | +def scaffold( |
| 18 | + user_space, |
| 19 | + projects, |
| 20 | + structure, |
| 21 | + include_analysis, |
| 22 | + include_pipeline, |
| 23 | + include_readme, |
| 24 | + extra_reqs, |
| 25 | +): |
| 26 | + if any([not x for x in (user_space, structure, projects)]): |
| 27 | + user_space = click.prompt("Name space for user project") |
| 28 | + structure = click.prompt("Structure of user project [directory, module]") |
| 29 | + projects = click.prompt( |
| 30 | + "Project names to scaffold in user project name space" |
| 31 | + ).split(" ") |
| 32 | + include_analysis = click.confirm("Include analysis module?") |
| 33 | + include_pipeline = click.confirm("Include pipeline module?") |
| 34 | + include_readme = click.confirm("Include project README.md?") |
| 35 | + extra_reqs = click.confirm( |
| 36 | + "Include file for extra python requirements/libraries?" |
| 37 | + ) |
| 38 | + |
| 39 | + projects = set(projects) |
| 40 | + |
| 41 | + click.echo( |
| 42 | + "The following project scaffold will be created in 'mpcontribs-lux.mpcontribs.projects':" |
| 43 | + ) |
| 44 | + visualize_scaffold( |
| 45 | + user_space, |
| 46 | + projects, |
| 47 | + structure, |
| 48 | + include_analysis, |
| 49 | + include_pipeline, |
| 50 | + include_readme, |
| 51 | + extra_reqs, |
| 52 | + ) |
| 53 | + if click.confirm("Proceed? y/N", abort=True): |
| 54 | + user_space_root = pathlib.Path(__file__).parent.parent.parent.joinpath( |
| 55 | + "projects", user_space |
| 56 | + ) |
| 57 | + |
| 58 | + user_space_root.mkdir() |
| 59 | + |
| 60 | + build_scaffold( |
| 61 | + user_space_root, |
| 62 | + user_space, |
| 63 | + projects, |
| 64 | + structure, |
| 65 | + include_analysis, |
| 66 | + include_pipeline, |
| 67 | + include_readme, |
| 68 | + extra_reqs, |
| 69 | + ) |
| 70 | + click.echo( |
| 71 | + f"Project scaffold created at 'mpcontribs-lux.mpcontribs.projects.{user_space}'!" |
| 72 | + ) |
0 commit comments