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

Implement JSON File Reading Utility #10

Open
angeloalvarez opened this issue Aug 12, 2024 · 2 comments
Open

Implement JSON File Reading Utility #10

angeloalvarez opened this issue Aug 12, 2024 · 2 comments
Assignees

Comments

@angeloalvarez
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

The primary use case for this utility is to read configuration files that can be integrated into the initialization process of an existing class. This will enhance the flexibility of the class by allowing configurations to be easily loaded and modified via external JSON files.

Describe the solution you'd like

I would like to implement a utility function for reading JSON files to enhance the way our project handles external configurations and data. The proposed solution involves creating a dedicated package within our project structure to manage file reading operations. Specifically, the read_json_file function will be designed to:

  • Accept a file path as an argument and return the contents of the file as either a dictionary or a list, depending on the JSON structure.

  • Handle common errors gracefully, such as when the file is not found or when the file contents are not valid JSON.

  • Be integrated with the initialization process of an existing class within our project, allowing the class to load its configuration from an external JSON file. This will provide greater flexibility in managing class configurations and reduce the need to hardcode settings directly into the code.

Describe alternatives you've considered

One alternative would be to continue hardcoding configurations directly within the class, but this would reduce flexibility and make it more difficult to update settings without modifying the code. Another option could involve using a different file format (e.g., YAML), with the potential for future support for YAML to allow even greater flexibility.

@thiarthur
Copy link
Owner

That's a great suggestion!
This solution will also allow Eolic to be configured by config maps on K8s clusters.

Since we are already using the pydantic models to handle serializable schemas, we could use BaseSettings or the regular BaseModel to handle json, yaml, toml and also some future configuration by environment variables

@angeloalvarez
Copy link
Collaborator Author

Thank you for your insightful suggestion!

I’ve made the necessary changes to the code to implement this solution, which will indeed allow Eolic to be configured using config maps on K8s clusters. By leveraging Pydantic's BaseSettings, we can now efficiently handle JSON, YAML, TOML configurations, and future environment variable setups.

I hope this approach works well for you! If you have any thoughts or suggestions, I’d love to hear them!

feat/config-file

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

When branches are created from issues, their pull requests are automatically linked.

2 participants