Skip to content

Conversation

NaniNoni
Copy link

@NaniNoni NaniNoni commented Jul 9, 2025

Describe your changes

I implemented the print_config_info command to allow for easily checking which config files are loaded. This is especially useful when f3d is ran not from the command line.

f3d_print_config_info

Issue ticket number and link if any

#2349

Checklist for finalizing the PR

  • I have performed a self-review of my code
  • I have added tests for new features and bugfixes
  • I have added documentation for new features
  • If it is a modifying the libf3d API, I have updated bindings
  • If it is a modifying the .github/workflows/versions.json, I have updated timestamp

Continuous integration

Please check the checkbox of the CI you want to run, then push again on your branch.

  • Style checks
  • Fast CI
  • Coverage cached CI
  • Analysis cached CI
  • WASM docker CI
  • Android docker CI
  • macOS Intel cached CI
  • macOS ARM cached CI
  • Windows cached CI
  • Linux cached CI
  • Other cached CI

// Clear config file paths to avoid reading them if dryRun is set
if (dryRun)
{
actualConfigFilePaths.clear();
Copy link
Member

Choose a reason for hiding this comment

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

insteaed you may want to just return ?

Copy link
Author

Choose a reason for hiding this comment

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

Yes I will do that

Copy link
Member

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

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

looks good!

Please add a test though, you can look at

application/testing/CMakeLists.txt:1101

TestCommandScriptPrintScene and copy the logic.

@snoyer
Copy link
Contributor

snoyer commented Jul 10, 2025

Nice! thanks @NaniNoni

As it is, from a user point of view, this could answer "where are the current config files?" but not "where should I create my config file?" as only the existing files are listed?

How about removing the fs::exists check from GetConfigPaths

if (fs::exists(configPath))
and handling it in ReadConfigFiles where both existing and non-existing files could be logged accordingly?

@NaniNoni
Copy link
Author

looks good!

Please add a test though, you can look at

application/testing/CMakeLists.txt:1101

TestCommandScriptPrintScene and copy the logic.

Thank you, will do

@NaniNoni
Copy link
Author

I fixed/implemented the requested changes. However, in the loop over canonical paths, I ended up using debug instead of print(logLevel, ...) due to the large amount of unwanted output when the config files were actually being read when f3d is launched. I think the level of output is appropriate now, but it just makes the logLevel parameter slightly misleading since it no longer applies to all internal log calls.

// Recover an absolute canonical path to config file
try
{
  configPath = fs::canonical(fs::path(configPath)).string();
}
catch (const fs::filesystem_error&)
{
  // This (file not found) error is expected in dry run mode
  if (dryRun)
  {
    f3d::log::print(logLevel, "Found available config location ", configPath.string());
  }
  else
  {
    f3d::log::debug(
      "Configuration file does not exist: ", configPath.string(), " , ignoring it");
  }
  continue;
}

}
configPath = dir / configName;
paths.emplace_back(configPath);
f3d::log::debug("Found potential config file: ", configPath.string());
Copy link
Member

Choose a reason for hiding this comment

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

So you changed the logic a bit so that GetConfigPath does not check existence.

TBH I dont think this is needed. You can control the logLevel instead so it doesnt debug only.

Copy link
Member

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

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

not convinced by the new impl :/

@snoyer
Copy link
Contributor

snoyer commented Jul 12, 2025

Would it be better to improve the separation of concerns between GetConfigPaths and ReadConfigFiles instead of trying to include the user-facing logging into ReadConfigFiles with a dry-run param?

The idea would be:

  • GetConfigPaths returns both the candidate config files and search directories (whether they exist or not)
  • ReadConfigFiles iterates over the result of GetConfigPaths, reading the items that are file files and recursing into the items that are dirs
  • the print_config_info command uses only GetConfigPaths to print "found this files, would have used that file, would check that dir, ..." without having to do a full dry run of ReadConfigFiles

@NaniNoni
Copy link
Author

Would it be better to improve the separation of concerns between GetConfigPaths and ReadConfigFiles instead of trying to include the user-facing logging into ReadConfigFiles with a dry-run param?

The idea would be:

* `GetConfigPaths` returns both the candidate config files and search directories (whether they exist or not)

* `ReadConfigFiles` iterates over the result of `GetConfigPaths`, reading the items that are file files and recursing into the items that are dirs

* the `print_config_info` command uses only `GetConfigPaths` to print "found this files, would have used that file, would check that dir, ..." without having to do a full dry run of `ReadConfigFiles`

I like this idea a lot

@NaniNoni
Copy link
Author

I implemented the requested changes. The only downside I'm aware of is that the print_config_info command considers "config" as the only configSearch query for GetConfigPaths. I think this may cause an issue for different config locations.

std::vector<std::filesystem::path> availableConfigPaths =
        F3DConfigFileTools::GetConfigPaths("config");

@NaniNoni NaniNoni requested a review from mwestphal July 14, 2025 21:29
@snoyer
Copy link
Contributor

snoyer commented Jul 15, 2025

The only downside I'm aware of is that the print_config_info command considers "config" as the only configSearch query for GetConfigPaths

You'd have to track down where the configSearch param comes from for the real GetConfigPaths call and store that somewhere to reuse it in print_config_info. I don't know what the proper way to do it would but I'm sure @mwestphal will

Copy link
Member

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

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

I'm confused by this implementation. It looks to me this will not output anything about config files now ? We want the same or at least a similar output when --verbose is used.

configPath = fs::canonical(fs::path(configPath)).string();
}
catch (const fs::filesystem_error&)
if (!fs::exists(configPath))
Copy link
Member

Choose a reason for hiding this comment

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

you need a try catch around this call

@NaniNoni
Copy link
Author

I'm confused by this implementation. It looks to me this will not output anything about config files now ? We want the same or at least a similar output when --verbose is used.

Yes, you're right. That's another problem. Previously to these changes, the GetConfigPaths function checked for file existence and logged in debug if they didn't (because that was expected). Now, the existence check moved to ReadConfigFiles. ReadConfigFiles also had an existence check, but logged the results in error verbosity, since the files checked was supposed to exist at that point.

Now, the existence check in ReadConfigFiles cannot be an error, since it's sort of equivalent to the one we had before in GetConfigPaths. What do you think?

@NaniNoni
Copy link
Author

The only downside I'm aware of is that the print_config_info command considers "config" as the only configSearch query for GetConfigPaths

You'd have to track down where the configSearch param comes from for the real GetConfigPaths call and store that somewhere to reuse it in print_config_info. I don't know what the proper way to do it would but I'm sure @mwestphal will

Yes I agree. @mwestphal how would you like this to work?

@mwestphal
Copy link
Member

The only downside I'm aware of is that the print_config_info command considers "config" as the only configSearch query for GetConfigPaths

You'd have to track down where the configSearch param comes from for the real GetConfigPaths call and store that somewhere to reuse it in print_config_info. I don't know what the proper way to do it would but I'm sure @mwestphal will

Yes I agree. @mwestphal how would you like this to work?

Alright, actually your implementation is not far off!

How about adding another method:

F3DConfigFileTools::PrintConfigInfo(const std::vector<fs::path>&)

that prints output using log::info like this by checking the file/dir existence:

Candidate config file not found: /etc/f3d/config.json
Candidate config file not found: /etc/f3d/config.d
Candidate config file not found: /usr/share/f3d/configs/config.json
Candidate config file not found: /usr/share/f3d/configs/config.d
Candidate config file not found: /home/glow/dev/f3d/others/F3D-3.2.0-RC2-Linux-x86_64-raytracing/share/f3d/confi
Config file found: /home/glow/dev/f3d/others/F3D-3.2.0-RC2-Linux-x86_64-raytracing/share/f3d/configs/config.d
Candidate config file not found: /home/glow/.config/f3d/config.json
Candidate config file not found: /home/glow/.config/f3d/config.d

And use it in print_config_info always and in F3DConfigFileTools::ReadConfigFiles if verbose == debug.

@mwestphal
Copy link
Member

Hi @NaniNoni , how is it going ? Do you need any help ?

1 similar comment
@mwestphal
Copy link
Member

Hi @NaniNoni , how is it going ? Do you need any help ?

@NaniNoni
Copy link
Author

Hi, sorry for the delay. I've been away and then unexpectedly very busy, but I've implemented the changes and it should hopefully be closer to the desired implementation. However, the quoted comment below is still unresolved. How would you like this to work?

The only downside I'm aware of is that the print_config_info command considers "config" as the only configSearch query for GetConfigPaths

You'd have to track down where the configSearch param comes from for the real GetConfigPaths call and store that somewhere to reuse it in print_config_info. I don't know what the proper way to do it would but I'm sure @mwestphal will

/**
* Recover a OS-specific vector of potential config file directories
*/
std::vector<std::filesystem::path> GetConfigPaths(const std::string& configSearch);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::vector<std::filesystem::path> GetConfigPaths(const std::string& configSearch);
std::vector<fs::path> GetConfigPaths(const std::string& configSearch);

@mwestphal mwestphal marked this pull request as ready for review August 20, 2025 11:32
Copy link
Member

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

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

It looks good. I found a small issue to fix. Next time you push the CI will run.

@mwestphal mwestphal requested a review from snoyer August 20, 2025 11:33
Comment on lines +73 to +85
void F3DConfigFileTools::PrintConfigInfo(const std::vector<fs::path>& configPaths)
{
for (const fs::path& path : F3DConfigFileTools::GetConfigPaths("config"))
{
if (fs::exists(path))
{
f3d::log::info("Config file found: ", path);
}
else
{
f3d::log::info("Candidate config file not found: ", path);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say we can get rid of this method and log specifically in ReadConfigFiles and the print_config_info command

Copy link
Contributor

@snoyer snoyer Aug 20, 2025

Choose a reason for hiding this comment

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

I mean doing something like

      for (const fs::path& path : F3DConfigFileTools::GetConfigPaths("config"))
      {
        f3d::log::info("- ", path, fs::exists(path) ? "(found)" : "(not found)");
      }

in the command and logging in the existing if (!fs::exists(configPath)) branches in ReadConfigFiles() (and it may not need to be info level there?)

Copy link
Member

Choose a reason for hiding this comment

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

I dont think that works ?

Copy link
Member

Choose a reason for hiding this comment

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

ha right, sure, that works too :)

@mwestphal
Copy link
Member

@NaniNoni you need to rebase on latest master

@mwestphal
Copy link
Member

Hi @NaniNoni , need any help moving forward ?

1 similar comment
@mwestphal
Copy link
Member

Hi @NaniNoni , need any help moving forward ?

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