redhataccess / pantheon-cmd

Pantheon CMD is an open source and freely distributed program for validating and building local previews of modular documentation.
GNU General Public License v3.0
2 stars 5 forks source link

Create a function to validate the structure of a pantheon2.yml file #12

Closed adahms closed 3 years ago

adahms commented 3 years ago

Today, pantheon-cmd assumes the structure of a pantheon2.yml file is correct. While this is sufficient for testing purposes, out in the real world, it will need to validate that the structure of this file is correct before doing anything, or users might become frustrated when attempting to use a command and not understand why it fails. It also enforces good practice around pantheon2.yml files, and ensures that before anything can compile, several basic issues are resolved.

It should probably -

Moreover, some of these should be an error, whereas others can be warnings. For example, if the attributes file is missing, it shouldn't go any further. However, if it finds duplicate or non-existent files, perhaps it's enough to simply warn the user, skip any broken files, and keep going.

adahms commented 3 years ago

@Levi-Le - another one to review. :)

Levi-Leah commented 3 years ago

@adahms this commit partially addresses what you've outlined here - 66ceffe

it checks if all keys exist, in our case it's server, repository, variants, assemblies, modules, resources. if one of them is missing - it throws and error. if all exist - it checks values and if path to attribute file/images dir exists. (it validates canonical only if set to true but I can change that. for some reason I assumed it's a must but maybe not.)

I'm probably missing something here, so feel free to correct me.

I'm not sure we should include duplicates here as we got a separate check for it and some teams do it intentionally, but that's up for discussion.

I put this check as another command line option for now but we can integrate it at a different stage. Let me know what you think.

Regarding assemblies without modules, I actually have a validation in mind briefly outlined here https://github.com/redhataccess/pantheon-cmd/issues/7, but I ran into troubles when the path in includes is specified through an attribute (e.g. {some-attribute}/module.adoc) or is relative (e.g. ../modules-dir/some-module.adoc)

FYI, the messages are not very descriptive so I'm very much open to suggestions.

adahms commented 3 years ago

Thanks @Levi-Le!

I added some comments, but the majority are more around general conventions than anything to do with actual problems themselves.

Interesting point about duplicates, and agreed. The checks you've added all make sense to me, and I'd be curious to hear more about teams adding duplicate entries intentionally as well. I suspect there's something there I'm not seeing.

Love the idea in #7 about thoroughly checking whether all the modules an assembly are included in the yaml file. It opens a deeper architectural question over whether PV2 should simply automatically grab those without needing to define them in the yaml file at all, but perhaps that's not something we can tackle at this stage. :)

Levi-Leah commented 3 years ago

Path to images dir does not resolve if defined as images/**. Code needs to be rewritten with glob.glob