pipen-hostenv 0.0.1__py3-none-any.whl

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,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,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,5 @@
1
+ pipen_hostenv/__init__.py,sha256=RVPh1uqzscC0RDqGMfJ1fTutTlSLqvZAaaFofRKxpEU,1425
2
+ pipen_hostenv-0.0.1.dist-info/METADATA,sha256=ZSLS5HbOq1eRuFP34xrYmqBw0YA_K0uQQG_gLuBSKKU,3300
3
+ pipen_hostenv-0.0.1.dist-info/WHEEL,sha256=THafob7ofN-NsuMN7Mg4qZyHaQI7KkD-QlcQatYhXPo,87
4
+ pipen_hostenv-0.0.1.dist-info/entry_points.txt,sha256=vVbKIJHzyWKlIxc1QJdJZT1v6u3eMnT7GhztSbYBrAo,45
5
+ pipen_hostenv-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [pipen]
2
+ hostenv = pipen_hostenv:PipenHostEnv