Issue976#978
Open
lior-antonov wants to merge 21 commits into
Open
Conversation
The eager getToolkit(EXPERIMENT) call pulled geopandas+xarray+pint (~290ms) on every import. experimentTK is now None until explicitly requested.
…935) toolkitHome, Project, datatypes, ToolkitHome, and autocache utilities are now populated on first access rather than at import time. 'import hera' drops from ~610ms to ~22ms. All consumer patterns continue to work via PEP 562 __getattr__. Zero heavy libs (pandas, mongoengine, geopandas, ...) loaded until first use.
…port (#935) datalayer/document: createDBConnection loop moved from module level into _ensure_connections() called by getDBObject() on first use. This removes the DB connection overhead from any import path that doesn't touch the datalayer. datalayer/project: remove unused 'from hera import toolkit' (toolkit was only referenced in docstring text, not in any actual code). This also breaks the circular import hera.toolkit <-> hera.datalayer that required toolkit to be imported before datalayer.
Removes module-level 'import pandas as pd'. The two methods that use pandas (getDataSourceTable and the toolkit registry builder) now import it locally. Return type annotation uses string form to avoid class-body import.
Replace module-level imports with _LazyModule proxies. Importing the module's public constants (WSG84, ITM, convertCRS) is now instant. Heavy libs are loaded on first attribute access when a GIS operation is actually performed.
experiment.py: remove module-level 'import pandas as pd'; defer
experimentPresentation/experimentAnalysis imports to experimentHome.__init__.
WSG84/ITM kept at module level (integer constants; GIS utils now fast).
presentation.py: replace numpy/pandas/jinja2 with _LazyModule proxies.
analysis.py: replace 'import pandas' with _LazyModule proxy.
The experiment toolkit's heavy deps (argos + pandas/numpy) are loaded on first
getToolkit('experiment') call, not at 'import hera' time.
…935) CLI entry points: moved all 'from hera.*' imports inside if __name__ == '__main__' so module-level code is only stdlib (argparse, argcomplete, logging). Applies to: hera-project, hera-openFoam, hera-workflows, hera-GIS, hera-LSM, hera-riskassessment, hera-experiment, hera-radiosonde. CLI module files: added _setup()/_initialized pattern to defer heavy imports to first function call, not module import: - hera/utils/data/CLI.py (toolkitHome, datalayer, pandas, tabulate) - hera/measurements/GIS/CLI.py (pandas, toolkitHome, WSG84/ITM) - hera/simulations/LSM/CLI.py (ToolkitHome, toolkitHome, loadJSON) hera/riskassessment/__init__.py: replaced eager imports with PEP 562 __getattr__ so 'from hera.riskassessment import CLI' no longer pulls geopandas/scipy/matplotlib. Result (--help response time): hera-project: 58ms (was 736ms) hera-GIS: 48ms (was 936ms) hera-workflows: 56ms (already fast) hera-LSM: 51ms (was 671ms) hera-riskassessment: 50ms (was 1820ms)
… toolkits can be slow) refs #935
…no benefit from __main__ guard) refs #935
…icate class definitions refs #935
… in CLI files refs #935 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…get the exact doument that would be saved in the DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #976