Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config.conf and logic to handle config files #664

Merged
merged 51 commits into from
Mar 17, 2024
Merged

Conversation

Rekt3421
Copy link
Contributor

@Rekt3421 Rekt3421 commented Feb 1, 2024

Adds configs from .conf file, I decided to go against using individual sections to append the name further since we can do so by keeping everything in a unordered map. Env vars are given priority. Addresses issue #631

@Rekt3421 Rekt3421 marked this pull request as draft February 1, 2024 17:56
@Rekt3421 Rekt3421 marked this pull request as ready for review February 2, 2024 17:15
@rjodinchr
Copy link
Contributor

I think we need to think about the path of that file. Where should it be? Should we consider multiple possibilities? like /etc/something as well as <current_directory> for example.

@Rekt3421
Copy link
Contributor Author

Rekt3421 commented Feb 2, 2024

@rjodinchr I think you are right either we should make a file under /etc/something for system specific configs perhaps? and check the current directory as well. Maybe we can populate a file based on customized configs based on the platform? I am not quite sure myself. WDYT?

Copy link
Owner

@kpet kpet left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution!

I'm wondering whether we should also add the ability to select a config file from the environment using a variable (e.g. CLVK_CONFIG_FILE=/path/to/clvk.conf.

We also need to think through how we could test the ability to load config files automatically. Testing all cases would be hard but I think we should at least have some testing.

src/config.cpp Outdated Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
src/config.hpp Outdated Show resolved Hide resolved
src/config.hpp Outdated Show resolved Hide resolved
src/config.toml Outdated Show resolved Hide resolved
@Rekt3421 Rekt3421 marked this pull request as draft February 5, 2024 21:22
@Rekt3421 Rekt3421 changed the title Add config.toml and logic to handle config files Add config.conf and logic to handle config files Feb 6, 2024
src/config.cpp Outdated Show resolved Hide resolved
@rjodinchr
Copy link
Contributor

have a look at https://github.com/kpet/clvk/blob/main/src/log.hpp, and then change all the prints please.

src/config.hpp Outdated Show resolved Hide resolved
tests/config/CMakeLists.txt Outdated Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
tests/config/main.cpp Outdated Show resolved Hide resolved
tests/config/run_test.sh Outdated Show resolved Hide resolved
tests/config/run_test.sh Outdated Show resolved Hide resolved
tests/config/run_test.sh Outdated Show resolved Hide resolved
src/config.hpp Outdated Show resolved Hide resolved
@Rekt3421 Rekt3421 requested a review from kpet February 16, 2024 19:27
src/config.cpp Outdated Show resolved Hide resolved
src/config.cpp Show resolved Hide resolved
Copy link
Owner

@kpet kpet left a comment

Choose a reason for hiding this comment

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

Nice work! This is missing a few finishing touches and documentation. Ideally we'd rework the section on environment variables into a more generic description of the config system, explaining that there is support for files and environment variables. If you're unsure of how to go about it, then just document CLVK_CONFIG_FILE and we can do the rest later.

I'm sure we will need to spend more time on config file path management and system integration but this PR is good enough as a first step IMO.

tests/config/run_test.sh Outdated Show resolved Hide resolved
tests/config/run_test.sh Outdated Show resolved Hide resolved
src/config.cpp Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
src/config.cpp Show resolved Hide resolved
tests/config/clvk.conf Show resolved Hide resolved
tests/config/run_test.sh Show resolved Hide resolved
.github/workflows/presubmit.yml Outdated Show resolved Hide resolved
src/config.cpp Show resolved Hide resolved
src/config.cpp Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
src/log.cpp Show resolved Hide resolved
tests/config/run_test.sh Outdated Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
tests/config/run_test.sh Outdated Show resolved Hide resolved
src/log.cpp Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
Copy link
Owner

@kpet kpet left a comment

Choose a reason for hiding this comment

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

Let's call this good enough. I'll tidy up on top.

Comment on lines +410 to +413
* `CLVK_CONFIG_FILE` specifies the path to a configuration file. You can see a
sample of the file under test/config/conf_test.conf. The file specified by env
var takes precedence over all other config files but does not take precedence
over env variable defined values.
Copy link
Owner

Choose a reason for hiding this comment

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

s/env/environment/g

config_file_paths.push_back(
(std::filesystem::current_path() / conf_file).string());
// First check if env var has file
std::string conv_file_env_var = "CLVK_CONFIG_FILE";
Copy link
Owner

Choose a reason for hiding this comment

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

Why did you introduce a function to compose the name of environment variables used for configuration without using it?


for (auto& opt : gConfigOptions) {
if (file_config_values.find(opt.name) == file_config_values.end() ||
file_config_values[opt.name].length() == 0) {
Copy link
Owner

Choose a reason for hiding this comment

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

I think we don't need to check that the length is zero since option values only get stored in the map if they are not empty strings (see read_config_file).

@@ -90,8 +199,9 @@ void parse_env() {

} // namespace

void init_config_from_env_only() { parse_env(); }
Copy link
Owner

Choose a reason for hiding this comment

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

Why are we now parsing the environment config twice?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kpet kpet merged commit 53a962d into kpet:main Mar 17, 2024
9 checks passed
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