Skip to content

Updated other uses of environment variables to use get_environment_variables - #834

Draft
elenya-grant wants to merge 5 commits into
NatLabRockies:developfrom
elenya-grant:env_vars/use_tools
Draft

Updated other uses of environment variables to use get_environment_variables#834
elenya-grant wants to merge 5 commits into
NatLabRockies:developfrom
elenya-grant:env_vars/use_tools

Conversation

@elenya-grant

@elenya-grant elenya-grant commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Updated other uses of environment variables to use get_environment_variables

Updated the other uses of environment variables (EIA API and setting custom resource of feedstock directories) to use the get_environment_variables function. The following functions were updated:

  • get_eia_api_key in h2integrate/preprocess/eia.py
  • check_data_dir in h2integrate/core/file_utils.py

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 2: Draft PR Checklist

  • Open draft PR
  • Describe the feature that will be added
  • Fill out TODO list steps
  • Describe requested feedback from reviewers on draft PR
  • [-] Complete Section 8: New Model Checklist (if applicable)

TODO:

  • Update doc page docs/getting_started/environment_variables.md
  • Update changelog

Type of Reviewer Feedback Requested (on Draft PR)

Structural feedback:

Implementation feedback:

  • Should the h2integrate/core/test/conftest.py be updated to have similar logic in place for FEEDSTOCK_DIR as there is for RESOURCE_DIR? (@RHammond2)

Other feedback:

  • Any use-cases that were not accounted for with this implementation?
  • Would love general feedback on the changes to the doc page I made!

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

This is intended to resolve issue #802 and issue #765

Section 5: Impacted Areas of the Software

Section 5.1: New Files

N/A

Section 5.2: Modified Files

  • h2integrate/core/file_utils.py
    • check_data_dir: updated to use get_environment_variables
  • h2integrate/preprocess/eia.py
    • get_eia_api_key: updated to use get_environment_variables
  • h2integrate/resource/utilities/nlr_developer_api_keys.py
    • get_nlr_developer_api_credential: updated doc string
  • docs/getting_started/environment_variables.md: updated documentation mostly related to RESOURCE_DIR

Section 6: Additional Supporting Information

Section 7: Test Results, if applicable

@elenya-grant elenya-grant added the ready for review This PR is ready for input from folks label Aug 11, 2026
@elenya-grant
elenya-grant requested a review from RHammond2 August 11, 2026 21:17
@elenya-grant
elenya-grant requested a review from johnjasa August 11, 2026 22:45

@RHammond2 RHammond2 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 the update, @elenya-grant! I just made one formatting suggestion, and this should be good from my perspective.

Comment on lines +60 to +67
raise ValueError(
"`EIA_API_KEY` has not been set. Please set the `EIA_API_KEY` environment variable."
)
if (eia_key := eia_api_key.get("EIA_API_KEY")) is not None:
return eia_key
raise ValueError(
"`EIA_API_KEY` has not been set. Please set the `EIA_API_KEY` environment variable."
)

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.

Suggested change
raise ValueError(
"`EIA_API_KEY` has not been set. Please set the `EIA_API_KEY` environment variable."
)
if (eia_key := eia_api_key.get("EIA_API_KEY")) is not None:
return eia_key
raise ValueError(
"`EIA_API_KEY` has not been set. Please set the `EIA_API_KEY` environment variable."
)
msg = "`EIA_API_KEY` has not been set. Please set the `EIA_API_KEY` environment variable."
raise ValueError(msg)
if (eia_key := eia_api_key.get("EIA_API_KEY")) is not None:
return eia_key
msg = "`EIA_API_KEY` has not been set. Please set the `EIA_API_KEY` environment variable."
raise ValueError(msg)

Just maintaining the original use of msg for multiline raises for traceback legibility.



def get_eia_api_key(api_key_file: Path | None) -> str:
def get_eia_api_key(api_key_file: Path | None, set_vars: bool = True) -> str:

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.

I'm not remotely opposed to this, and think it's good for API consistency, but just commenting that it's likely not at all necessary since all desired data can be downloaded with a single API call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review This PR is ready for input from folks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants