Skip to content

ociocheck to check OpenColorIO library version first#2310

Open
meimchu wants to merge 5 commits into
AcademySoftwareFoundation:mainfrom
meimchu:feature/config_exists_check
Open

ociocheck to check OpenColorIO library version first#2310
meimchu wants to merge 5 commits into
AcademySoftwareFoundation:mainfrom
meimchu:feature/config_exists_check

Conversation

@meimchu
Copy link
Copy Markdown
Contributor

@meimchu meimchu commented May 13, 2026

The idea behind this PR originated with me using ociocheck and getting stuck with config read error (#2303). So I just wanted clearer error message when the error was due to the file path provided being non-existent. Upon looking at the existing issues, I noticed there is an issue about removing pystring dependency (#2256). So I took this opportunity to get started by adding PathUtils::IsPathAbs(), PathUtils::NormalizePath()... etc with standard library filesystem and using them in Config. Also a change to ExceptionMissingFile raised if file does not exist. (Can revert back to just raise Exception if it's causing too much API change)

I would appreciate if @KevinJW has any thought about this as a starting point and the right track. Thank you!

meimchu added 3 commits May 13, 2026 00:01
Signed-off-by: Mei Chu <meimchu@gmail.com>
Signed-off-by: Mei Chu <meimchu@gmail.com>
Signed-off-by: Mei Chu <meimchu@gmail.com>
@meimchu meimchu marked this pull request as draft May 13, 2026 07:57
if (!filename || !*filename)
{
throw ExceptionMissingFile ("The config filepath is missing.");
throw ExceptionMissingFile("The config filepath is missing.");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably OK for now, but it is worth noting that as you highlighted in the issue this condition isn't quite the same as a missing file. ideally we'd have a different type for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Though should I switch this to just OCIO::Exception for now then? Ultimately it's a runtime error so it kind of fits!

Comment thread src/OpenColorIO/Config.cpp Outdated
// working directory must be an absolute path.
const char * workingDirectory = getWorkingDir();
if ((workingDirectory && !workingDirectory[0]) || !pystring::os::path::isabs(workingDirectory))
if ((workingDirectory && !workingDirectory[0]) || !IsPathAbs(workingDirectory))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My gut suggests we should deal with the switch away from the pystring implementation as a separate issue to cleaning up the error messages. Changing the implementation to use std::filesystem could have more subtle issues

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issue with that. I can reduce the scope of this specific change to just simply a better message if config file does not exists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted changes done to PathUtil which can be put in a separate PR.

Comment thread src/OpenColorIO/PathUtils.cpp Outdated
return (!hash.empty());
}

bool FileExists(const std::string & filename)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an example of the subtlety When comparing this function with the other overload

bool FileExists(const std::string & filename, const Context & context)

Shows a much more complicated implementation which immediately makes me wonder why. Should we be dealing with the IOProxy here or not, if not then should the function have a different name? or at least a clear documentation stating why etc.

At this point I have not reasoned this through as I don't have the understanding of the IOProxy workings without studying it.

Copy link
Copy Markdown
Contributor Author

@meimchu meimchu May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is all good points. I cannot say for sure myself about that other particular FileExists overload. I see it being used for trying to find lut files with search_path context. I have no issue with it being a different name when we want to replace pystring::path usages!

Perhaps we can create our own internal pystring-like module that basically does some of those pystring tasks that we use then? That was sort of where I was heading by adding these path-related stuff to PathUtil.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted changes done to PathUtil which can be put in a separate PR.

meimchu added 2 commits May 14, 2026 15:28
Signed-off-by: Mei Chu <meimchu@gmail.com>
Signed-off-by: Mei Chu <meimchu@gmail.com>
@meimchu meimchu marked this pull request as ready for review May 15, 2026 00:40
@meimchu
Copy link
Copy Markdown
Contributor Author

meimchu commented May 15, 2026

For now, I've reverted the more ambitious changes and opted for a targeted solution. I looked a little deeper into the existing PathUtils::FileExists function which seems caching file hash within a context. My shallow understanding is that it helps speed up the various lut files found via search_path. I also tried creating an empty context to try to utilize that same FileExists() with the config file path but it doesn't feel right to me.

The primary impact of this though is that ExceptionMissingFile() is raised if input file path does not exist. Relying on ifstream.fail() for other reasons why reading that file could fail.

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.

2 participants