Skip to content

Make checking function accessible from python interpreter#33

Open
aulemahal wants to merge 3 commits into
NCAS-CMS:mainfrom
WCRP-CORDEX:usable-in-interpreter
Open

Make checking function accessible from python interpreter#33
aulemahal wants to merge 3 commits into
NCAS-CMS:mainfrom
WCRP-CORDEX:usable-in-interpreter

Conversation

@aulemahal

Copy link
Copy Markdown

Hi all!

Maybe I should have opened an issue before pushing a PR ? Anyway, this took me only a few minutes.

In a goal of running check_cmip7_packing from inside a python script without having to make a system call and parse the result, I suggest here taking the core checking functionality and making it a standalone function that can be imported.

Reading errors are still managed externally and parsing errors are passed along using a custom error class. The function returns a boolean and a string detailing the reason for the result.

I'm not sure if this was needed, but without this change the check_cmip7_packing script was usable even if cmip7_repack was not installed in a python environment. I tried to preserve this possibility here with a try..except when importing.

Tested by running one two files (one passing and one failing) from inside an interpreter:

from cmip7_repack import check_cmip7_packing

check_cmip7_packing(filename)

and from the CLI. Also ran the same "tests" from the CLI outside the environment (pyfive available, but cmip7_repack not installed).

For my use case, this is the minimal importable stuff I need, but it could be interesting to also have access to the functions in cmip7_repack that compute the metadata blocksize and chunksizes, etc. I could maybe suggest another PR if there's interest.

What do you guys think ? Is this useful ?

@jesusff

jesusff commented May 21, 2026

Copy link
Copy Markdown

Pascal, this is maybe related to these functions which already exist in the quality checker
https://github.com/ESGF/cc-plugin-wcrp/blob/54398a09d208e2d8141d24087e3c734df241dea6/checks/format_checks/check_internal_packing.py

The code is becoming hard to maintain as copies and forks are proliferating to be able to tweak the default hard-coded behaviour. A flexible central code that others can just invoke with different parameters would be simpler

@aulemahal

Copy link
Copy Markdown
Author

Ah yes indeed, I didn't see that.
I thought this repo was the central code which is why I suggested this here!

@valeriupredoi

Copy link
Copy Markdown
Contributor

@aulemahal Pascal, many thanks, mate! As noted above, this is the source repo for the CMIP7 repack checker, but it's not where it's being used by ESGF; your implementation makes sense in order to add a bit more reach via Python API, and I support it, but I am also CCing my colleagues @davidhassell and @zequihg50 that are the actual developers of the package - I am devops, and from my packaging/operational PoV it's fine, but we'd need a few more tests from you 🍺

@valeriupredoi

Copy link
Copy Markdown
Contributor

ping @davidhassell and @zequihg50 gents, what say you about this implement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants