Skip to content

Commit

Permalink
Merge branch 'main' into feature/abstract-error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ivyleavedtoadflax authored Jul 27, 2023
2 parents b23ae74 + a5becb3 commit 68c1a9a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add endpoint config subcommand #47 (resolves #41)
- Adds `ls` alias to `list` command #50
- Adds `-f` shortcut to `--force` command #50
- Adds `hugie ui` command #70
- Adds `poetry` for dependency management #69
- Adds `ui` command to open Hugging Face Inference Endpoint website in browser #70

### Changed
- Only create docs on merge to main #50
Expand All @@ -29,8 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Address missing token message #46
- Handle 40x responses in create #45
- Update now handles 40x codes #44
- Removve --no-json from cli #43

- Remove --no-json from cli #43

## [0.2.0]

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ Options:
--help Show this message and exit.
Commands:
Commands:
config
endpoint
version Show version.
ui Open the Hugging Face Endpoints UI in a browser
version Print hugie version
```

# Endpoint
Expand Down
15 changes: 14 additions & 1 deletion hugie/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib.metadata
import webbrowser

import typer

Expand All @@ -10,11 +11,23 @@

@app.command()
def version():
"""Show version."""
"""Print hugie version"""
typer.echo(importlib.metadata.version("hugie"))
typer.Exit(0)


@app.command("ui")
def open_ui():
"""
Open the Hugging Face Endpoints UI in a browser
"""
url = "https://ui.endpoints.huggingface.co/"
typed_url = typer.style(url, fg=typer.colors.BLUE, bold=True)
typer.echo(f"Opening {typed_url} in your browser...")
webbrowser.open(url)
typer.Exit(0)


app.add_typer(endpoint_app, name="endpoint")
app.add_typer(config_app, name="config")

Expand Down
27 changes: 27 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from unittest.mock import Mock

from hugie.__main__ import app
from typer.testing import CliRunner

runner = CliRunner()


def test_ui_command(monkeypatch):
mock_open = Mock(
return_value="Opening https://ui.endpoints.huggingface.co/ in your browser..."
)

# Use monkeypatch to replace the ui function with the mock function
monkeypatch.setattr("webbrowser.open", mock_open)

runner = CliRunner()
result = runner.invoke(app, ["ui"])

assert result.exit_code == 0
assert (
"Opening https://ui.endpoints.huggingface.co/ in your browser..."
in result.output
)

# Check that the mock was called
mock_open.assert_called()

0 comments on commit 68c1a9a

Please sign in to comment.