Skip to content

Commit

Permalink
fix: Install cli extra normally, and add entrypoint tests.
Browse files Browse the repository at this point in the history
Signed-off-by: DanCardin <[email protected]>
  • Loading branch information
DanCardin committed Dec 19, 2023
1 parent 53dddf1 commit 1f83bb7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 50 deletions.
42 changes: 3 additions & 39 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
cache: "poetry"

- name: Install dependencies
run: poetry install
run: poetry install -E cli

- name: run ci checks
run: make ci
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E cli
poetry run pip install "pydantic<2"
- name: run ci checks
Expand All @@ -91,42 +91,6 @@ jobs:
with:
file: ./coverage.xml

test-cli:
name: test cli with py${{ matrix.python-version }} (pydantic v1) on ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]

runs-on: ${{ matrix.os }}

steps:
- name: checkout
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: setup python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"

- name: Install dependencies
run: |
poetry install -E cli
- name: run cli tests
run: make test-cli

- name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml

workflow-tests:
name: run workflow tests
timeout-minutes: 10
Expand All @@ -149,7 +113,7 @@ jobs:
cache: "poetry"

- name: Install dependencies
run: poetry install
run: poetry install -E cli

- name: setup k3d cluster
run: make install-k3d
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ lint: ## Run a `lint` process on Hera and report problems

.PHONY: test
test: ## Run tests for Hera
@poetry run python -m pytest --cov-report=term-missing -m "not on_cluster and not cli"

.PHONY: test-cli
test-cli: ## Run tests for Hera
@poetry run python -m pytest -m 'cli'
@poetry run python -m pytest --cov-report=term-missing -m "not on_cluster"

.PHONY: workflows-models
workflows-models: ## Generate the Workflows models portion of Argo Workflows
Expand Down
18 changes: 12 additions & 6 deletions src/hera/__main__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
"""Entrypoint for running hera as a CLI."""
import importlib.util
import sys


def main():
def main(argv=None):
"""Entrypoint for running hera as a CLI."""
try:
import cappa
except ImportError:
raise ImportError("Use of the `hera` CLI tool requires installing the 'cli' extra, `pip install hera[cli]`.")
importlib.util.find_spec("cappa")
except ImportError as e:
raise ImportError(
"Use of the `hera` CLI tool requires installing the 'cli' extra, `pip install hera[cli]`."
) from e

import cappa
import rich

from hera._cli.base import Hera

rich.print(
"[yellow bold]warning: The `hera` CLI is a work-in-progress, subject to change at any time![/yellow bold]"
"[yellow bold]warning: The `hera` CLI is a work-in-progress, subject to change at any time![/yellow bold]",
file=sys.stderr,
)

cappa.invoke(Hera)
cappa.invoke(Hera, argv=argv)


if __name__ == "__main__":
Expand Down
24 changes: 24 additions & 0 deletions tests/cli/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from unittest.mock import patch

import cappa
import pytest

from hera.__main__ import main


def test_main_dependency_missing():
with patch("importlib.util.find_spec", side_effect=ImportError):
with pytest.raises(ImportError) as e:
main()

assert "pip install hera[cli]" in str(e.value)


def test_main_dependency_exists(capsys):
with pytest.raises(cappa.Exit) as e:
main(["--help"])

assert e.value.code == 0

err = capsys.readouterr().err
assert "CLI is a work-in-progress" in err

0 comments on commit 1f83bb7

Please sign in to comment.