Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[maint] auto opening urls, PyPI CI #211

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,24 @@ jobs:
- name: Run Tests
shell: bash
run: make typecheck

release-pypi:
name: "Release to pypi"
runs-on: ubuntu-latest
if: github.event_name == 'release'
needs: [test-no-extras, tests, test-rsconnect]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: "Build Package"
run: |
python -m pip install build wheel
python -m build --sdist --wheel

- name: "Deploy to Test PyPI"
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
9 changes: 9 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@

For full details, view the [commit logs](https://github.com/rstudio/vetiver-python/commits/).

## v0.2.5
## What's Changed

[**Full Changelog**](https://github.com/rstudio/vetiver-python/compare/v0.2.4...v0.2.5)

* MAINT: refactor tests in [GH209](https://github.com/rstudio/vetiver-python/pull/209)
* DOCS: Update link to custom handlers documentation in [GH208](https://github.com/rstudio/vetiver-python/pull/208)
* ENH: add `Field` examples to model prototypes in [GH210](https://github.com/rstudio/vetiver-python/pull/210)


## v0.2.4
## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ include = [
# single character).
ignore = [
#"vetiver/__init__.py",
#"vetiver/attach_pkgs.py",
"vetiver/attach_pkgs.py",
"vetiver/helpers.py",
"vetiver/meta.py",
"vetiver/mock.py",
Expand Down
34 changes: 22 additions & 12 deletions vetiver/server.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import json
import logging
import re
import webbrowser
from textwrap import dedent
from typing import Callable, List, Union
from urllib.parse import urljoin
from warnings import warn

import httpx
import json
import pandas as pd
import requests
import uvicorn
import logging
import pandas as pd
from fastapi import FastAPI, Request
from fastapi.exceptions import RequestValidationError
from fastapi.openapi.utils import get_openapi
from fastapi.responses import HTMLResponse, RedirectResponse, PlainTextResponse
from textwrap import dedent
from warnings import warn
from urllib.parse import urljoin
from typing import Callable, List, Union
from fastapi.responses import HTMLResponse, PlainTextResponse, RedirectResponse

from .helpers import api_data_to_frame, response_to_frame
from .meta import VetiverMeta
from .utils import _jupyter_nb, get_workbench_path
from .vetiver_model import VetiverModel
from .meta import VetiverMeta
from .helpers import api_data_to_frame, response_to_frame


class VetiverAPI:
Expand Down Expand Up @@ -251,7 +253,7 @@ async def custom_endpoint(input_data: Request):
else:
return predictions

def run(self, port: int = 8000, host: str = "127.0.0.1", **kw):
def run(self, port: int = 8000, host: str = "127.0.0.1", quiet_open=False, **kw):
"""
Start API

Expand All @@ -261,6 +263,8 @@ def run(self, port: int = 8000, host: str = "127.0.0.1", **kw):
An integer that indicates the server port that should be listened on.
host : str
A valid IPv4 or IPv6 address, which the application will listen on.
quiet_open : bool
If host is a localhost address, try to automatically open API in browser

Examples
-------
Expand All @@ -273,7 +277,13 @@ def run(self, port: int = 8000, host: str = "127.0.0.1", **kw):
"""
_jupyter_nb()
self.workbench_path = get_workbench_path(port)

if port and host:
try:
if host == "127.0.0.1" and not quiet_open:
# quality of life for developing APIs locally
webbrowser.open(f"http://{host}:{port}")
except Exception:
pass
if self.workbench_path:
uvicorn.run(
self.app, port=port, host=host, root_path=self.workbench_path, **kw
Expand Down
Loading