Describe the New Feature
Allow calling met_db_load as an imported module from other Python applications.
We have a use case for METdbLoad that involves installing METdataio as a package, importing METdbLoad.ush.met_db_load.main and calling it from our own Python module. (The details probably aren't relevant, but for context, we're subscribing to a message queue and loading new MET stats into the database as files arrive.)
pip installing METdataio worked well enough, but there were a few pain points when we tried to call METdbLoad.ush.met_db_load.main():
met_db_load.main expects args to be passed directly from argparse (in dot notation), which makes it a little awkward to call.
met_db_load.print_version looks up the package version in a way that seems to only work when invoking METdataio from a full copy of the Git repository. When METdataio is installed as a Python package, the docs/ folder containing the version info is no longer available at the expected relative path.
- A
logger call in an except: block in met_db_load.py tries to reference self (though it's not part of a class/object).
netcdf4 (or h5netcdf) and metcalcpy dependencies were missing from requirements.txt.
- Lastly, because dynamic inclusion of project requirements is disabled (commented) in
pyproject.toml, metdataio dependencies aren't automatically installed when pip installing METdataio itself.
We could use subprocess to call met_db_load.py with typical CLI parameters from our app, but given that so many pieces seem to already be in place for a direct import to work, it seemed worthwhile to open an issue and submit a PR. It's somewhere between a bug report and feature request, so feel free to relabel it if need-be. Welcome any other feedback or critiques as well (this is my first time contributing here).
I've opened a draft PR with some relevant changes.
Acceptance Testing
Our desired workflow is essentially the following:
Install metdataio and its subpackages (this part already works, except for the runtime issues noted above).
pip install git+https://github.com/dtcenter/METdataio.git@main_v3.0
# or a 'git clone https://github.com/dtcenter/METdataio.git' followed by a 'cd METdataio && pip install .'
Import the DB loader and call it against a load spec XML.
from METdbLoad.ush.met_db_load import main as load_met_data
load_met_data(xmlfile, index=False)
Time Estimate
<1 day
Sub-Issues
- Implement keyword argument support in
METdbLoad.met_db_load.main.
- Re-enable inclusion of dependencies from
requirements.txt in pyproject.toml
Relevant Deadlines
None
Funding Source
None
Define the Metadata
I'm not quite sure how best to fill out this section.
Assignee
Labels
Milestone and Projects
Define Related Issue(s)
Consider the impact to the other METplus components.
New Feature Checklist
See the METplus Workflow for details.
Describe the New Feature
Allow calling
met_db_loadas an imported module from other Python applications.We have a use case for METdbLoad that involves installing METdataio as a package, importing
METdbLoad.ush.met_db_load.mainand calling it from our own Python module. (The details probably aren't relevant, but for context, we're subscribing to a message queue and loading new MET stats into the database as files arrive.)pip installing METdataio worked well enough, but there were a few pain points when we tried to callMETdbLoad.ush.met_db_load.main():met_db_load.mainexpects args to be passed directly fromargparse(in dot notation), which makes it a little awkward to call.met_db_load.print_versionlooks up the package version in a way that seems to only work when invoking METdataio from a full copy of the Git repository. When METdataio is installed as a Python package, thedocs/folder containing the version info is no longer available at the expected relative path.loggercall in anexcept:block inmet_db_load.pytries to referenceself(though it's not part of a class/object).netcdf4(orh5netcdf) andmetcalcpydependencies were missing fromrequirements.txt.pyproject.toml,metdataiodependencies aren't automatically installed when pip installing METdataio itself.We could use
subprocessto callmet_db_load.pywith typical CLI parameters from our app, but given that so many pieces seem to already be in place for a direct import to work, it seemed worthwhile to open an issue and submit a PR. It's somewhere between a bug report and feature request, so feel free to relabel it if need-be. Welcome any other feedback or critiques as well (this is my first time contributing here).I've opened a draft PR with some relevant changes.
Acceptance Testing
Our desired workflow is essentially the following:
Install
metdataioand its subpackages (this part already works, except for the runtime issues noted above).pip install git+https://github.com/dtcenter/METdataio.git@main_v3.0 # or a 'git clone https://github.com/dtcenter/METdataio.git' followed by a 'cd METdataio && pip install .'Import the DB loader and call it against a load spec XML.
Time Estimate
<1 day
Sub-Issues
METdbLoad.met_db_load.main.requirements.txtinpyproject.tomlRelevant Deadlines
None
Funding Source
None
Define the Metadata
I'm not quite sure how best to fill out this section.
Assignee
Labels
Milestone and Projects
Define Related Issue(s)
Consider the impact to the other METplus components.
New Feature Checklist
See the METplus Workflow for details.
Branch name:
feature_<Issue Number>_<Description>Pull request:
feature <Issue Number> <Description>Select: Reviewer(s) and Development issue
Select: Milestone as the next official version
Select: METdataio-X.Y.Z Development project for development toward the next official release