Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ jobs:
save-if: ${{ github.ref == 'refs/heads/main' }}
# The Python resolver tests run a user resolvers.py in python3; PyYAML
# and omegaconf make the fixture parity test run against the real package.
# kadet and jinja2 let the kadet evaluator test run. omegaconf is held
# at the version the reference implementation needs, so this job and the
# parity job exercise the same one.
# kadet and jinja2 let the kadet evaluator test run. omegaconf and
# python-box are held at the versions the reference implementation
# needs, so this job and the parity job exercise the same ones.
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ matrix.python }}
- run: pip install pyyaml "omegaconf==2.4.0.dev3" kadet jinja2
- run: pip install pyyaml "omegaconf==2.4.0.dev3" kadet jinja2 "python-box>=7.2.0,<8"
- run: cargo test --locked

parity:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,4 @@ jobs:
pattern: wheel-*
path: dist
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ and network access for pip.
`python3` with

```sh
pip install pyyaml "omegaconf==2.4.0.dev3" kadet jinja2
pip install pyyaml "omegaconf==2.4.0.dev3" kadet jinja2 "python-box>=7.2.0,<8"
```

Without them the tests pass without running and say why on stderr, which
Expand Down
38 changes: 29 additions & 9 deletions crates/krab-compile/src/pyenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
//! `KRAB_PYTHON_REQUIREMENTS` adds specifiers for this machine only, one
//! per line (`kadet==0.3.1`, `kadet @ file:///home/me/kadet`, or
//! `-e /home/me/kadet` for an editable checkout), without touching the
//! shared `.kapitan`. A `kadet` or `jinja2` named by either source replaces
//! the baseline entry, so a pin or a checkout is the only one installed.
//! shared `.kapitan`. A `kadet`, `jinja2` or `python-box` named by either
//! source replaces the baseline entry, so a pin or a checkout is the only
//! one installed.
//!
//! `--python` / `KRAB_PYTHON` bypass all of this: that interpreter is
//! used as it is, and nothing else is ever tried (in particular not a
Expand All @@ -33,7 +34,10 @@ use std::process::Command;
use krab_inventory::python::{PythonCmd, cache_dir, which};

/// What every kadet evaluation needs, whatever the repository declares.
pub const BASELINE: &[&str] = &["kadet", "jinja2"];
/// python-box is held to the range kapitan 0.36.3 requires: from 8 on,
/// `BoxList` copies the dicts it is built from, so a component's write to an
/// element of `a + b` no longer reaches `a` (#320).
pub const BASELINE: &[&str] = &["kadet", "jinja2", "python-box>=7.2.0,<8"];

const MARKER: &str = ".krab-env.json";

Expand Down Expand Up @@ -124,7 +128,7 @@ impl PythonEnv {
.collect();
let mut out: Vec<String> = BASELINE
.iter()
.filter(|b| !named.contains(&b.to_string()))
.filter(|b| project_name(b).is_none_or(|n| !named.contains(&n)))
.map(|s| s.to_string())
.collect();
for r in self.requirements.iter().chain(&self.extra) {
Expand Down Expand Up @@ -332,7 +336,13 @@ mod tests {
assert!(env.declared);
assert_eq!(
env.specifiers(),
vec!["kadet", "jinja2", "jmespath", "jsonpath-ng"]
vec![
"kadet",
"jinja2",
"python-box>=7.2.0,<8",
"jmespath",
"jsonpath-ng"
]
);
assert!(env.requirements_file.is_none());
}
Expand All @@ -356,18 +366,28 @@ mod tests {

#[test]
fn a_named_baseline_package_replaces_the_baseline_entry() {
let env = spec(Some(vec!["Kadet==0.3.1", "jinja2>=3"]));
assert_eq!(env.specifiers(), vec!["Kadet==0.3.1", "jinja2>=3"]);
let env = spec(Some(vec!["Kadet==0.3.1", "jinja2>=3", "python_box==7.4.1"]));
assert_eq!(
env.specifiers(),
vec!["Kadet==0.3.1", "jinja2>=3", "python_box==7.4.1"]
);

let mut env = spec(None);
env.extra = vec!["-e /home/me/kadet/".into()];
assert_eq!(env.specifiers(), vec!["jinja2", "-e /home/me/kadet/"]);
assert_eq!(
env.specifiers(),
vec!["jinja2", "python-box>=7.2.0,<8", "-e /home/me/kadet/"]
);

let mut env = spec(None);
env.extra = vec!["kadet @ file:///home/me/kadet".into()];
assert_eq!(
env.specifiers(),
vec!["jinja2", "kadet @ file:///home/me/kadet"]
vec![
"jinja2",
"python-box>=7.2.0,<8",
"kadet @ file:///home/me/kadet"
]
);
}

Expand Down
4 changes: 4 additions & 0 deletions crates/krab-compile/tests/kadet_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ fn evaluates_a_component_without_the_python_kapitan() {
assert_eq!(output["pruned"], json!({ "keep": 1, "nested": {} }));
assert_eq!(output["targets"], json!(["app.api", "app.web"]));
assert_eq!(output["params"], "plain");
assert_eq!(
output["pod"]["containers"],
json!([{ "name": "app", "securityContext": { "readOnlyRootFilesystem": true } }])
);
let modules: Vec<&str> = output["kapitan_modules"]
.as_array()
.unwrap()
Expand Down
7 changes: 5 additions & 2 deletions docs/GETTING-STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ templates and whatever the components themselves import); the Python
kapitan itself is not. krab builds that environment for you: declare the
components' own packages in `.kapitan` and the first compile creates a venv
under `~/.cache/krab/python/` (with `uv` when installed, else `python3
-m venv` and pip) holding `kadet`, `jinja2` and them:
-m venv` and pip) holding `kadet`, `jinja2`, `python-box` (in the range kapitan
requires) and them:

```yaml
compile:
Expand All @@ -177,7 +178,9 @@ alone. To try another kadet, or your own checkout, without touching the
shared file, set `KRAB_PYTHON_REQUIREMENTS` (one specifier per line, for
example `kadet==0.3.1` or `-e /home/me/kadet`); a `kadet` named there or in
`.kapitan` replaces krab's own entry. `--python` / `$KRAB_PYTHON` name
an interpreter to use as it is instead (nothing is installed into it). Nothing else is tried: an installed
an interpreter to use as it is instead (nothing is installed into it). With a
python-box newer than kapitan allows there, kadet output can differ from
kapitan's (#320). Nothing else is tried: an installed
Python kapitan plays no part in kadet evaluation. The component's
`main()` runs in that Python with krab's own `kapitan` package on the path,
which provides the API components import (`kapitan.inputs.kadet`,
Expand Down
21 changes: 15 additions & 6 deletions docs/specs/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,23 @@ CMP-43 Without one, kadet evaluation MUST use krab's managed environment: a
Test: none
Since: #91

CMP-44 The managed environment MUST install `kadet` and `jinja2`, then the
entries of `compile.python-requirements`, then the lines of
`$KRAB_PYTHON_REQUIREMENTS`. A `kadet` or `jinja2` named in either
list replaces the baseline entry. A single
CMP-44 The managed environment MUST install `kadet`, `jinja2` and
`python-box>=7.2.0,<8`, then the entries of
`compile.python-requirements`, then the lines of
`$KRAB_PYTHON_REQUIREMENTS`. A `kadet`, `jinja2` or `python-box` named
in either list replaces the baseline entry. A single
`compile.python-requirements` value that is an existing file or ends
in `.txt` is a requirements file.
Test: crates/krab-compile/src/pyenv.rs::tests::a_named_baseline_package_replaces_the_baseline_entry
Since: #91
Test: crates/krab-compile/src/pyenv.rs::tests::a_named_baseline_package_replaces_the_baseline_entry,
crates/krab-compile/tests/kadet_runner.rs::evaluates_a_component_without_the_python_kapitan
(the write to an element of `a + b`)
Since: #91, python-box range #321

The python-box range is the one kapitan 0.36.3 declares. python-box 8
copies the dicts a `BoxList` is built from, so a component that writes
to an element of `a + b` (the kubernetes generator's
`pod_spec.containers + pod_spec.initContainers`) loses the write, and
its output differs from kapitan's.

CMP-45 `--backend python` MUST try, in order, `--python`/`$KRAB_PYTHON`, a
kapitan PEX on PATH run with PEX_INTERPRETER=1, and `python3`, and
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/kadet/components/greeter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def main(input_params):
out.root.pruned = greetlib.prune_empty({"keep": 1, "drop": [], "nested": {"drop": {}}})
out.root.targets = sorted(all_documents(None).keys())
out.root.params = input_params.get("flavour")
# A write to an element of `a + b` lands in `a`, as with kapitan's python-box (#320).
pod = BaseObj().root
pod.containers = [{"name": "app"}]
pod.initContainers = []
for container in pod.containers + pod.initContainers:
container["securityContext"] = {"readOnlyRootFilesystem": True}
out.root.pod = pod
# Nothing from an installed kapitan may have been imported.
out.root.kapitan_modules = sorted(m for m in sys.modules if m == "kapitan" or m.startswith("kapitan."))
return out
Loading