feat(template): Check that Helm defined templates carry the chart name - #647
feat(template): Check that Helm defined templates carry the chart name#647lfrancke wants to merge 2 commits into
Conversation
Adds a script called by prek which walks our charts and checks whether all defines/calls use a namespaced name stackabletech/issues#882
52ad078 to
c91762d
Compare
| file=sys.stderr, | ||
| ) | ||
| sys.exit(2) | ||
| names = unprefixed(Path(path).read_text(), chart) |
There was a problem hiding this comment.
What does read_text do here? I think we should explain it, because at least I don't understand it just from context. It might be obvious for people used to Python, but it is not obvious for me (and potentially a bunch of other people).
There was a problem hiding this comment.
If it does what I assume it does - reading the file as text - this is even more surprising and should be documented. Usually, filesystem io goes through a file first: File::open(path).read() (pseudo code).
There was a problem hiding this comment.
https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_text
This also exists in Java and in Rust, no? Shortcuts to just read the full file?
Honest question: What do you find surprising here? I read the code and thought "yup, makes sense"
So on this I'll push back and say: This is the normal way I learned.
There was a problem hiding this comment.
Mhm yeah. I find it very unintuitive personally, especially coming from Rust. In Rust we have this:
// The long form
let mut contents = String::new();
let file = std::fs::File::open("my-path")?;
let n = file.read(&mut contents)?;
// The short form
let contents = std::fs::read_to_string("my-path")?;Both forms make it very obvious - in my opinion - what the code does.
When I saw the Python code, my mind didn't connect the dots at all before reading it multiple times and seeing how it is used by unprefixed(). I find the jump from a plain path to the contents of (a potential) file at that path very odd.
| return sorted({name for name in names if not name.startswith(f"{chart}.")}) | ||
|
|
||
|
|
||
| class TestCoreMethods(unittest.TestCase): |
There was a problem hiding this comment.
It is generally nice that there are some tests, but how exactly are they executed?
There was a problem hiding this comment.
That's documented right at the beginning of the file. They are not executed automatically.
There was a problem hiding this comment.
python3 -m unittest check_namespaced_defines.py
There was a problem hiding this comment.
But.... it might be relatively easy to add them to CI, I'll see about that.
There was a problem hiding this comment.
Should be possible. Question is if it should go into the prek file and then tested indirectly via github actions or directly into github actions and leave the test out of prek. Opinions?
There was a problem hiding this comment.
That's documented right at the beginning of the file. They are not executed automatically.
Ah I see. I kinda skipped that block of text. Could we maybe leave a simple comment here either stating the command or referring back to the top of the file?
Question is if it should go into the prek file and then tested indirectly via github actions or directly into github actions and leave the test out of prek. Opinions?
I would say add it to prek. For people who have it enabled locally to run on git commit, it will immediately be tested and validates that any potential change still passes. Additionally, we can more easily scope based on file paths.
Only having it in CI as a separate workflow delays the time one sees if the tests still pass - potentially leading to a follow-up fix commit.
* Rename vairable * Fix the locale so it doesn't depend on the machine * Switch to a named capture group
Adds a script called by prek which walks our charts and checks whether all defines/calls use a namespaced name
I tested it locally:
This was a checkout before the rollout of #645
It succeeds on main now.
stackabletech/issues#882