Skip to content

Commit

Permalink
fix ui
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrochar committed Mar 3, 2024
2 parents d690a61 + a3f1ef3 commit 2b32a02
Show file tree
Hide file tree
Showing 87 changed files with 2,230 additions and 1,084 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: "3.12"
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
Expand All @@ -41,17 +41,17 @@ jobs:
- name: Install dev dependencies
run: poetry install --with=dev --no-root
- name: Ruff
run: poetry run ruff check blitz/
run: poetry run ruff check blitz/ tests/
- name: Mypy
run: poetry run mypy blitz/
run: poetry run mypy blitz/ tests/
test:
needs: lint
strategy:
fail-fast: true
matrix:
os: [ "ubuntu-latest", "macos-latest" ]
os: ["ubuntu-latest", "macos-latest"]
# python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
python-version: [ "3.12" ]
python-version: ["3.12"]
runs-on: ${{ matrix.os }}
steps:
#----------------------------------------------
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction
run: poetry install --with=dev --no-interaction
#----------------------------------------------
# add matrix specifics and run test suite
#----------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ database.db
.nicegui/
demo-blitz-app/
.idea/
.ruff_cache/
5 changes: 4 additions & 1 deletion blitz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import importlib.metadata

from .core import BlitzCore

__version__ = importlib.metadata.version("blitz")

__all__ = [
"BlitzCore",
]
__version__ = "0.1.0"
24 changes: 7 additions & 17 deletions blitz/api/logs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from loguru import logger
import logging
import inspect
import logging
import sys
from typing import TYPE_CHECKING

from loguru import logger

from blitz.app import BlitzApp

if TYPE_CHECKING:
Expand All @@ -22,26 +23,15 @@ def emit(self, record: logging.LogRecord) -> None:
except ValueError:
level = record.levelno

if record.name in ("uvicorn.access",):
if record.args[2].startswith("/projects"): # type: ignore
record.name += ".ui"
elif record.args[2].startswith("/api"): # type: ignore
record.name += ".api"
elif record.args[2].startswith("/admin"): # type: ignore
record.name += ".admin"

# Find caller from where originated the logged message.
frame, depth = inspect.currentframe(), 0
while frame and (depth == 0 or frame.f_code.co_filename == logging.__file__):
frame = frame.f_back
depth += 1
if record.name in ["uvicorn.access.ui", "uvicorn.access.admin"]:
pass
else:
logger.opt(
depth=depth,
exception=record.exc_info,
).log(level, record.getMessage())
logger.opt(
depth=depth,
exception=record.exc_info,
).log(level, record.getMessage())


def filter_logs(record: logging.LogRecord, blitz_app: BlitzApp) -> bool:
Expand Down
10 changes: 5 additions & 5 deletions blitz/cli/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# from .commands.swagger import list_routes
from .commands.swagger import list_routes
from .commands.start import start_blitz
from .commands.list import list_blitz_app
import typer

from .commands.create import create_blitz_app
from .commands.list import list_blitz_app
from .commands.release import release_blitz

import typer
from .commands.start import start_blitz
from .commands.swagger import list_routes

app = typer.Typer()
app.command(name="create")(create_blitz_app)
Expand Down
25 changes: 9 additions & 16 deletions blitz/cli/commands/create.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from pathlib import Path
from typing import Annotated, Optional
from rich import prompt, print
from blitz.models.blitz.file import BlitzFile
import yaml
from blitz.models.blitz.config import BlitzAppConfig

import typer
import yaml
from rich import print, prompt

from blitz.models.blitz.config import BlitzAppConfig
from blitz.models.blitz.file import BlitzFile
from blitz.models.blitz.resource import BlitzResourceConfig


Expand Down Expand Up @@ -65,9 +66,7 @@ class BlitzProjectCreator:
DEMO_BLITZ_APP_DESCRIPTION = "This is a demo blitz app"
DEMO_BLITZ_APP_NAME = "Demo Blitz App"

def __init__(
self, name: str, description: str, file_format: str, demo: bool = False
) -> None:
def __init__(self, name: str, description: str, file_format: str, demo: bool = False) -> None:
self.name = name
self.description = description
self.file_format = file_format
Expand Down Expand Up @@ -95,9 +94,7 @@ def create_file_or_exit(self) -> None:
raise typer.Exit(code=1)

def print_success_message(self) -> None:
print(
f"\n[medium_purple1 bold]{self.name}[/medium_purple1 bold] created successfully !"
)
print(f"\n[medium_purple1 bold]{self.name}[/medium_purple1 bold] created successfully !")
print("To start your app, you can use:")
print(f" [bold medium_purple1]blitz start {self.path}[/bold medium_purple1]")

Expand Down Expand Up @@ -127,9 +124,7 @@ def _write_blitz_file(self) -> Path:
raise Exception()
match self.file_format:
case "json":
blitz_file_data = self.blitz_file.model_dump_json(
indent=4, by_alias=True, exclude_unset=True
)
blitz_file_data = self.blitz_file.model_dump_json(indent=4, by_alias=True, exclude_unset=True)
case "yaml":
blitz_file_data = yaml.dump(
self.blitz_file.model_dump(by_alias=True, exclude_unset=True),
Expand All @@ -151,9 +146,7 @@ def _print_file_error(error: Exception) -> None:

@staticmethod
def _print_directory_error(error: Exception) -> None:
print(
f"[red bold]Error[/red bold] while creating the blitz app in the file system: {error}"
)
print(f"[red bold]Error[/red bold] while creating the blitz app in the file system: {error}")


def create_blitz_app(
Expand Down
20 changes: 9 additions & 11 deletions blitz/cli/commands/start.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import contextlib
import time
from semver import Version
import typer
import os
import uvicorn

import time
from pathlib import Path
from typing import Annotated, Optional

import typer
import uvicorn
from semver import Version
from uvicorn.supervisors import ChangeReload

from blitz import __version__
from blitz.api import create_blitz_api
from blitz.cli.utils import print_version
from blitz.core import BlitzCore

from blitz.settings import get_settings
from blitz.cli.errors import (
BlitzAppNotFoundError,
BlitzAppVersionNotFoundError,
MissingBlitzAppNameError,
)

from blitz import __version__
from blitz.cli.utils import print_version
from blitz.core import BlitzCore
from blitz.settings import get_settings


def start_blitz(
Expand Down
2 changes: 1 addition & 1 deletion blitz/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import enum
from functools import lru_cache
import os
from functools import lru_cache

from pydantic_settings import BaseSettings

Expand Down
4 changes: 1 addition & 3 deletions blitz/ui/blitz_ui.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from functools import lru_cache
from pathlib import Path
from typing import Any

from blitz.app import BlitzApp
from blitz.core import BlitzCore
from blitz.settings import Settings, get_settings
from blitz.tools.erd import generate_mermaid_erd


# @lru_cache
# def get_erd(app: BlitzApp) -> str:
# return generate_mermaid_erd(app._base_resource_model.metadata)
Expand All @@ -30,7 +30,6 @@ def current_project(self) -> str | None:

@current_project.setter
def current_project(self, project: str) -> None:
print(project)
self._current_project = project

@property
Expand Down Expand Up @@ -95,7 +94,6 @@ def _get_preprompt(self) -> str:

def reset_preprompt(self) -> None:
self.preprompt = self._get_preprompt()
print(self.preprompt)


@lru_cache
Expand Down
5 changes: 5 additions & 0 deletions blitz/ui/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .base import BaseComponent as Component

__all__ = [
"Component",
]
File renamed without changes.
62 changes: 62 additions & 0 deletions blitz/ui/components/accordion/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from nicegui import ui
from typing import Callable
from blitz.ui.components.base import BaseComponent


class BaseExpansion(BaseComponent[ui.expansion]):
def __init__(
self,
text: str = "",
caption: str | None = None,
icon: str | None = None,
group: str | None = None,
value: bool = False,
on_value_change: Callable[..., None] | None = None,
props: str = "",
classes: str = "",
) -> None:
self.text = text
self.caption = caption
self.icon = icon
self.group = group
self.value = value
self.on_value_change = on_value_change
super().__init__(props=props, classes=classes)

def render(self) -> None:
self.ng = (
ui.expansion(
self.text,
caption=self.caption,
icon=self.icon,
group=self.group,
value=self.value,
on_value_change=self.on_value_change,
)
.classes(self.classes)
.props(self.props)
)


class BaseAccordion(BaseExpansion):
def __init__(
self,
text: str = "",
caption: str | None = None,
icon: str | None = None,
group: str | None = None,
is_open: bool = False,
on_change: Callable[..., None] | None = None,
props: str = "",
classes: str = "",
) -> None:
super().__init__(
text=text,
caption=caption,
icon=icon,
group=group,
value=is_open,
on_value_change=on_change,
props=props,
classes=classes,
)
Loading

0 comments on commit 2b32a02

Please sign in to comment.