Skip to content

US_EIA Fix import path#2072

Open
kartik-s21 wants to merge 22 commits into
datacommonsorg:masterfrom
kartik-s21:fix-eia-import-path
Open

US_EIA Fix import path#2072
kartik-s21 wants to merge 22 commits into
datacommonsorg:masterfrom
kartik-s21:fix-eia-import-path

Conversation

@kartik-s21

@kartik-s21 kartik-s21 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a ModuleNotFoundError: No module named 'util' error that blocked the execution of us_eia scripts (both locally and when running in cloud environments).
The issue arose because of a recent change in the shared util/ package, which broke the legacy directory-appending strategy used by the EIA ingestion scripts.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds the repository root directory to sys.path in scripts/us_eia/opendata/process/common.py. The reviewer notes that adding both the root directory and the util/ subdirectory to sys.path is a Python anti-pattern that can cause duplicate module loading, and recommends transitioning to absolute imports.

Comment thread scripts/us_eia/opendata/process/common.py
@kartik-s21 kartik-s21 changed the title us_eia Fix import path US_EIA Fix import path Jun 17, 2026
_MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
_SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(_SCRIPT_PATH, '../../../../util/'))
sys.path.append(os.path.join(_SCRIPT_PATH, '../../../../'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did not realize that it could break the import scripts. I wonder if it can impact other imports as well. Instead of fixing various imports, can we revert the changes to file_util.py in my PR and instead handle it in differ_utils.py

-from util.file_util import FileIO
-from util.file_util import file_get_matching
+import sys
+_SCRIPT_DIR = os.path.dirname(os.path.abspath(file))
+_DATA_DIR = os.path.dirname(os.path.dirname(_SCRIPT_DIR))
+sys.path.append(os.path.join(_DATA_DIR, 'util'))
+
+from file_util import FileIO
+from file_util import file_get_matching

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes sure this will be fine.

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