diff --git a/.github/workflows/mkdocs.yml b/.github/workflows/mkdocs.yml new file mode 100644 index 0000000..8321eb3 --- /dev/null +++ b/.github/workflows/mkdocs.yml @@ -0,0 +1,23 @@ + +name: mkdocs +on: + push: + branches: + - master + - main +permissions: + contents: write +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - uses: actions/cache@v2 + with: + key: ${{ github.ref }} + path: .cache + - run: pip install "mkdocstrings==0.22.0" "mkdocstrings-python==1.3.*" "mkdocs-material" + - run: mkdocs gh-deploy --force diff --git a/README.md b/README.md index e9160b5..1e163c8 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # snk-cli + +The dynamic CLI from [snk](https://snk.wytamma.com/). \ No newline at end of file diff --git a/docs/env.md b/docs/env.md new file mode 100644 index 0000000..cc1ef3b --- /dev/null +++ b/docs/env.md @@ -0,0 +1,109 @@ +--- +title: Environments +--- + +# The CLI env command + +The `env` subcommand in the `workflow` tool allows you to access and manage the conda environments used within the workflow. This guide provides an overview of the available options and commands for working with workflow environments. + +## Options + +- `--help`, `-h`: Show the help message and exit. + +## Commands + +The `env` subcommand provides several commands to manage the workflows conda environments. + +### `list` + +List the environments in the workflow. + +```bash +workflow env list [OPTIONS] +``` + +### `activate` + +Activate a workflow conda environment. + +```bash +workflow env activate [OPTIONS] ENV_NAME +``` + +- `ENV_NAME`: Name of the environment to activate. + +This command activates the specified conda environment within the workflow. + +### `create` + +This command creates all the conda environments specified in the `envs` dir. + +A Snakemake workflow that uses a lot of conda envs can take a long time to install as each env is created sequentially. Running `workflow env create` will create all the conda envs in parallel (up to `--workers` at a time, defaults to number of cores). + +```bash +workflow env create [OPTIONS] [NAME] +``` + +Individual conda envs can be create with `workflow env create ENV_NAME`. + + +### `remove` + +Delete all conda environments. + +```bash +workflow env remove [OPTIONS] +``` + +This command deletes all the conda environments in the workflow. + +### `run` + +The `env run` command in the `workflow` tool allows you to run a command within one of the workflow environments. + +#### Arguments + +- `cmd`: The command to run in the environment. This argument is required. + +#### Options + +- `--env`, `-e`: The name of the environment in which to run the command. +- `--help`, `-h`: Show the help message and exit. + +#### Usage + +To run a command in one of the workflow environments, use the following command format: + +```bash +workflow env run --env ENV_NAME CMD... +``` + +- `CMD...`: The command and its arguments to execute within the specified environment. + +Make sure to replace `ENV_NAME` with the actual name of the desired environment, and `CMD...` with the command you want to run. + +#### Example + +Here's an example command that demonstrates the usage of `workflow env run`: + +```bash +workflow env run -e my_environment "python script.py --input input_file.txt --output output_file.txt" +``` + +This command runs the `python script.py --input input_file.txt --output output_file.txt` command within the `my_environment` environment in the workflow. Adjust the command and environment name according to your specific use case. + + +- `ENV_NAME`: Name of the environment in which to run the command. +- `COMMAND [ARGS]...`: The command and its arguments to execute within the specified environment. + +This command runs the provided command within the specified conda environment in the workflow. + +### `show` + +Show the environments config file contents. + +```bash +workflow env show [OPTIONS] +``` + +This command displays the contents of the environments configuration file used in the workflow. diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..3aabf5b --- /dev/null +++ b/docs/index.md @@ -0,0 +1,19 @@ +--- +title: Home +--- +# snk-cli + +The dynamic CLI from [snk](https://snk.wytamma.com/). + +# The Dynamically Generated Snk CLI + +The primary feature of Snk is dynamic CLI generation. Many aspects of this CLI can be configure though the [Snk config file](/snk_config_file/). + +The CLI provides several commands for interacting with the workflow including + +- config - Access the workflow configuration. +- [env](/CLI/env/) - Access the workflow conda environments. +- [script](/CLI/script/) - Access the workflow scripts. +- info - Display information about the workflow. +- profile - Access the workflow profiles. +- run - Run the Snakemake workflow. diff --git a/docs/reference/cli.md b/docs/reference/cli.md new file mode 100644 index 0000000..6287091 --- /dev/null +++ b/docs/reference/cli.md @@ -0,0 +1,2 @@ +::: src.snk_cli.cli + diff --git a/docs/reference/config.md b/docs/reference/config.md new file mode 100644 index 0000000..1277b57 --- /dev/null +++ b/docs/reference/config.md @@ -0,0 +1,4 @@ +::: src.snk_cli.config.config + +::: src.snk_cli.config.utils + diff --git a/docs/reference/dynamic_typer.md b/docs/reference/dynamic_typer.md new file mode 100644 index 0000000..a652550 --- /dev/null +++ b/docs/reference/dynamic_typer.md @@ -0,0 +1,2 @@ +::: src.snk_cli.dynamic_typer + diff --git a/docs/reference/options.md b/docs/reference/options.md new file mode 100644 index 0000000..5daf56e --- /dev/null +++ b/docs/reference/options.md @@ -0,0 +1,4 @@ +::: src.snk_cli.options.option + +::: src.snk_cli.options.utils + diff --git a/docs/reference/subcommands.md b/docs/reference/subcommands.md new file mode 100644 index 0000000..dedb650 --- /dev/null +++ b/docs/reference/subcommands.md @@ -0,0 +1,12 @@ +::: src.snk_cli.subcommands.run + +::: src.snk_cli.subcommands.config + +::: src.snk_cli.subcommands.env + +::: src.snk_cli.subcommands.profile + +::: src.snk_cli.subcommands.utils + +::: src.snk_cli.subcommands.script + diff --git a/docs/reference/testing.md b/docs/reference/testing.md new file mode 100644 index 0000000..24b24e1 --- /dev/null +++ b/docs/reference/testing.md @@ -0,0 +1,2 @@ +::: src.snk_cli.testing + diff --git a/docs/reference/utils.md b/docs/reference/utils.md new file mode 100644 index 0000000..a710224 --- /dev/null +++ b/docs/reference/utils.md @@ -0,0 +1,2 @@ +::: src.snk_cli.utils + diff --git a/docs/reference/validate.md b/docs/reference/validate.md new file mode 100644 index 0000000..2935cd0 --- /dev/null +++ b/docs/reference/validate.md @@ -0,0 +1,2 @@ +::: src.snk_cli.validate + diff --git a/docs/reference/workflow.md b/docs/reference/workflow.md new file mode 100644 index 0000000..6d3fcb2 --- /dev/null +++ b/docs/reference/workflow.md @@ -0,0 +1,2 @@ +::: src.snk_cli.workflow + diff --git a/docs/script.md b/docs/script.md new file mode 100644 index 0000000..286ef5e --- /dev/null +++ b/docs/script.md @@ -0,0 +1,41 @@ +--- +title: Scripts +--- + +# Script Commands + +The `script` commands allow you to interact with the workflow scripts. Scripts must be located in the `scripts` directory of the workflow. + +## List + +The list command will list all scripts in the workflow. + +```bash +snk script list +``` + +## Show + +The show command will display the contents of a script. + +```bash +snk script show hello.py +``` + +## Run + +The run command will run a script. + +```bash +snk script run hello.py +``` + +!!! note + The executor used to run the script is determined by the suffix of the script file. For example, a script named `hello.py` will be run using the `python` executor. + +Use the `--env` option to specify the environment to run the script in. + +```bash +snk script run --env python hello.py +``` + diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..3d8c346 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,44 @@ + +site_name: snk_cli +# repo_url: https://github.com/wytamma/write-the + +theme: + name: "material" + # homepage: https://write-the.wytamma.com + # logo: assets/logo.png + # favicon: images/favicon.png + palette: + - scheme: default + toggle: + icon: material/brightness-7 + name: Switch to dark mode + - scheme: slate + toggle: + icon: material/brightness-4 + name: Switch to light mode + features: + - toc.follow + - content.action.edit + +extra: + social: + - icon: fontawesome/solid/robot + link: https://github.com/Wytamma/write-the + name: Generated with write-the + +plugins: +- search +- mkdocstrings: + handlers: + python: + options: + docstring_style: "google" + +markdown_extensions: + - pymdownx.highlight: + anchor_linenums: true + line_spans: __span + pygments_lang_class: true + - pymdownx.inlinehilite + - pymdownx.snippets + - pymdownx.superfences diff --git a/src/snk_cli/cli.py b/src/snk_cli/cli.py index d0f2ebc..d12e8ec 100644 --- a/src/snk_cli/cli.py +++ b/src/snk_cli/cli.py @@ -58,10 +58,10 @@ def __init__(self, workflow_dir_path: Path = None, *, pipeline_dir_path: Path = ) else: self.snk_config = snk_config - if self.snk_config.version: - self.version = self.snk_config.version - else: + if self.workflow.version: self.version = self.workflow.version + else: + self.version = self.snk_config.version self.options = build_dynamic_cli_options(self.snakemake_config, self.snk_config) self.snakefile = self._find_snakefile() self.conda_prefix_dir = self.workflow.conda_prefix_dir