Skip to content

Commit 50975f1

Browse files
authored
Merge pull request #11 from bhklab/katys/add-env-variables
feat: add global environment variables to pixi.toml
2 parents afeb7dc + e979ae2 commit 50975f1

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

pixi.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ platforms = ["osx-arm64", "linux-64", "win-64", "osx-64"]
1111
quality = { features = ["quality"], solve-group = "default" }
1212
docs = { features = ["docs"], solve-group = "default" }
1313

14+
[activation]
15+
# convenient variables which can be used in scripts
16+
env.CONFIG = "${PIXI_PROJECT_ROOT}/config"
17+
env.METADATA = "${PIXI_PROJECT_ROOT}/metadata"
18+
env.LOGS = "${PIXI_PROJECT_ROOT}/logs"
19+
env.RAWDATA = "${PIXI_PROJECT_ROOT}/data/rawdata"
20+
env.PROCDATA = "${PIXI_PROJECT_ROOT}/data/procdata"
21+
env.RESULTS = "${PIXI_PROJECT_ROOT}/data/results"
22+
env.SCRIPTS = "${PIXI_PROJECT_ROOT}/workflow/scripts"
23+
24+
1425
[dependencies]
1526
python = ">=3.12"
1627
ipython = "*"
@@ -33,6 +44,9 @@ readii = ">=1.35.1, <2"
3344
[target.linux-64.dependencies]
3445
bioconductor-survcomp = ">=1.56.0,<2"
3546

47+
[tasks]
48+
example_script = {cmd="python $SCRIPTS/example_script.py"}
49+
3650
############################################## QUALITY ###############################################
3751
# Quality includes linting, type checking, and formatting
3852
[feature.quality.dependencies]
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "442beff9",
6+
"metadata": {},
7+
"source": [
8+
"# Example Notebook\n",
9+
"\n",
10+
"This is just a quick example showing how to use the template."
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 1,
16+
"id": "75fde9f9",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"import logging\n",
21+
"\n",
22+
"logging.basicConfig(\n",
23+
"\tlevel=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s'\n",
24+
")\n",
25+
"\n",
26+
"logger = logging.getLogger(__name__)"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 2,
32+
"id": "2d08bd5d",
33+
"metadata": {},
34+
"outputs": [
35+
{
36+
"name": "stderr",
37+
"output_type": "stream",
38+
"text": [
39+
"2025-05-09 13:20:53,996 - INFO - PIXI_PROJECT_ROOT: /Users/bhklab/dev/bhklab/testdirs/another-example has 20 files\n",
40+
"2025-05-09 13:20:53,997 - INFO - RAWDATA: data/rawdata has 0 files\n",
41+
"2025-05-09 13:20:53,998 - INFO - PROCDATA: data/procdata has 0 files\n",
42+
"2025-05-09 13:20:53,998 - INFO - SCRIPTS: workflow/scripts has 0 files\n"
43+
]
44+
}
45+
],
46+
"source": [
47+
"import os\n",
48+
"from pathlib import Path\n",
49+
"\n",
50+
"env_dir_variables = [\n",
51+
" 'PIXI_PROJECT_ROOT',\n",
52+
" 'RAWDATA',\n",
53+
" 'PROCDATA',\n",
54+
" 'SCRIPTS',\n",
55+
"]\n",
56+
"\n",
57+
"for var in env_dir_variables:\n",
58+
" var_path = Path(os.environ.get(var))\n",
59+
" logger.info(f'{var}: {var_path} has {len(list(var_path.glob(\"*\")))} files')\n",
60+
"\n",
61+
"\n"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"id": "ac1f9617",
68+
"metadata": {},
69+
"outputs": [],
70+
"source": []
71+
}
72+
],
73+
"metadata": {
74+
"kernelspec": {
75+
"display_name": "default",
76+
"language": "python",
77+
"name": "python3"
78+
},
79+
"language_info": {
80+
"codemirror_mode": {
81+
"name": "ipython",
82+
"version": 3
83+
},
84+
"file_extension": ".py",
85+
"mimetype": "text/x-python",
86+
"name": "python",
87+
"nbconvert_exporter": "python",
88+
"pygments_lexer": "ipython3",
89+
"version": "3.13.3"
90+
}
91+
},
92+
"nbformat": 4,
93+
"nbformat_minor": 5
94+
}

workflow/scripts/example_script.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import logging
2+
import os
3+
from pathlib import Path
4+
5+
logging.basicConfig(
6+
level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s'
7+
)
8+
9+
logger = logging.getLogger(__name__)
10+
11+
12+
def main() -> None:
13+
# examples of template defined env variables
14+
env_dir_variables = [
15+
'RAWDATA',
16+
'PROCDATA',
17+
'SCRIPTS',
18+
]
19+
20+
for var in env_dir_variables:
21+
var_path = Path(os.environ.get(var))
22+
logger.info(f'{var}: {var_path} has {len(list(var_path.glob("*")))} files')
23+
24+
25+
if __name__ == '__main__':
26+
logger.info(f'Starting example script from {Path().cwd()=}')
27+
main()

0 commit comments

Comments
 (0)