Config
InvalidSnkConfigError
Bases: SnkConfigError
, ValueError
Thrown if the given SNK config appears to have an invalid format.
MissingSnkConfigError
Bases: SnkConfigError
, FileNotFoundError
Thrown if the given SNK config file cannot be found.
SnkConfig
dataclass
A dataclass for storing Snakemake workflow configuration.
Attributes:
Name | Type | Description |
---|---|---|
art |
str
|
The art to display in the CLI. Defaults to None. |
logo |
str
|
The logo to display in the CLI. Defaults to None. |
tagline |
str
|
The tagline to display in the CLI. Defaults to "A Snakemake workflow CLI generated with Snk". |
font |
str
|
The font size for the CLI. Defaults to "small". |
version |
Optional[str]
|
The version of the workflow. Defaults to None. |
conda |
bool
|
Whether to use conda for managing environments. Defaults to True. |
resources |
List[Path]
|
List of paths to additional resources. Defaults to an empty list. |
symlink_resources |
bool
|
Whether to symlink resources instead of copying them. Defaults to False. |
skip_missing |
bool
|
Whether to skip missing CLI options. Defaults to False. |
additional_snakemake_args |
List[str]
|
List of additional Snakemake command-line arguments. Defaults to an empty list. |
commands |
List[str]
|
List of subcommands to include in the CLI. Defaults to ["run", "script", "env", "profile", "info", "config"]. |
cli |
dict
|
Dictionary of CLI options and their values. Defaults to an empty dictionary. |
_snk_config_path |
Path
|
The path to the SNK config file. Defaults to None. |
Methods
from_path(snk_config_path: Path) -> SnkConfig: Load and validate Snk config from file.
from_workflow_dir(workflow_dir_path: Path, create_if_not_exists: bool = False) -> SnkConfig: Load and validate SNK config from workflow directory.
validate_resources(resources: List[Path]) -> None: Validate resources.
add_resources(resources: List[Path], workflow_dir_path: Path = None) -> None: Add resources to the SNK config.
to_yaml(path: Path) -> None: Write SNK config to YAML file.
save() -> None: Save SNK config.
Source code in src/snk_cli/config/config.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
add_resources(resources, workflow_dir_path=None)
Add resources to the SNK config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resources |
List[Path]
|
List of resources to add. |
required |
workflow_dir_path |
Path
|
Path to the workflow directory. |
None
|
Returns:
Type | Description |
---|---|
None |
Side Effects
Adds the resources to the SNK config.
Examples:
>>> snk_config = SnkConfig()
>>> snk_config.add_resources([Path("resource1.txt"), Path("resource2.txt")], Path("workflow"))
Source code in src/snk_cli/config/config.py
from_path(snk_config_path)
classmethod
Load and validate Snk config from file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
snk_config_path |
Path
|
Path to the SNK config file. |
required |
Returns:
Name | Type | Description |
---|---|---|
SnkConfig |
A SnkConfig object. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the SNK config file is not found. |
Examples:
>>> SnkConfig.from_path(Path("snk.yaml"))
SnkConfig(art=None, logo=None, tagline='A Snakemake workflow CLI generated with Snk', font='small', resources=[], annotations={}, symlink_resources=False, _snk_config_path=PosixPath('snk.yaml'))
Source code in src/snk_cli/config/config.py
from_workflow_dir(workflow_dir_path, create_if_not_exists=False)
classmethod
Load and validate SNK config from workflow directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
workflow_dir_path |
Path
|
Path to the workflow directory. |
required |
create_if_not_exists |
bool
|
Whether to create a SNK config file if one does not exist. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SnkConfig |
A SnkConfig object. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the SNK config file is not found. |
Examples:
>>> SnkConfig.from_workflow_dir(Path("workflow"))
SnkConfig(art=None, logo=None, tagline='A Snakemake workflow CLI generated with Snk', font='small', resources=[], annotations={}, symlink_resources=False, _snk_config_path=PosixPath('workflow/snk.yaml'))
Source code in src/snk_cli/config/config.py
save()
Save SNK config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Path to write the YAML file to. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Side Effects
Writes the SNK config to the path specified by _snk_config_path.
Examples:
Source code in src/snk_cli/config/config.py
to_yaml(path)
Write SNK config to YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Path to write the YAML file to. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Side Effects
Writes the SNK config to the specified path.
Examples:
Source code in src/snk_cli/config/config.py
validate_resources(resources)
Validate resources.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resources |
List[Path]
|
List of resources to validate. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If a resource is not found. |
Notes
This function does not modify the resources list.
Examples:
Source code in src/snk_cli/config/config.py
SnkConfigError
get_config_from_workflow_dir(workflow_dir_path)
Get the config file from a workflow directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
workflow_dir_path |
Path
|
Path to the workflow directory. |
required |
Returns:
Name | Type | Description |
---|---|---|
Path |
Path to the config file, or None if not found. |
Examples:
Source code in src/snk_cli/config/config.py
load_workflow_snakemake_config(workflow_dir_path)
Load the Snakemake config from a workflow directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
workflow_dir_path |
Path
|
Path to the workflow directory. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
The Snakemake config. |
Examples:
>>> load_workflow_snakemake_config(Path("workflow"))
{'inputs': {'data': 'data.txt'}, 'outputs': {'results': 'results.txt'}}
Source code in src/snk_cli/config/config.py
get_version_from_config(config_path, config_dict=None)
Get the version from the config file or config dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path |
Path
|
Path to the config file. |
required |
config_dict |
dict
|
Config dictionary. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The version. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the version file (about.py) is not found. |
KeyError
|
If the version key is not found in the version file. |
Examples:
>>> get_version_from_config(Path("config.yaml"))
'0.1.0'
>>> get_version_from_config(Path("config.yaml"), {"version": "0.2.0"})
'0.2.0'