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

Expose host for several apps. #59

Merged
merged 4 commits into from
Jan 3, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The **third number** is for emergencies when we need to start branches for older
([#58](https://github.com/Tinche/uapi/pull/58))
- Dictionaries are now supported in the OpenAPI schema, rendering to object schemas with `additionalProperties`.
([#58](https://github.com/Tinche/uapi/pull/58))
- {meth}`uapi.flask.FlaskApp.run`, {meth}`uapi.quart.QuartApp.run` and {meth}`uapi.starlette.StarletteApp.run` now expose `host` parameters.
([#59](https://github.com/Tinche/uapi/pull/59))

## [v23.3.0](https://github.com/tinche/uapi/compare/v23.2.0...v23.3.0) - 2023-12-20

Expand Down
26 changes: 25 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ test = [
"uapi[lint, frameworks]",
"python-multipart>=0.0.6",
"pytest-mypy-plugins>=3.0.0",
"pytest-xdist>=3.5.0",
]
frameworks = [
"aiohttp==3.9.0b0",
Expand Down
5 changes: 3 additions & 2 deletions src/uapi/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ def adapter(**kwargs):

return f

def run(self, import_name: str, port: int = 8000):
self.to_framework_app(import_name).run(port=port)
def run(self, import_name: str, host: str | None = None, port: int = 8000):
"""Start serving the app using the Flask development server."""
self.to_framework_app(import_name).run(host=host, port=port)

@staticmethod
def _path_param_parser(p: str) -> tuple[str, list[str]]:
Expand Down
2 changes: 2 additions & 0 deletions src/uapi/quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ async def adapter(**kwargs):
async def run(
self,
import_name: str,
host: str = "127.0.0.1",
port: int = 8000,
handle_signals: bool = True,
log_level: str | int | None = None,
Expand All @@ -176,6 +177,7 @@ async def run(

config = Config(
self.to_framework_app(import_name),
host=host,
port=port,
access_log=False,
log_level=log_level,
Expand Down
7 changes: 6 additions & 1 deletion src/uapi/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ async def adapted(

async def run(
self,
host: str = "127.0.0.1",
port: int = 8000,
handle_signals: bool = True,
log_level: str | int | None = None,
Expand All @@ -189,7 +190,11 @@ async def run(
from uvicorn import Config, Server

config = Config(
self.to_framework_app(), port=port, access_log=False, log_level=log_level
self.to_framework_app(),
host=host,
port=port,
access_log=False,
log_level=log_level,
)

if handle_signals:
Expand Down
2 changes: 1 addition & 1 deletion tests/quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def request_method_native(req_method: Method) -> Response:


async def run_on_quart(app: App, port: int) -> None:
await app.run(__name__, port, handle_signals=False, log_level="critical")
await app.run(__name__, port=port, handle_signals=False, log_level="critical")
2 changes: 1 addition & 1 deletion tests/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def request_method_native(req_method: Method) -> Response:


async def run_on_starlette(app: App, port: int) -> None:
await app.run(port, handle_signals=False)
await app.run(port=port, handle_signals=False)
13 changes: 8 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Keep docs in sync with docs env and .readthedocs.yml.
[gh-actions]
python =
3.10: py310, lint
3.10: py310
3.11: py311
3.12: py312
3.12: py312, lint

[tox]
envlist = py310, py311, py312, lint
isolated_build = True

[testenv:lint]
basepython = python3.10
basepython = python3.12
allowlist_externals =
make
pdm
Expand All @@ -21,9 +21,12 @@ commands =
[testenv]
setenv =
PDM_IGNORE_SAVED_PYTHON="1"
COVERAGE_PROCESS_START={toxinidir}/pyproject.toml
commands_pre =
pdm sync -G test
python -c 'import pathlib; pathlib.Path("{env_site_packages_dir}/cov.pth").write_text("import coverage; coverage.process_startup()")'
commands =
pdm install -G test
pdm run coverage run -m pytest tests --mypy-only-local-stub {posargs}
pdm run coverage run -m pytest tests --mypy-only-local-stub -n auto {posargs}
allowlist_externals = pdm
package = wheel
wheel_build_env = .pkg
Loading