NodeBlock Docs CI - #2196
Conversation
shnizzedy
left a comment
There was a problem hiding this comment.
I'm all for more CI!
Is https://github.com/FCP-INDI/cpac-docs the future replacement for the main C-PAC docs repo (https://github.com/FCP-INDI/fcp-indi.github.io) or is it a component repo like https://github.com/FCP-INDI/C-PAC_tutorials ? I can't tell from that repo / this PR if it's already in use or just in preparation for future use.
I think all this functionality is just in service of the documentation CI, not anything happening in C-PAC itself. In that case, I think we should move the scripts from scripts to .github/scripts and add
.github/scripts/config_extractor.py
.github/scripts/nodeblock_docs.pyto .dockerignore after https://github.com/childmindresearch/C-PAC-test/blob/9c876c3a29a0ca97d4acfa7d6cfbd037f5ba9e44/.dockerignore#L7
OR these scripts and most of the workflow could live in https://github.com/FCP-INDI/cpac-docs and this repo could just add a workflow that triggers the workflow over there.
Not at all a blocker for merging this, but I think this would be easier to follow and maintain with more thorough type hints.
There's some wheel reinventing here that I'm not sure is necessary (but it might be? I'm also not sure it isn't necessary). I commented some suggestions, that, if accepted, I think several of the functions here could then be removed entirely.
| import sys | ||
|
|
||
| sys.path.append(".") | ||
|
|
||
| CPAC_DIR = pl.Path(".") | ||
| CONFIG_DIR = pl.Path("configs") | ||
|
|
||
| fetch_and_expand_all_cpac_configs(CPAC_DIR, CONFIG_DIR) | ||
|
|
||
| with open("nodeblock_index.json") as f: | ||
| nbs = json.load(f) | ||
|
|
||
| configs = {} | ||
|
|
||
| for config_path in CONFIG_DIR.glob("*.yml"): | ||
| with open(config_path, "r", encoding="utf-8") as handle: | ||
| config = yaml.safe_load(handle) | ||
|
|
||
| configs[config_path.stem] = config |
There was a problem hiding this comment.
We can use existing infrastructure to load all the preconfigs
| import sys | |
| sys.path.append(".") | |
| CPAC_DIR = pl.Path(".") | |
| CONFIG_DIR = pl.Path("configs") | |
| fetch_and_expand_all_cpac_configs(CPAC_DIR, CONFIG_DIR) | |
| with open("nodeblock_index.json") as f: | |
| nbs = json.load(f) | |
| configs = {} | |
| for config_path in CONFIG_DIR.glob("*.yml"): | |
| with open(config_path, "r", encoding="utf-8") as handle: | |
| config = yaml.safe_load(handle) | |
| configs[config_path.stem] = config | |
| from CPAC.pipeline import ALL_PIPELINE_CONFIGS | |
| from CPAC.utils.configuration.configuration import Configuration, Preconfiguration | |
| with open("nodeblock_index.json") as f: | |
| nbs = json.load(f) | |
| configs: dict[str, Configuration] = {config: Preconfiguration(config, skip_env_check=True) for config in ALL_PIPELINE_CONFIGS} |
and then we'll have a dict[str, Configuration] instead of a dict[str, dict] so we'll continue to have access to all the built-in methods
|
|
||
| configs_with_this_enabled = [] | ||
| for config_name, config in configs.items(): | ||
| if _any_true_in_config(config, paths): |
There was a problem hiding this comment.
If I'm reading this right and paths is what's in a switch key in a NodeBlock, if we load the configurations as Configurations instead of dicts, we could use the switch_is_on method like
| if _any_true_in_config(config, paths): | |
| if all(config.switch_is_on(switch) for switch in paths): |
and then we don't need a lot of the new infrastructure here.
There was a problem hiding this comment.
was about to add the changes I made over at the prototype repo, but using the config class directly is of course better.
Just for reference:
| def check_cpac_config( | ||
| config: dict, | ||
| ) -> tuple[Literal[True], None] | tuple[Literal[False], Exception]: | ||
| """Checks if the specified file is a valid C-PAC config file""" | ||
| from CPAC.utils.configuration.configuration import Configuration # noqa | ||
|
|
||
| try: | ||
| Configuration(config) | ||
| except Exception as e: | ||
| return False, e | ||
| return True, None |
| def find_nodeblocks(root_dir): | ||
| visitor = NodeBlockVisitor() | ||
| root_path = Path(root_dir) | ||
|
|
||
| # Walk through all Python files | ||
| for python_file in root_path.rglob('*.py'): | ||
| try: | ||
| with open(python_file, 'r', encoding='utf-8') as f: | ||
| source = f.read() | ||
| visitor.current_source = source.splitlines() | ||
| visitor.current_file = python_file.relative_to(root_path) | ||
| tree = ast.parse(source) | ||
| visitor.visit(tree) | ||
| except Exception as e: | ||
| print(f"Error processing {python_file}: {e}") | ||
|
|
||
| return visitor.nodeblocks |
There was a problem hiding this comment.
I think this is different enough that it's probably worth having both for now, but it's pretty similar to
C-PAC/CPAC/pipeline/resource_inventory.py
Lines 64 to 108 in b3521fc
There was a problem hiding this comment.
hey Jon, thanks for your comments - they're super helpful in understanding how CI will work best in this context :)
In regard to
Is https://github.com/FCP-INDI/cpac-docs the future replacement for the main C-PAC docs repo (https://github.com/FCP-INDI/fcp-indi.github.io) or is it a component repo like https://github.com/FCP-INDI/C-PAC_tutorials ? I can't tell from that repo / this PR if it's already in use or just in preparation for future use.
Yes, I'm using https://github.com/FCP-INDI/cpac-docs as the future replacement for the main C-PAC docs repo. At the time of this PR, it didn't have any content - we were just using it as a place to store nodeblock_index.json.
I opened an issue in that new repo here FCP-INDI/cpac-docs#12 to address the others. Looking forward to getting it all working!
| # Copy the JSON file to the target repo and commit it | ||
| - name: Commit documentation to target repo | ||
| run: | | ||
| cp source-repo/nodeblock_index.json target-repo/ |
There was a problem hiding this comment.
| cp source-repo/nodeblock_index.json target-repo/ | |
| cp source-repo/nodeblock_index.json target-repo/src/ |
There was a problem hiding this comment.
Now that FCP-INDI/cpac-docs#120 is merged, I think this change should address my suggestions re: FCP-INDI/cpac-docs#24
|
hi @shnizzedy, I applied the above suggestions - let me know if I missed something! Since I moved the scripts from |
shnizzedy
left a comment
There was a problem hiding this comment.
Sorry I missed this for 2 months. Yeah, I think it looks good! Once it's merged into main, we can see how it works and patch any bugs directly then.
Description
Adds continuous integration functionality for C-PAC documentation. The
nodeblock_index.jsonfile is populated with updated nodeblock documentation, which will then be read into https://github.com/FCP-INDI/cpac-docs.Technical details
Once merged, the C-PAC repo will also need the CPAC_DOC_REPO_ACCESS secret added.
Checklist
Update index.md).developbranch of the repository.Developer Certificate of Origin
Developer Certificate of Origin