Skip to content
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
16 changes: 8 additions & 8 deletions .github/workflows/docker-build-and-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ jobs:
id: build-image
uses: docker/build-push-action@v6
with:
context: ${{ env.DOCKER_PATH_CONTEXT }}
file: ${{ env.DOCKER_BUILD_DOCKERFILE }}
load: ${{ env.DOCKER_LOAD_BOOL }}
tags: ${{ env.DOCKER_TAGS }}
context: ${{ inputs.DOCKER_PATH_CONTEXT || env.DOCKER_PATH_CONTEXT }}
file: ${{ inputs.DOCKER_BUILD_DOCKERFILE || env.DOCKER_BUILD_DOCKERFILE }}
load: ${{ inputs.DOCKER_LOAD_BOOL || env.DOCKER_LOAD_BOOL }}
tags: ${{ inputs.DOCKER_TAGS || env.DOCKER_TAGS }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.33.1
with:
image-ref: ${{ env.DOCKER_TAGS }}
image-ref: ${{ inputs.DOCKER_TAGS || env.DOCKER_TAGS }}
format: 'table'
exit-code: '1'
ignore-unfixed: true
Expand All @@ -62,7 +62,7 @@ jobs:
if: github.event_name == 'workflow_call'
uses: docker/build-push-action@v6
with:
context: ${{ env.DOCKER_PATH_CONTEXT }}
file: ${{ env.DOCKER_BUILD_DOCKERFILE }}
context: ${{ inputs.DOCKER_PATH_CONTEXT || env.DOCKER_PATH_CONTEXT }}
file: ${{ inputs.DOCKER_BUILD_DOCKERFILE || env.DOCKER_BUILD_DOCKERFILE }}
push: true
tags: ${{ env.DOCKER_TAGS }}
tags: ${{ inputs.DOCKER_TAGS || env.DOCKER_TAGS }}
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ dependencies = [
"pathlib>=1.0.1",
"pydantic>=2.12.5",
"pydantic-settings>=2.12.0",
"pyfiglet>=1.0.4",
"pylint>=4.0.4",
"pylint-pydantic>=0.4.1",
"pytest>=9.0.2",
"rich>=14.3.2",
]

[project.optional-dependencies]
Expand Down
30 changes: 20 additions & 10 deletions src/sample_python_app/core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
)


def setup_logger():
def setup_logger(mode="normal"):
logger.remove()
logger.add(sink=lambda msg: print(msg, end=""), format=log_format, level="INFO")
logger.add(
"app.log",
format=log_format,
level="DEBUG",
rotation="1 MB",
retention="10 days",
compression="zip",
)
if mode == "silent":
logger.add(
"app.log",
format=log_format,
level="DEBUG",
rotation="1 MB",
retention="10 days",
compression="zip",
)
else:
logger.add(sink=lambda msg: print(msg, end=""), format=log_format, level="INFO")
logger.add(
"app.log",
format=log_format,
level="DEBUG",
rotation="1 MB",
retention="10 days",
compression="zip",
)
return logger
9 changes: 8 additions & 1 deletion src/sample_python_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
Main entry point for the python-app-template project.
"""

from pyfiglet import Figlet
from rich.console import Console

from sample_python_app.core import settings, setup_logger


def run_app():
logger = setup_logger()
console = Console()
f = Figlet(font="slant")
ascii_art = f.renderText("Hello, Synthwave!")
console.print(f"[bold magenta]{ascii_art}[/bold magenta]")
logger = setup_logger(mode="silent")
logger.info(f"Starting {settings.APP_NAME}...")
logger.info("Hello from python-app-template!")

Expand Down
16 changes: 16 additions & 0 deletions tests/test_figlet_rich.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Test for minimal figlet output using Rich and pyfiglet.
"""

from pyfiglet import Figlet
from rich.console import Console


def test_figlet_rich_output(capfd):
console = Console()
f = Figlet(font="slant")
ascii_art = f.renderText("Hello, Synthwave!")
console.print(f"[bold magenta]{ascii_art}[/bold magenta]")
out, _ = capfd.readouterr()
# Check for a distinctive substring from the ASCII art output
assert "__ __" in out or "/ / / /__" in out
34 changes: 34 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Tests for sample_python_app.core.logging
"""

import time

from loguru import logger as loguru_logger

from sample_python_app.core.logging import setup_logger


def test_logger_normal_mode_stdout(capsys):
logger = setup_logger("normal")
logger.info("Test normal mode log")
out, _ = capsys.readouterr()
assert "Test normal mode log" in out


def test_logger_silent_mode_no_stdout(capsys):
logger = setup_logger("silent")
logger.info("Test silent mode log")
out, _ = capsys.readouterr()
assert "Test silent mode log" not in out


def test_logger_file_logging(tmp_path):
log_path = tmp_path / "app.log"
loguru_logger.remove()
loguru_logger.add(str(log_path), format="{message}", level="DEBUG")
loguru_logger.info("File log test")
time.sleep(0.1)
with open(log_path, "r", encoding="utf-8") as f:
contents = f.read()
assert "File log test" in contents
3 changes: 2 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ def test_main_subprocess():
def test_main_runs(capfd):
main.run_app()
out, _ = capfd.readouterr()
assert "Hello from python-app-template!" in out
# Check for a distinctive substring from the ASCII art output
assert "__ __" in out or "/ / / /__" in out
47 changes: 47 additions & 0 deletions uv.lock

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

Loading