fixed flake8 lint errors

This commit is contained in:
Илья Глазунов 2025-12-04 03:06:58 +03:00
parent cec6e927a7
commit 7662a7924a
17 changed files with 62 additions and 84 deletions

View File

@ -2,7 +2,7 @@
PyServe - HTTP web server written on Python
"""
__version__ = "0.9.10"
__version__ = "0.10.0"
__author__ = "Ilya Glazunov"
from .asgi_mount import (

View File

@ -19,7 +19,8 @@ def main() -> None:
epilog="For service management (start/stop/restart/logs), use: pyservectl",
)
parser.add_argument(
"-c", "--config",
"-c",
"--config",
default="config.yaml",
help="Path to configuration file (default: config.yaml)",
)

View File

@ -88,6 +88,4 @@ def main():
if __name__ == "__main__":
import os
main()

View File

@ -7,16 +7,14 @@ Integrates with ProcessManager for actual process management.
import asyncio
import os
import signal
import sys
import time
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional
from ..config import Config
from ..process_manager import ProcessConfig, ProcessInfo, ProcessManager, ProcessState
from .state import ServiceState, StateManager
from ..process_manager import ProcessConfig, ProcessManager, ProcessState
from .state import StateManager
@dataclass

View File

@ -190,7 +190,6 @@ def show_cmd(ctx, config_file: Optional[str], output_format: str, section: Optio
console.print(syntax)
elif output_format == "table":
from rich.table import Table
from rich.tree import Tree
def build_tree(data, tree):

View File

@ -5,7 +5,7 @@ pyserve down - Stop all services
import signal
import time
from pathlib import Path
from typing import Optional, cast
from typing import cast
import click
@ -56,6 +56,7 @@ def down_cmd(
try:
import os
# FIXME: Please fix the cast usage here
os.kill(cast(int, daemon_pid), signal.SIGTERM)
@ -93,8 +94,8 @@ def down_cmd(
console.print("[bold]Stopping services...[/bold]")
from .._runner import ServiceRunner
from ...config import Config
from .._runner import ServiceRunner
config_path = Path(ctx.config_file)
if config_path.exists():

View File

@ -4,7 +4,6 @@ pyserve health - Check health of services
import asyncio
from pathlib import Path
from typing import Optional
import click
@ -60,6 +59,7 @@ def health_cmd(ctx, services: tuple, timeout: int, output_format: str):
return
from rich.table import Table
from ..output import format_health
table = Table(show_header=True, header_style="bold")

View File

@ -3,7 +3,6 @@ pyserve init - Initialize a new pyserve project
"""
from pathlib import Path
from typing import Optional
import click
@ -119,7 +118,7 @@ extensions:
port_range: [9000, 9999]
health_check_enabled: true
proxy_timeout: 60.0
apps:
# Example: FastAPI application
- name: api
@ -136,7 +135,7 @@ extensions:
strip_path: true
env:
APP_ENV: "production"
# Example: Flask application (WSGI)
# - name: admin
# path: /admin
@ -191,7 +190,7 @@ extensions:
- path: /api
app: myapp.api:app
# factory: false # Set to true if app is a factory function
# Starlette app mounted at /web
# - path: /web
# app: myapp.web:app
@ -257,13 +256,13 @@ logging:
format:
type: standard
use_colors: false
# JSON logs for log aggregation
- path: ./logs/pyserve.json
level: INFO
format:
type: json
# Access logs
- path: ./logs/access.log
level: INFO
@ -278,7 +277,7 @@ extensions:
port_range: [9000, 9999]
health_check_enabled: true
proxy_timeout: 60.0
apps:
- name: api
path: /api
@ -384,7 +383,7 @@ def init_cmd(
pyserve init -t full # All features
pyserve init -o production.yaml # Custom output file
"""
from ..output import console, print_success, print_warning, print_info
from ..output import console, print_info, print_success, print_warning
if list_templates:
console.print("\n[bold]Available Templates:[/bold]\n")

View File

@ -3,7 +3,6 @@ pyserve logs - View service logs
"""
import asyncio
import sys
import time
from pathlib import Path
from typing import Optional
@ -81,15 +80,13 @@ def logs_cmd(
pyserve logs --tail 50 # Last 50 lines
pyserve logs --since "10m" # Logs from last 10 minutes
"""
from ..output import console, print_error, print_info
from ..output import print_info
from ..state import StateManager
state_manager = StateManager(Path(".pyserve"), ctx.project)
if services:
log_files = [
(name, state_manager.get_service_log_file(name)) for name in services
]
log_files = [(name, state_manager.get_service_log_file(name)) for name in services]
else:
all_services = state_manager.get_all_services()
if not all_services:
@ -100,10 +97,7 @@ def logs_cmd(
print_info("No logs available. Start services with 'pyserve up'")
return
else:
log_files = [
(name, state_manager.get_service_log_file(name))
for name in all_services
]
log_files = [(name, state_manager.get_service_log_file(name)) for name in all_services]
existing_logs = [(name, path) for name, path in log_files if path.exists()]
@ -115,9 +109,7 @@ def logs_cmd(
until_timestamp = _parse_time(until_time) if until_time else None
colors = ["cyan", "green", "yellow", "blue", "magenta"]
service_colors = {
name: colors[i % len(colors)] for i, (name, _) in enumerate(existing_logs)
}
service_colors = {name: colors[i % len(colors)] for i, (name, _) in enumerate(existing_logs)}
if follow:
asyncio.run(
@ -144,7 +136,7 @@ def logs_cmd(
def _parse_time(time_str: str) -> Optional[float]:
import re
from datetime import datetime, timedelta
from datetime import datetime
# Relative time (e.g., "10m", "1h", "2d")
match = re.match(r"^(\d+)([smhd])$", time_str)
@ -182,10 +174,10 @@ def _read_logs(
no_color: bool,
filter_pattern: Optional[str],
):
from ..output import console
import re
from ..output import console
all_lines = []
for service_name, log_path in log_files:
@ -210,9 +202,7 @@ def _read_logs(
try:
from datetime import datetime
line_time = datetime.fromisoformat(
timestamp_match.group(1).replace(" ", "T")
).timestamp()
line_time = datetime.fromisoformat(timestamp_match.group(1).replace(" ", "T")).timestamp()
except ValueError:
pass

View File

@ -34,10 +34,10 @@ def scale_cmd(ctx, scales: tuple, timeout: int, no_wait: bool):
pyserve scale api=4 # Scale api to 4 workers
pyserve scale api=4 admin=2 # Scale multiple services
"""
from ...config import Config
from .._runner import ServiceRunner
from ..output import console, print_error, print_info, print_success
from ..state import StateManager
from .._runner import ServiceRunner
from ...config import Config
scale_map = {}
for scale in scales:
@ -72,9 +72,7 @@ def scale_cmd(ctx, scales: tuple, timeout: int, no_wait: bool):
print_info(f"Scaling {service}: {current}{workers} workers")
try:
success = await runner.scale_service(
service, workers, timeout=timeout, wait=not no_wait
)
success = await runner.scale_service(service, workers, timeout=timeout, wait=not no_wait)
if success:
print_success(f"Scaled {service} to {workers} workers")
else:

View File

@ -4,7 +4,6 @@ pyserve start/stop/restart - Service management commands
import asyncio
from pathlib import Path
from typing import List
import click
@ -28,10 +27,10 @@ def start_cmd(ctx, services: tuple, timeout: int):
pyserve start api # Start api service
pyserve start api admin # Start multiple services
"""
from ..output import console, print_error, print_info, print_success
from ..state import StateManager
from .._runner import ServiceRunner
from ...config import Config
from .._runner import ServiceRunner
from ..output import console, print_error, print_success
from ..state import StateManager
config_path = Path(ctx.config_file)
if not config_path.exists():
@ -94,10 +93,10 @@ def stop_cmd(ctx, services: tuple, timeout: int, force: bool):
pyserve stop api admin # Stop multiple services
pyserve stop api --force # Force stop
"""
from ...config import Config
from .._runner import ServiceRunner
from ..output import console, print_error, print_success
from ..state import StateManager
from .._runner import ServiceRunner
from ...config import Config
config_path = Path(ctx.config_file)
config = Config.from_yaml(str(config_path)) if config_path.exists() else Config()
@ -150,10 +149,10 @@ def restart_cmd(ctx, services: tuple, timeout: int):
pyserve restart api # Restart api service
pyserve restart api admin # Restart multiple services
"""
from ...config import Config
from .._runner import ServiceRunner
from ..output import console, print_error, print_success
from ..state import StateManager
from .._runner import ServiceRunner
from ...config import Config
config_path = Path(ctx.config_file)
if not config_path.exists():

View File

@ -78,17 +78,11 @@ def ps_cmd(
all_services = {k: v for k, v in all_services.items() if k in services}
if filter_status:
all_services = {
k: v for k, v in all_services.items() if v.state.lower() == filter_status.lower()
}
all_services = {k: v for k, v in all_services.items() if v.state.lower() == filter_status.lower()}
if not show_all:
# By default, show only running/starting/failed services
all_services = {
k: v
for k, v in all_services.items()
if v.state.lower() in ("running", "starting", "stopping", "failed", "restarting")
}
all_services = {k: v for k, v in all_services.items() if v.state.lower() in ("running", "starting", "stopping", "failed", "restarting")}
if not all_services:
if daemon_running:

View File

@ -65,12 +65,13 @@ async def _run_dashboard(
refresh_interval: float,
no_color: bool,
):
from rich.live import Live
from rich.table import Table
from rich.panel import Panel
from rich.layout import Layout
from rich.live import Live
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
from ..output import console, format_uptime, format_bytes
from ..output import console, format_bytes, format_uptime
try:
import psutil

View File

@ -7,7 +7,6 @@ import signal
import sys
import time
from pathlib import Path
from typing import List, Optional
import click
@ -78,9 +77,9 @@ def up_cmd(
pyserve up --scale api=4 # Scale api to 4 workers
pyserve up --wait # Wait for healthy status
"""
from .._runner import ServiceRunner
from ..output import console, print_error, print_info, print_success, print_warning
from ..state import StateManager
from .._runner import ServiceRunner
config_path = Path(ctx.config_file)
@ -116,6 +115,7 @@ def up_cmd(
try:
import os
from typing import cast
# FIXME: Please fix the cast usage here
os.kill(cast(int, daemon_pid), signal.SIGTERM)
time.sleep(2)

View File

@ -11,6 +11,21 @@ from typing import Optional
import click
from .commands import (
config_cmd,
down_cmd,
health_cmd,
init_cmd,
logs_cmd,
ps_cmd,
restart_cmd,
scale_cmd,
start_cmd,
stop_cmd,
top_cmd,
up_cmd,
)
from .. import __version__
DEFAULT_CONFIG = "config.yaml"
@ -113,21 +128,6 @@ def cli(ctx, config_file: str, project: Optional[str], verbose: bool, debug: boo
click.echo(ctx.get_help())
from .commands import (
config_cmd,
down_cmd,
health_cmd,
init_cmd,
logs_cmd,
ps_cmd,
restart_cmd,
scale_cmd,
start_cmd,
stop_cmd,
top_cmd,
up_cmd,
)
cli.add_command(init_cmd, name="init")
cli.add_command(config_cmd, name="config")
cli.add_command(up_cmd, name="up")

View File

@ -35,9 +35,11 @@ def print_warning(message: str) -> None:
def print_success(message: str) -> None:
console.print(f"[success] {message}[/success]")
def print_info(message: str) -> None:
console.print(f"[info] {message}[/info]")
def create_services_table() -> Table:
table = Table(
title=None,

View File

@ -9,9 +9,7 @@ import os
import time
from dataclasses import asdict, dataclass, field
from pathlib import Path
from typing import Any, Dict, List, Optional
import yaml
from typing import Any, Dict, Optional
@dataclass