mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
[V5] openbb-eia: Refactor for V5 + Add Full API Implementation (#7584)
* eia refactor for v5 * add test and publish workflows * data browser state * fix workflows * more workflow test items * temp files in tests * more fixes * more browsers * fix codeql issues * fix mer state and ensure multi-user capability * uv lock * table bridge * fix electricity browser state * convert HTML widgets to iFrame * fix recursion error in workspace mcp
This commit is contained in:
201
.github/workflows/publish-openbb-us-eia.yml
vendored
Normal file
201
.github/workflows/publish-openbb-us-eia.yml
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
name: 📦 publish openbb-us-eia
|
||||
|
||||
# Triggers exclusively on the merge of a ``release/openbb-us-eia-v*`` branch
|
||||
# into ``develop``. No push / tag triggers. Four sequential jobs — check the
|
||||
# version is bumped, build once against a freshly crawled catalog, test the
|
||||
# built artifact across the full cross-platform matrix, and only publish to
|
||||
# PyPI if the entire matrix is green.
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [closed]
|
||||
branches: [develop, v5]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
version-check:
|
||||
name: Verify version bump
|
||||
if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/openbb-us-eia-v')) || github.event_name == 'workflow_dispatch' }}
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
version: ${{ steps.parse.outputs.version }}
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: openbb_platform/providers/eia
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
ref: develop
|
||||
|
||||
- name: Parse [project].version from pyproject.toml
|
||||
id: parse
|
||||
run: |
|
||||
VERSION=$(grep -m1 -E '^version[[:space:]]*=' pyproject.toml | sed -E 's/^version[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/')
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "::error::Could not parse [project].version from pyproject.toml."
|
||||
exit 1
|
||||
fi
|
||||
echo "Local version: $VERSION"
|
||||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Fail if version already exists on PyPI
|
||||
env:
|
||||
VERSION: ${{ steps.parse.outputs.version }}
|
||||
run: |
|
||||
STATUS=$(curl -sS -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/openbb-us-eia/${VERSION}/json")
|
||||
case "$STATUS" in
|
||||
200)
|
||||
echo "::error::openbb-us-eia ${VERSION} is already published on PyPI."
|
||||
echo "Bump openbb_platform/providers/eia/pyproject.toml [project].version and re-merge a fresh release branch."
|
||||
exit 1
|
||||
;;
|
||||
404)
|
||||
echo "openbb-us-eia ${VERSION} is not yet on PyPI — proceeding."
|
||||
;;
|
||||
*)
|
||||
echo "::error::Unexpected status $STATUS from PyPI JSON API. Aborting to avoid a silent skip."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
- name: Verify release branch name matches pyproject version
|
||||
if: github.event_name == 'pull_request'
|
||||
env:
|
||||
VERSION: ${{ steps.parse.outputs.version }}
|
||||
BRANCH: ${{ github.event.pull_request.head.ref }}
|
||||
run: |
|
||||
EXPECTED="release/openbb-us-eia-v${VERSION}"
|
||||
if [ "$BRANCH" != "$EXPECTED" ]; then
|
||||
echo "::error::Release branch '${BRANCH}' does not match pyproject version '${VERSION}'."
|
||||
echo "Expected branch name: '${EXPECTED}'."
|
||||
echo "Either rename the release branch or update [project].version in pyproject.toml so they agree."
|
||||
exit 1
|
||||
fi
|
||||
echo "Branch '${BRANCH}' matches pyproject version '${VERSION}'."
|
||||
|
||||
build:
|
||||
name: Build sdist + wheel
|
||||
needs: version-check
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: openbb_platform/providers/eia
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
ref: develop
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.11"
|
||||
|
||||
- run: python -m pip install --upgrade pip uv
|
||||
|
||||
- name: Install the build backend and openbb-core
|
||||
run: |
|
||||
uv pip install --system "hatchling>=1.25" "requests>=2.31"
|
||||
uv pip install --system ../../core
|
||||
|
||||
- name: Save the freshly crawled catalog (warming pool for the PR workflow)
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: openbb_platform/providers/eia/openbb_us_eia/assets/eia_catalog.json.xz
|
||||
key: eia-catalog-${{ hashFiles('openbb_platform/providers/eia/openbb_us_eia/utils/generate_catalog.py') }}
|
||||
|
||||
- name: Build sdist (fresh EIA catalog)
|
||||
env:
|
||||
OPENBB_EIA_FORCE_CATALOG_REBUILD: "1"
|
||||
EIA_API_KEY: ${{ secrets.EIA_API_KEY }}
|
||||
run: uv build --sdist --no-sources --no-build-isolation --python "$(which python)"
|
||||
|
||||
- name: Build wheel
|
||||
env:
|
||||
OPENBB_EIA_FORCE_CATALOG_REBUILD: "0"
|
||||
run: uv build --wheel --no-sources --no-build-isolation --python "$(which python)"
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: openbb-us-eia-dist
|
||||
path: openbb_platform/providers/eia/dist/
|
||||
if-no-files-found: error
|
||||
retention-days: 7
|
||||
|
||||
test:
|
||||
name: Test (${{ matrix.os }} / Python ${{ matrix.python_version }})
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
# Linux: full sweep across every released Python.
|
||||
- { os: ubuntu-latest, python_version: "3.10" }
|
||||
- { os: ubuntu-latest, python_version: "3.11" }
|
||||
- { os: ubuntu-latest, python_version: "3.12" }
|
||||
- { os: ubuntu-latest, python_version: "3.13" }
|
||||
- { os: ubuntu-latest, python_version: "3.14" }
|
||||
# macOS + Windows: min and max supported.
|
||||
- { os: macos-latest, python_version: "3.10" }
|
||||
- { os: macos-latest, python_version: "3.14" }
|
||||
- { os: windows-latest, python_version: "3.10" }
|
||||
- { os: windows-latest, python_version: "3.14" }
|
||||
runs-on: ${{ matrix.os }}
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: openbb_platform/providers/eia
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
ref: develop
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: ${{ matrix.python_version }}
|
||||
allow-prereleases: true
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: openbb-us-eia-dist
|
||||
path: openbb_platform/providers/eia/dist
|
||||
|
||||
- run: python -m pip install --upgrade pip uv
|
||||
|
||||
- name: Install dependencies then openbb-us-eia wheel
|
||||
# ``openbb-core>=2.0.0`` isn't on PyPI yet — install it from the
|
||||
# sibling source tree first so the wheel's pinned deps resolve.
|
||||
# ``--group dev`` brings in pytest / pytest-asyncio / pytest-cov /
|
||||
# pytest-recorder / ruff / ty.
|
||||
run: |
|
||||
uv pip install --system ../../core
|
||||
uv pip install --system --group dev
|
||||
uv pip install --system dist/openbb_us_eia-*.whl
|
||||
|
||||
- name: Test the installed wheel
|
||||
# Remove the local ``openbb_us_eia/`` source so pytest imports the
|
||||
# package from site-packages — i.e., the EXACT wheel that's about to
|
||||
# be uploaded to PyPI. This is a release pipeline; the source tree
|
||||
# can't be allowed to shadow the artifact.
|
||||
run: |
|
||||
rm -rf openbb_us_eia
|
||||
pytest tests --cov=openbb_us_eia --cov-report=term-missing --cov-fail-under=100
|
||||
|
||||
publish:
|
||||
name: Publish to PyPI
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write # required for PyPI OIDC trusted publishing
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: openbb-us-eia-dist
|
||||
path: dist
|
||||
|
||||
- uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
packages-dir: dist
|
||||
164
.github/workflows/test-unit-openbb-us-eia.yml
vendored
Normal file
164
.github/workflows/test-unit-openbb-us-eia.yml
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
name: 🧪 test openbb-us-eia
|
||||
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [develop, main, v5]
|
||||
paths:
|
||||
- "openbb_platform/providers/eia/**"
|
||||
- ".github/workflows/test-unit-openbb-us-eia.yml"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
force_catalog_rebuild:
|
||||
description: "Force the build hook to regenerate the EIA catalog from the live APIv2 metadata tree (ignores actions/cache)."
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
# Cancel in-flight matrix runs when a new commit lands on the same PR.
|
||||
group: test-openbb-us-eia-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build sdist + wheel
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: openbb_platform/providers/eia
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.11"
|
||||
|
||||
- run: python -m pip install --upgrade pip uv
|
||||
|
||||
- name: Install the build backend and openbb-core
|
||||
run: |
|
||||
uv pip install --system "hatchling>=1.25" "requests>=2.31"
|
||||
uv pip install --system ../../core
|
||||
|
||||
- name: Restore EIA catalog
|
||||
# ``eia_catalog.json.xz`` is gitignored. On a cache hit the build hook
|
||||
# reuses it; on a miss it crawls api.eia.gov, which needs EIA_API_KEY.
|
||||
id: eia-cache
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: openbb_platform/providers/eia/openbb_us_eia/assets/eia_catalog.json.xz
|
||||
key: eia-catalog-${{ hashFiles('openbb_platform/providers/eia/openbb_us_eia/utils/generate_catalog.py') }}
|
||||
restore-keys: |
|
||||
eia-catalog-
|
||||
|
||||
- name: Build sdist
|
||||
env:
|
||||
OPENBB_EIA_FORCE_CATALOG_REBUILD: ${{ inputs.force_catalog_rebuild == true && '1' || '0' }}
|
||||
EIA_API_KEY: ${{ secrets.EIA_API_KEY }}
|
||||
run: uv build --sdist --no-sources --no-build-isolation --python "$(which python)"
|
||||
|
||||
- name: Build wheel
|
||||
env:
|
||||
OPENBB_EIA_FORCE_CATALOG_REBUILD: "0"
|
||||
run: uv build --wheel --no-sources --no-build-isolation --python "$(which python)"
|
||||
|
||||
- uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: openbb-us-eia-dist
|
||||
path: openbb_platform/providers/eia/dist/
|
||||
if-no-files-found: error
|
||||
retention-days: 7
|
||||
|
||||
lint:
|
||||
name: Lint (ruff + ty)
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: openbb_platform/providers/eia
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.11"
|
||||
|
||||
- run: python -m pip install --upgrade pip uv
|
||||
|
||||
- uses: actions/download-artifact@v5
|
||||
with:
|
||||
name: openbb-us-eia-dist
|
||||
path: openbb_platform/providers/eia/dist
|
||||
|
||||
- name: Install dependencies then openbb-us-eia wheel
|
||||
run: |
|
||||
uv pip install --system ../../core
|
||||
uv pip install --system --group dev
|
||||
uv pip install --system dist/openbb_us_eia-*.whl
|
||||
|
||||
- name: ruff check
|
||||
run: ruff check openbb_us_eia tests hatch_build.py
|
||||
|
||||
- name: ruff format --check
|
||||
run: ruff format --check openbb_us_eia tests hatch_build.py
|
||||
|
||||
- name: ty check
|
||||
run: ty check openbb_us_eia
|
||||
|
||||
test:
|
||||
name: Test (${{ matrix.os }} / Python ${{ matrix.python_version }})
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
# Linux: full sweep across every released Python.
|
||||
- { os: ubuntu-latest, python_version: "3.10" }
|
||||
- { os: ubuntu-latest, python_version: "3.11" }
|
||||
- { os: ubuntu-latest, python_version: "3.12" }
|
||||
- { os: ubuntu-latest, python_version: "3.13" }
|
||||
- { os: ubuntu-latest, python_version: "3.14" }
|
||||
# macOS + Windows: min and max supported.
|
||||
- { os: macos-latest, python_version: "3.10" }
|
||||
- { os: macos-latest, python_version: "3.14" }
|
||||
- { os: windows-latest, python_version: "3.10" }
|
||||
- { os: windows-latest, python_version: "3.14" }
|
||||
runs-on: ${{ matrix.os }}
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: openbb_platform/providers/eia
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: ${{ matrix.python_version }}
|
||||
allow-prereleases: true
|
||||
|
||||
- uses: actions/download-artifact@v5
|
||||
with:
|
||||
name: openbb-us-eia-dist
|
||||
path: openbb_platform/providers/eia/dist
|
||||
|
||||
- run: python -m pip install --upgrade pip uv
|
||||
|
||||
- name: Install dependencies then openbb-us-eia wheel
|
||||
run: |
|
||||
uv pip install --system ../../core
|
||||
uv pip install --system --group dev
|
||||
uv pip install --system dist/openbb_us_eia-*.whl
|
||||
|
||||
- name: Test the installed wheel
|
||||
# Remove the local ``openbb_us_eia/`` source so pytest imports the
|
||||
# package from site-packages — the exact wheel that was just built.
|
||||
# The HTTP fetchers replay from tests/record cassettes, so no EIA
|
||||
# credential is needed here.
|
||||
run: |
|
||||
rm -rf openbb_us_eia
|
||||
pytest tests --cov=openbb_us_eia --cov-report=term-missing --cov-fail-under=100
|
||||
Reference in New Issue
Block a user