[+] improve deploy:wheel

1. format with ruff;
  2. use tomlq from venv;
This commit is contained in:
Siarhei Siniak 2025-08-25 19:02:09 +03:00
parent 99a0013f42
commit b3c0dd2703
2 changed files with 72 additions and 83 deletions

@ -1,6 +1,6 @@
project(
run_command(
'tomlq', '-r', '.project.name', 'pyproject.toml',
'.venv/bin/tomlq', '-r', '.project.name', 'pyproject.toml',
check: true
).stdout().strip('\n'),
# 'online.fxreader.uv',

@ -6,13 +6,21 @@ import datetime
import django.http
from typing import (
Literal, Any, Optional, Annotated, cast,
TypeVar, Protocol, Generic, Callable,
Literal,
Any,
Optional,
Annotated,
cast,
TypeVar,
Protocol,
Generic,
Callable,
)
logger = logging.getLogger(__name__)
class Metric(pydantic.BaseModel):
name: str
type: Literal['gauge', 'counter']
@ -33,72 +41,53 @@ class Metric(pydantic.BaseModel):
o: 'Metric',
s: 'Metric.Sample',
) -> str:
samples: list[Metric.Sample] = [s,]
samples: list[Metric.Sample] = [
s,
]
if o.type == 'gauge':
samples.append(
Metric.Sample(
parameters=s.parameters,
value='NaN',
timestamp=(
s.timestamp + datetime.timedelta(seconds=15)
if s.timestamp
else None
)
)
Metric.Sample(parameters=s.parameters, value='NaN', timestamp=(s.timestamp + datetime.timedelta(seconds=15) if s.timestamp else None))
)
return ''.join([
return ''.join(
[
'{metric}{{{parameters}}} {value} {timestamp}\n'.format(
metric=o.name,
parameters=','.join([
'%s=%s' % (
parameters=','.join(
[
'%s=%s'
% (
k,
json.dumps(v),
)
for k, v in s2.parameters.items()
]),
value=s2.value,
timestamp=(
'%.f' % (s2.timestamp.timestamp() * 1000,)
if s2.timestamp
else ''
]
),
value=s2.value,
timestamp=('%.f' % (s2.timestamp.timestamp() * 1000,) if s2.timestamp else ''),
)
for s2 in samples
])
]
)
def serialize(
metrics: list[Metric],
):
return django.http.HttpResponse(
''.join([
''.join(
[
'{help}{type}{samples}'.format(
# help='# HELP %s some metric' % o.name,
# type='# TYPE %s counter' % o.name,
help=(
'# HELP {0} {1}\n'.format(
o.name,
o.help
)
if o.help
else ''
),
type=(
'# TYPE {0} {1}\n'.format(
o.name,
o.type
)
if o.type
else ''
),
samples=''.join([
Metric.sample_serialize(o, s)
for s in o.samples
]),
help=('# HELP {0} {1}\n'.format(o.name, o.help) if o.help else ''),
type=('# TYPE {0} {1}\n'.format(o.name, o.type) if o.type else ''),
samples=''.join([Metric.sample_serialize(o, s) for s in o.samples]),
)
for o in metrics
if len(o.samples) > 0
]),
]
),
content_type='text/plain; version=0.0.4; charset=utf-8',
)