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

Feat/configuration module #215

Merged
merged 18 commits into from
May 6, 2024

Conversation

mgcooper
Copy link
Contributor

@mgcooper mgcooper commented May 5, 2024

This pull request adds a configuration subpackage to simplify setting up and managing paths within pyflowline.

Key Changes

  1. Moved the configuration functions into a new subpackage pyflowline.configuration.
  2. Added a path_manager module within configuration, to programmatically retrieve and build paths:
    • pyflowline_project_root(): Returns the top-level project path.
    • pyflowline_package_root(): Returns the package path, akin to how pkg_resources manages package roots.
  3. Added a little test script to ensure the paths are retrieved correctly.

Usage Examples:

from pyflowline.configuration import path_manager as pyflowline_path_manager

# Define paths using the new path_manager
sFolder_input = pyflowline_path_manager.join_project_path('data', sDomainName, 'input')
sFolder_output = pyflowline_path_manager.join_project_path('data', sDomainName, 'output')

path_manager returns Path objects, so I added conversions to str() in the configuration functions. I tried to ensure the updates are platform / os agnostic, but happy to revisit if the previous use of realpath is preferable.

mgcooper and others added 18 commits May 5, 2024 11:59
… module.

This commit only moves the functions, and is thus breaking.
Rename from pyflowline_create_basin_template_configuration_file to pyflowline_create_template_basin_configuration_file for consistency with the main method. This has no side effects.
This fixes the imports of the read_configuration_file, change_json_key_value, and other configuration functions used to set json file parameters in the demos with the new module syntax. This also fixes various smaller bugs in the mpas example so it runs without error. The overall layout of the mpas example was also updated so all the parameters are defined up top so its clearer to users what values need to be modified. A subsequent commit will programmatically update the paths to make it easier, but this commit serves as a marker of a working set of demos using the new configuration module syntax.
This will enable programmatic setting of project paths in the examples and demos and json files.
…fects.

This refactor writes to a tempfile in case the function errors early. This should be os agnostic.
The purpose is to handle both realpath (str) and Path objects. With Path objects its easier to use the joinpath method, but a dedicated function will help ensure compatibility if path_manager is adopted more widely in the project.
This replaces realpath with Path and converts to str where needed, however, the Path objects are fully compatible with the configuration module functions. Conversion to string was only done for compatibility with the Hungarian notation convention e.g., sFolder_output is now oFolder_output.
It is necessary to check if optional path inputs are Path if they are set to None by default, unlike the required inputs which can be converted to str without any isinstance
@changliao1025 changliao1025 merged commit 1ad9acb into changliao1025:main May 6, 2024
0 of 4 checks passed
@changliao1025
Copy link
Owner

@mgcooper
We can change pyflowline_change_json_key_value to change_json_key_value, later on we can move this function into pyearth so it is universal.

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