From 8e8b5aba96c9a0099830f08065f637275d410101 Mon Sep 17 00:00:00 2001 From: sapetnioc Date: Fri, 7 Jun 2024 08:53:59 +0200 Subject: [PATCH] #7 --- activate.sh | 4 +- bin/neuro-forge | 115 +++++++++++++++++++++++++----------------------- pixi.toml | 5 ++- 3 files changed, 67 insertions(+), 57 deletions(-) diff --git a/activate.sh b/activate.sh index 8e81d2b..6b3540e 100644 --- a/activate.sh +++ b/activate.sh @@ -1,2 +1,2 @@ -export PYTHONPATH="$PIXI_PROJECT_ROOT/python:$PIXI_PROJECT_ROOT/soma-forge/python":$PYTHONPATH -export PATH="$PIXI_PROJECT_ROOT/bin:$PIXI_PROJECT_ROOT/soma-forge/bin:$PATH" +export PYTHONPATH="$PIXI_PROJECT_ROOT/python:$PYTHONPATH +export PATH="$PIXI_PROJECT_ROOT/bin:$PATH" diff --git a/bin/neuro-forge b/bin/neuro-forge index a08fd57..a5845a7 100755 --- a/bin/neuro-forge +++ b/bin/neuro-forge @@ -1,69 +1,76 @@ #!/usr/bin/env python -import fire +import click from itertools import chain -import os from pathlib import Path import shutil from subprocess import check_call -class Commands: - @staticmethod - def init(channel_dir: str): - """Initialise a new channel directory""" - # Create an empty channel - channel_dir = Path(channel_dir).absolute() - if not channel_dir.exists(): - check_call( - [ - "datalad", - "create", - "--description", - "Neuro-forge channel : https://brainvisa.info/neuro-forge", - str(channel_dir), - ] - ) - save_datalad = True - else: - save_datalad = False - (channel_dir / "noarch").mkdir(exist_ok=True) - (channel_dir / "linux-64").mkdir(exist_ok=True) - check_call(["conda", "index", channel_dir]) +@click.group(context_settings={"help_option_names": ["-h", "--help"]}) +def main(): + pass - # Create base packages - neuro_forge = Path(__file__).parent.parent - for recipe_dir in chain( - [neuro_forge / "soma-forge"], (neuro_forge / "recipes").iterdir() - ): - if not (recipe_dir / "recipe.yaml").exists(): - continue - command = [ - "env", - f"HOME={channel_dir}", - "rattler-build", - "build", - "-r", - str(recipe_dir), - "--output-dir", + +@main.command() +@click.argument("channel_dir", type=click.Path()) +def init(channel_dir): + """Initialise a new channel directory + + CHANNEL_DIR directory where packages are going to be created + """ + # Create an empty channel + channel_dir = Path(channel_dir).absolute() + if not channel_dir.exists(): + check_call( + [ + "datalad", + "create", + "--description", + "Neuro-forge channel : https://brainvisa.info/neuro-forge", str(channel_dir), ] - variants = recipe_dir / "variants.yaml" - if variants.exists(): - command.extend(["-m", str(variants)]) - check_call(command) + ) + save_datalad = True + else: + save_datalad = False + (channel_dir / "noarch").mkdir(exist_ok=True) + (channel_dir / "linux-64").mkdir(exist_ok=True) + check_call(["conda", "index", channel_dir]) + + # Create base packages + neuro_forge = Path(__file__).parent.parent + for recipe_dir in chain( + [neuro_forge / "soma-forge"], (neuro_forge / "recipes").iterdir() + ): + if not (recipe_dir / "recipe.yaml").exists(): + continue + command = [ + "env", + f"HOME={channel_dir}", + "rattler-build", + "build", + "-r", + str(recipe_dir), + "--output-dir", + str(channel_dir), + ] + variants = recipe_dir / "variants.yaml" + if variants.exists(): + command.extend(["-m", str(variants)]) + check_call(command) - # Cleanup and create channel index - for i in ("bld", "src_cache", ".rattler", ".cache"): - to_delete = channel_dir / i - if to_delete.exists(): - shutil.rmtree(to_delete) - check_call(["conda", "index", channel_dir]) - if save_datalad: - check_call( - ["datalad", "save", "-m", "Created initial packages", str(channel_dir)] - ) + # Cleanup and create channel index + for i in ("bld", "src_cache", ".rattler", ".cache"): + to_delete = channel_dir / i + if to_delete.exists(): + shutil.rmtree(to_delete) + check_call(["conda", "index", channel_dir]) + if save_datalad: + check_call( + ["datalad", "save", "-m", "Created initial packages", str(channel_dir)] + ) if __name__ == "__main__": - fire.Fire(Commands) + main() diff --git a/pixi.toml b/pixi.toml index 5f5703b..80a615a 100644 --- a/pixi.toml +++ b/pixi.toml @@ -11,11 +11,14 @@ scripts = ["activate.sh"] [tasks] [dependencies] -python = "*" +python = "> 2" conda-build = "*" rattler-build = "*" fire = "*" +click = "*" +rich = "*" git = "*" +gitpython = "*" pip = "*" toml = "*" pyaml = "*"