Skip to content

Commit

Permalink
Merge pull request #70 from MantisAI/feature/ui
Browse files Browse the repository at this point in the history
Add `hugie ui` command (Fixes #30)
  • Loading branch information
ivyleavedtoadflax authored Jul 25, 2023
2 parents e90aeac + 96e5f05 commit a5becb3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.2]

### Added
- Add endpoint config subcommand #47 (resolves #41)
- Adds `ls` alias to `list` command #50
- Adds `-f` shortcut to `--force` command #50
- 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

### Removed
- Removes `--no-force` option to `delete` command #50

### Fixed
- Breaking changes introduced by pydantic 2.0.0 #68
- Fix data bug in `update` function #63

## [0.2.0]

✨ Renamed to Hugie 🐻
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hugie"
version = "0.3.1"
version = "0.3.2"
description = "CLI for managing Hugging Face Inference Endpoints"
authors = ["Matthew Upson <[email protected]>",
"Nick Sorros <[email protected]>"]
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 a5becb3

Please sign in to comment.