pipen-hostenv 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ name: Build and Deploy
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ if: "! contains(github.event.head_commit.message, 'wip') && ! startsWith(github.ref, 'refs/tags')"
10
+ strategy:
11
+ matrix:
12
+ python-version: ["3.12"]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v6
16
+ - name: Install uv
17
+ uses: astral-sh/setup-uv@v8.0.0
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ enable-cache: true
21
+ - name: Install dependencies
22
+ run: uv sync --group dev
23
+ - name: Test with pytest
24
+ run: uv run pytest tests/ --junitxml=junit/test-results-${{ matrix.python-version }}.xml
25
+ - name: Upload pytest test results
26
+ uses: actions/upload-artifact@v7
27
+ with:
28
+ name: pytest-results-${{ matrix.python-version }}
29
+ path: junit/test-results-${{ matrix.python-version }}.xml
30
+ # Use always() to always run this step to publish test results when there are test failures
31
+ if: ${{ always() }}
32
+
33
+ deploy:
34
+ # needs: build
35
+ runs-on: ubuntu-latest
36
+ if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
37
+ strategy:
38
+ matrix:
39
+ python-version: ["3.12"]
40
+ steps:
41
+ - uses: actions/checkout@v6
42
+ - name: Install uv
43
+ uses: astral-sh/setup-uv@v8.0.0
44
+ with:
45
+ python-version: ${{ matrix.python-version }}
46
+ enable-cache: true
47
+ - name: Build and publish to PyPI
48
+ run: |
49
+ uv build
50
+ uv publish --username ${{ secrets.PYPI_USER }} --password ${{ secrets.PYPI_PASSWORD }}
51
+ if: success()
@@ -0,0 +1,130 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ env/
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+
27
+ # PyInstaller
28
+ # Usually these files are written by a python script from a template
29
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .coverage
41
+ .coverage.*
42
+ .cache
43
+ nosetests.xml
44
+ coverage.xml
45
+ .coverage.xml
46
+ cov.xml
47
+ *,cover
48
+ .hypothesis/
49
+
50
+ # Translations
51
+ *.mo
52
+ *.pot
53
+
54
+ # Django stuff:
55
+ *.log
56
+ local_settings.py
57
+
58
+ # Flask stuff:
59
+ instance/
60
+ .webassets-cache
61
+
62
+ # Scrapy stuff:
63
+ .scrapy
64
+
65
+ # Sphinx documentation
66
+ docs/_build/
67
+
68
+ # PyBuilder
69
+ target/
70
+
71
+ # IPython Notebook
72
+ .ipynb_checkpoints
73
+
74
+ # pyenv
75
+ .python-version
76
+
77
+ # celery beat schedule file
78
+ celerybeat-schedule
79
+
80
+ # dotenv
81
+ # .env
82
+
83
+ # virtualenv
84
+ venv/
85
+ ENV/
86
+
87
+ # Spyder project settings
88
+ .spyderproject
89
+
90
+ # Rope project settings
91
+ .ropeproject
92
+
93
+ workdir/
94
+ node_modules/
95
+ _book/
96
+ .vscode
97
+ export/
98
+ *.svg
99
+ *.dot
100
+ *.queue.txt
101
+ site/
102
+
103
+ # poetry
104
+ # poetry.lock
105
+
106
+ # backup files
107
+ *.bak
108
+
109
+ .history/
110
+ .xqute/
111
+ .pipen/
112
+ t-*.ipynb
113
+ *-output/
114
+ *_results/
115
+ t.py
116
+
117
+ nohup.out
118
+ test.py
119
+ test.ipynb
120
+ gac_key.json
121
+ examples/.pipen.toml
122
+ docs/api/
123
+ docs/index.md
124
+ docs/CONTRIBUTING.md
125
+ # apptainer images
126
+ *.sif
127
+ # git bundle files
128
+ *.bundle
129
+ .pipen/
130
+ *-output/
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.5
2
+ Name: pipen-hostenv
3
+ Version: 0.0.1
4
+ Summary: Bring your host env to the jobs for pipen pipelines
5
+ Author-email: pwwang <pwwang@pwwang.com>
6
+ Requires-Python: >=3.9
7
+ Requires-Dist: pipen>=1.1
8
+ Requires-Dist: python-dotenv>=1.0
9
+ Description-Content-Type: text/markdown
10
+
11
+ <div align="center">
12
+ <img src="./logo.png" width="240px" alt="pipen-hostenv" />
13
+
14
+ <p style="font-weight:bold;">Bring your host environment variables into the jobs of
15
+ <a href="https://github.com/pwwang/pipen" target="_blank">pipen</a> pipelines.
16
+ </p>
17
+
18
+ </div>
19
+
20
+ <hr />
21
+
22
+ Variables are read when each job is initialized and injected into the job's wrapper script
23
+ (`export VAR='value'`), so they are available as `$VAR` in `script` and to any process the job
24
+ starts. The pipen process itself is not modified.
25
+
26
+ Installing the plugin is all it takes — pipen loads it through its `pipen` entry point.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install pipen-hostenv
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ By default `./.env`, relative to the directory pipen is run from, is loaded for every job:
37
+
38
+ ```python
39
+ from pipen import Proc, run
40
+
41
+ class P1(Proc):
42
+ input = "name:var"
43
+ output = "o:file:{{in.name}}.txt"
44
+ script = "echo ${{in.name}} > {{out.o}}"
45
+
46
+ run("MyPipeline", starts=P1, data=["VAR"]) # $VAR comes from ./.env
47
+ ```
48
+
49
+ ### Custom env file
50
+
51
+ Per process:
52
+
53
+ ```python
54
+ class P1(Proc):
55
+ plugin_opts = {"hostenv_file": "./envfile"}
56
+ ```
57
+
58
+ Or for the whole pipeline:
59
+
60
+ ```python
61
+ run("MyPipeline", starts=P1, data=["VAR"], plugin_opts={"hostenv_file": "./envfile"})
62
+ ```
63
+
64
+ ### Passing values directly
65
+
66
+ ```python
67
+ run(
68
+ "MyPipeline",
69
+ starts=P1,
70
+ data=["VAR"],
71
+ plugin_opts={"hostenv_values": {"VAR": "green grass"}},
72
+ )
73
+ ```
74
+
75
+ ## Options
76
+
77
+ | Option | Default | Description |
78
+ | ---------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
79
+ | `hostenv_file` | `./.env` | Path to a [dotenv](https://github.com/theskumar/python-dotenv) file. Resolved against the working directory of the pipen process and silently skipped when it is missing. Set it to a falsy value to disable file loading. |
80
+ | `hostenv_values` | `{}` | Mapping of environment variables to pass to the jobs directly. |
81
+
82
+ ## Precedence
83
+
84
+ For a given job, lowest to highest:
85
+
86
+ 1. `job.envs` of the process
87
+ 2. Entries read from `hostenv_file`
88
+ 3. Entries from `hostenv_values`
89
+
90
+ `plugin_opts` are merged per process on top of the pipeline configuration, so options set on a
91
+ `Proc` class win over those passed to `run()`/`Pipen()`. The merge is shallow — a process-level
92
+ `hostenv_values` replaces the pipeline-level one entirely rather than merging key by key.
93
+
94
+ ## Notes
95
+
96
+ - A pipeline-level env file applies to every process; override it for a single process with
97
+ process-level `plugin_opts`.
98
+ - Only shell variables (`$VAR`) are populated. The values are not available as template variables
99
+ at script rendering time (`{{ envs.VAR }}` renders empty).
@@ -0,0 +1,89 @@
1
+ <div align="center">
2
+ <img src="./logo.png" width="240px" alt="pipen-hostenv" />
3
+
4
+ <p style="font-weight:bold;">Bring your host environment variables into the jobs of
5
+ <a href="https://github.com/pwwang/pipen" target="_blank">pipen</a> pipelines.
6
+ </p>
7
+
8
+ </div>
9
+
10
+ <hr />
11
+
12
+ Variables are read when each job is initialized and injected into the job's wrapper script
13
+ (`export VAR='value'`), so they are available as `$VAR` in `script` and to any process the job
14
+ starts. The pipen process itself is not modified.
15
+
16
+ Installing the plugin is all it takes — pipen loads it through its `pipen` entry point.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install pipen-hostenv
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ By default `./.env`, relative to the directory pipen is run from, is loaded for every job:
27
+
28
+ ```python
29
+ from pipen import Proc, run
30
+
31
+ class P1(Proc):
32
+ input = "name:var"
33
+ output = "o:file:{{in.name}}.txt"
34
+ script = "echo ${{in.name}} > {{out.o}}"
35
+
36
+ run("MyPipeline", starts=P1, data=["VAR"]) # $VAR comes from ./.env
37
+ ```
38
+
39
+ ### Custom env file
40
+
41
+ Per process:
42
+
43
+ ```python
44
+ class P1(Proc):
45
+ plugin_opts = {"hostenv_file": "./envfile"}
46
+ ```
47
+
48
+ Or for the whole pipeline:
49
+
50
+ ```python
51
+ run("MyPipeline", starts=P1, data=["VAR"], plugin_opts={"hostenv_file": "./envfile"})
52
+ ```
53
+
54
+ ### Passing values directly
55
+
56
+ ```python
57
+ run(
58
+ "MyPipeline",
59
+ starts=P1,
60
+ data=["VAR"],
61
+ plugin_opts={"hostenv_values": {"VAR": "green grass"}},
62
+ )
63
+ ```
64
+
65
+ ## Options
66
+
67
+ | Option | Default | Description |
68
+ | ---------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
69
+ | `hostenv_file` | `./.env` | Path to a [dotenv](https://github.com/theskumar/python-dotenv) file. Resolved against the working directory of the pipen process and silently skipped when it is missing. Set it to a falsy value to disable file loading. |
70
+ | `hostenv_values` | `{}` | Mapping of environment variables to pass to the jobs directly. |
71
+
72
+ ## Precedence
73
+
74
+ For a given job, lowest to highest:
75
+
76
+ 1. `job.envs` of the process
77
+ 2. Entries read from `hostenv_file`
78
+ 3. Entries from `hostenv_values`
79
+
80
+ `plugin_opts` are merged per process on top of the pipeline configuration, so options set on a
81
+ `Proc` class win over those passed to `run()`/`Pipen()`. The merge is shallow — a process-level
82
+ `hostenv_values` replaces the pipeline-level one entirely rather than merging key by key.
83
+
84
+ ## Notes
85
+
86
+ - A pipeline-level env file applies to every process; override it for a single process with
87
+ process-level `plugin_opts`.
88
+ - Only shell variables (`$VAR`) are populated. The values are not available as template variables
89
+ at script rendering time (`{{ envs.VAR }}` renders empty).
Binary file
@@ -0,0 +1,30 @@
1
+ [project]
2
+ name = "pipen-hostenv"
3
+ # version = "0.1.0"
4
+ dynamic = ["version"]
5
+ description = "Bring your host env to the jobs for pipen pipelines"
6
+ readme = "README.md"
7
+ authors = [
8
+ { name = "pwwang", email = "pwwang@pwwang.com" }
9
+ ]
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ "pipen>=1.1",
13
+ "python-dotenv>=1.0",
14
+ ]
15
+
16
+ [tool.hatch.version]
17
+ path = "src/pipen_hostenv/__init__.py"
18
+
19
+ [project.entry-points.pipen]
20
+ hostenv = "pipen_hostenv:PipenHostEnv"
21
+
22
+ [build-system]
23
+ requires = ["hatchling"]
24
+ build-backend = "hatchling.build"
25
+
26
+ [dependency-groups]
27
+ dev = [
28
+ "pipen-verbose>=1.1.5",
29
+ "pytest>=8.4.2",
30
+ ]
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from typing import TYPE_CHECKING
5
+ from dotenv import dotenv_values
6
+ from pipen import plugin
7
+
8
+ if TYPE_CHECKING:
9
+ from pipen import Pipen
10
+ from pipen.job import Job
11
+
12
+ __version__ = "0.0.1"
13
+
14
+
15
+ class PipenHostEnv:
16
+ __version__ = __version__
17
+ name = "hostenv"
18
+
19
+ @plugin.impl
20
+ def on_setup(pipen: Pipen) -> None: # pyright: ignore[reportGeneralTypeIssues]
21
+ """Default configurations"""
22
+ # pipeline level: name or detailed theme
23
+ pipen.config.plugin_opts.hostenv_file = "./.env"
24
+ pipen.config.plugin_opts.hostenv_values = {}
25
+
26
+ @plugin.impl
27
+ async def on_job_init(job: Job) -> None: # pyright: ignore[reportGeneralTypeIssues]
28
+ """Load host environment variables"""
29
+
30
+
31
+ env_file = (
32
+ job
33
+ .proc
34
+ .plugin_opts # pyright: ignore[reportOptionalMemberAccess]
35
+ .get( # pyright: ignore[reportOptionalMemberAccess]
36
+ "hostenv_file",
37
+ "./.env",
38
+ )
39
+ )
40
+ env_values = (
41
+ job
42
+ .proc
43
+ .plugin_opts # pyright: ignore[reportOptionalMemberAccess]
44
+ .get("hostenv_values", {}) # pyright: ignore[reportOptionalMemberAccess]
45
+ )
46
+ if env_file and os.path.exists(env_file):
47
+ envs = dotenv_values(env_file)
48
+ job.envs.update(envs)
49
+ job.envs.update(env_values)
@@ -0,0 +1 @@
1
+ VAR="hello world"
@@ -0,0 +1,3 @@
1
+ import os
2
+
3
+ os.chdir(os.path.dirname(__file__))
@@ -0,0 +1 @@
1
+ VAR2="blue sky"
@@ -0,0 +1,102 @@
1
+ import pytest
2
+ import os
3
+ from pathlib import Path
4
+ from pipen import Proc, run
5
+
6
+
7
+ def test_hostenv_loads_cwd_dotenv():
8
+
9
+ class P1(Proc):
10
+ cache = False
11
+ input = "name:var"
12
+ output = "o:file:{{in.name}}.txt"
13
+ script = "echo ${{in.name}} > {{out.o}}"
14
+
15
+ run("HostEnvLoadsCwdEnvfile", starts=P1, data=["VAR"])
16
+ outfile = "HostEnvLoadsCwdEnvfile-output/P1/VAR.txt"
17
+
18
+ assert Path(outfile).exists()
19
+ assert Path(outfile).read_text().strip() == "hello world"
20
+
21
+
22
+ def test_hostenv_loads_custom_dotenv():
23
+
24
+ class P2(Proc):
25
+ cache = False
26
+ input = "name:var"
27
+ output = "o:file:{{in.name}}.txt"
28
+ script = "echo ${{in.name}} > {{out.o}}"
29
+ plugin_opts = {"hostenv_file": "./envfile"}
30
+
31
+ run(
32
+ "HostEnvLoadsCustomEnvfile",
33
+ starts=P2,
34
+ data=["VAR2"],
35
+ )
36
+ outfile = "HostEnvLoadsCustomEnvfile-output/P2/VAR2.txt"
37
+
38
+ assert Path(outfile).exists()
39
+ assert Path(outfile).read_text().strip() == "blue sky"
40
+
41
+
42
+ def test_hostenv_loads_from_pipeline_config():
43
+
44
+ class P3(Proc):
45
+ cache = False
46
+ input = "name:var"
47
+ output = "o:file:{{in.name}}.txt"
48
+ script = "echo ${{in.name}} > {{out.o}}"
49
+
50
+ run(
51
+ "HostEnvLoadsPipelineConfig",
52
+ starts=P3,
53
+ data=["VAR2"],
54
+ plugin_opts={"hostenv_file": "./envfile"},
55
+ )
56
+ outfile = "HostEnvLoadsPipelineConfig-output/P3/VAR2.txt"
57
+
58
+ assert Path(outfile).exists()
59
+ assert Path(outfile).read_text().strip() == "blue sky"
60
+
61
+
62
+ def test_hostenv_loads_direct_passed_envs():
63
+
64
+ class P4(Proc):
65
+ cache = False
66
+ input = "name:var"
67
+ output = "o:file:{{in.name}}.txt"
68
+ script = "echo ${{in.name}} > {{out.o}}"
69
+
70
+ run(
71
+ "HostEnvLoadsDirectPassedEnvs",
72
+ starts=P4,
73
+ data=["VAR3"],
74
+ plugin_opts={"hostenv_values": {"VAR3": "green grass"}},
75
+ )
76
+ outfile = "HostEnvLoadsDirectPassedEnvs-output/P4/VAR3.txt"
77
+
78
+ assert Path(outfile).exists()
79
+ assert Path(outfile).read_text().strip() == "green grass"
80
+
81
+
82
+ def test_hostenv_direct_envs_override_dotenv():
83
+
84
+ class P5(Proc):
85
+ cache = False
86
+ input = "name:var"
87
+ output = "o:file:{{in.name}}.txt"
88
+ script = "echo ${{in.name}} > {{out.o}}"
89
+
90
+ run(
91
+ "HostEnvDirectEnvsOverrideDotenv",
92
+ starts=P5,
93
+ data=["VAR"],
94
+ plugin_opts={
95
+ "hostenv_file": "./.env",
96
+ "hostenv_values": {"VAR": "override value"},
97
+ },
98
+ )
99
+ outfile = "HostEnvDirectEnvsOverrideDotenv-output/P5/VAR.txt"
100
+
101
+ assert Path(outfile).exists()
102
+ assert Path(outfile).read_text().strip() == "override value"