Skip to content

Commit

Permalink
[adt server] make --debug work with gunicorn (#175)
Browse files Browse the repository at this point in the history
* fix --debug to work with gunicorn

Signed-off-by: NilashishC <[email protected]>

* updates

Signed-off-by: NilashishC <[email protected]>

* add --debug flag to test fixture

Signed-off-by: NilashishC <[email protected]>

---------

Signed-off-by: NilashishC <[email protected]>
  • Loading branch information
NilashishC authored Apr 29, 2024
1 parent d3c50c6 commit fe1fe8a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
accesslog
ADT
Ansibuddy
antsibull
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ repos:
- django-stubs[compatible-mypy]
- jinja2
- pytest
- ansible-creator
- tox
- types-pyyaml
- types-requests
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ strict = true

[[tool.mypy.overrides]]
ignore_missing_imports = true
module = ["gunicorn.*", "openapi_core.*", "ansible_creator.*"]
module = ["gunicorn.*", "openapi_core.*"]

[tool.pydoclint]
allow-init-docstring = true
Expand Down
3 changes: 1 addition & 2 deletions src/ansible_dev_tools/resources/server/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def collection(
)


# TO-DO: remove type ignore after creator is released with py.typed
class CreatorOutput(Output): # type: ignore[misc]
class CreatorOutput(Output):
"""The creator output."""

def __init__(self: CreatorOutput, log_file: str) -> None:
Expand Down
5 changes: 4 additions & 1 deletion src/ansible_dev_tools/subcommands/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def __init__(self: Server, port: str, debug: bool) -> None: # noqa: FBT001
self.debug: bool = debug

settings.configure(
DEBUG=self.debug,
SECRET_KEY=os.environ.get("SECRET_KEY", os.urandom(32)),
ALLOWED_HOSTS=[
"*",
Expand All @@ -91,4 +90,8 @@ def run(self: Server) -> None:
options = {
"bind": f"0.0.0.0:{self.port}",
}
if self.debug:
# set log level to debug and write access logs to stdout
options.update({"loglevel": "debug", "accesslog": "-"})

AdtServerApp(self.application, options).run()
4 changes: 3 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
def dev_tools_server() -> Generator[str, None, None]:
"""Run the server."""
bin_path = Path(sys.executable).parent / "adt"
with subprocess.Popen([bin_path, "server", "-p", "8000"]) as proc: # noqa: S603
with subprocess.Popen(
[bin_path, "server", "-p", "8000", "--debug"], # noqa: S603
) as proc:
time.sleep(1) # allow the server to start
yield "http://localhost:8000"
proc.terminate()

0 comments on commit fe1fe8a

Please sign in to comment.