Skip to content

Enhancement: Make check_resource_dir a general data folder routine#791

Merged
johnjasa merged 19 commits into
NatLabRockies:developfrom
RHammond2:feature/resourece-dir-to-file-utils
Jul 6, 2026
Merged

Enhancement: Make check_resource_dir a general data folder routine#791
johnjasa merged 19 commits into
NatLabRockies:developfrom
RHammond2:feature/resourece-dir-to-file-utils

Conversation

@RHammond2

@RHammond2 RHammond2 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Enhancement: Make check_resource_dir a general data folder routine

This PR is in service of #777 to enable the usage of the functionality in h2integrate/resource/utilities/file_tools.py::check_resource_dir more broadly applicable to other data types (e.g. feedstocks). By creating the general check_data_dir with a thin wrapper for check_resource_dir that populates the data_type arg with "resource" much of the same usage is maintained through the resource data classes. Similarly the existing tests are able to be used with comparable test coverage and minimal changed code.

Section 1: Type of Contribution

  • Feature Enhancement
    • Framework
    • New Model
    • Updated Model
    • Tools/Utilities
    • Other (please describe):
  • Bug Fix
  • Documentation Update
  • CI Changes
  • Other (please describe):

Section 3: General PR Checklist

  • PR description thoroughly describes the new feature, bug fix, etc.
  • Added tests for new functionality or bug fixes
  • Tests pass (If not, and this is expected, please elaborate in the Section 6: Test Results)
  • Documentation
    • Docstrings are up-to-date
    • Related docs/ files are up-to-date, or added when necessary
    • Documentation has been rebuilt successfully
    • Examples have been updated (if applicable)
  • CHANGELOG.md
    • At least one complete sentence has been provided to describe the changes made in this PR
    • After the above, a hyperlink has been provided to the PR using the following format:
      "A complete thought. [PR XYZ]((https://github.com/NatLabRockies/H2Integrate/pull/XYZ)", where
      XYZ should be replaced with the actual number.

Section 4: Related Issues

N/A

Section 5: Impacted Areas of the Software

Section 5.1: New Files

N/A

Section 5.2: Modified Files

  • h2integrate/resource/utilities/file_tools.py: removed in favor of moving check_resource_dir to the below modified file.
  • h2integrate/core/utilities/file_utils.py:
    • check_data_dir: General data_type checking data directory checking with default handling, exactly as prescribed from the previous check_resource_dir, except with the flexibility of working with multiple data_type, e.g. "resource", "feedstock", or whatever types of data might be used later.
    • check_resource_dir: partial function of check_data_dir with data_type="resource" pre-populated.
    • check_feedstock_dir: Same as above, but for "feedstock".
  • h2integrate/core/test/test_utilities.py
    • temp_resource_dir_env: New fixture to ensure the environment variable is set and unset regardless of a test failure.
    • test_check_resource_dir_environment_var : uses a fixture to modify the RESOURCE_DIR environment variable.
  • test/conftest.py:
    • pytest_sessionstart: Stores the original RESOURCE_DIR value in a temporary variable.
    • pytest_sessionfinish: Restores the original `RESOURCE_DIR value from the temporary variable.

Section 6: Additional Supporting Information

This PR stems from a tangential issue in #777 where there is a need to reuse existing functionality, but is hard-coded for a specific use case making this work worthy of its own PR.

Section 7: Test Results, if applicable

@RHammond2 RHammond2 requested a review from elenya-grant June 23, 2026 23:37
@RHammond2 RHammond2 added enhancement New feature or request Tools/Utilities Tools and utilities that are used in H2I or for pre-processing or post-processing labels Jun 23, 2026
@RHammond2 RHammond2 requested review from johnjasa and removed request for johnjasa June 25, 2026 20:08

@elenya-grant elenya-grant left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for working on generalizing this method, Rob! I think it's a pretty slick solution you've come up with. I have some small comments and questions on the PR but they should be pretty simple.

I don't believe I've seen any new tests for the check_data_dir or check_feedstock_dir. I think it could be good to add some basic tests on check_data_dir to ensure that new errors are thrown when expected. It may also be good to have one test with check_feedstock_dir just to check that it works before that directory exists in H2I.

Thanks for working on this! If it came in as-is I wouldn't have any concerns. All my comments are pretty small and non-blocking.

Update: can you update the doc page docs/getting_started/environment_variables.md for setting the FEEDSTOCK_DIR as an environment variable (this could also happen in your other PR)

Comment on lines +530 to +534
check_resource_dir = partial(check_data_dir, data_type="resource")
update_wrapper(check_resource_dir, check_data_dir)

check_feedstock_dir = partial(check_data_dir, data_type="feedstock")
update_wrapper(check_feedstock_dir, check_data_dir)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

are these lines supposed to be here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what do they do? I've never seen partial or update_wrapper used. Could you add some in-line comments?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

partial functions create wrapper functions with the args/kwargs partially passed. It's a convenient way to pre-fill function calls with common parameterizations. For instance, check_resource_dir is now just a wrapper equal to check_data_dir(data_type="resource"), enabling the resource classes to use basically the same folder checking function calls as before this PR.

update_wrapper simply applies the docstring from one function to another, and is primarily for partial functions so that they can also have documentation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

that is very slick! Thanks for explaining that!

Comment thread h2integrate/resource/solar/test/test_resource_models.py
Comment thread h2integrate/__init__.py Outdated
Comment thread h2integrate/core/file_utils.py
@johnjasa johnjasa self-requested a review June 30, 2026 21:53
Comment thread h2integrate/core/test/test_utilities.py Outdated
@elenya-grant elenya-grant self-requested a review July 1, 2026 22:56
@RHammond2 RHammond2 requested review from johnjasa and removed request for johnjasa July 1, 2026 23:15
@RHammond2 RHammond2 requested review from johnjasa and removed request for johnjasa July 1, 2026 23:35

@elenya-grant elenya-grant left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks great Rob! Thanks for working through the annoying debugging process and making this method generalizable! I think this looks awesome!

@johnjasa johnjasa requested review from johnjasa and removed request for johnjasa July 6, 2026 15:56

@johnjasa johnjasa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this, @RHammond2 and @elenya-grant, and I'm sorry it was such a bear to debug! Really glad you got it working so well.

@johnjasa johnjasa merged commit d9eb193 into NatLabRockies:develop Jul 6, 2026
11 of 12 checks passed
@RHammond2 RHammond2 deleted the feature/resourece-dir-to-file-utils branch July 6, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Tools/Utilities Tools and utilities that are used in H2I or for pre-processing or post-processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants