Msc. lint stomping
This commit is contained in:
parent
5756f7dd07
commit
1684195192
6 changed files with 29 additions and 29 deletions
|
@ -127,9 +127,9 @@ def available_migrations(queries: Queries, conn) -> t.Iterable[MigrationDescript
|
||||||
if query_name.endswith("_cursor"):
|
if query_name.endswith("_cursor"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# type: query_name: str
|
# query_name: str
|
||||||
|
# query_fn: t.Callable + {.__name__, .__doc__, .sql}
|
||||||
query_fn = getattr(queries, query_name)
|
query_fn = getattr(queries, query_name)
|
||||||
# type: query_fn: t.Callable + {.__name__, .__doc__, .sql}
|
|
||||||
yield MigrationDescriptor(
|
yield MigrationDescriptor(
|
||||||
name = query_name,
|
name = query_name,
|
||||||
committed_at = None,
|
committed_at = None,
|
||||||
|
|
|
@ -234,7 +234,7 @@ class JobQueue(object):
|
||||||
yield next(iterable)
|
yield next(iterable)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
jobs = lf(jobs)
|
jobs = lf(jobs)
|
||||||
|
|
||||||
return self._from_results(jobs)
|
return self._from_results(jobs)
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
"""A quick and dirty Python driver for the jobqd API."""
|
"""A quick and dirty Python driver for the jobqd API."""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import NamedTuple
|
import typing as t
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class Job(NamedTuple):
|
class Job(t.NamedTuple):
|
||||||
id: int
|
id: int
|
||||||
payload: object
|
payload: object
|
||||||
events: object
|
events: object
|
||||||
|
@ -16,11 +16,11 @@ class Job(NamedTuple):
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, obj):
|
def from_json(cls, obj):
|
||||||
return cls(
|
return cls(
|
||||||
id = int(obj["id"]),
|
id=int(obj["id"]),
|
||||||
payload = obj["payload"],
|
payload=obj["payload"],
|
||||||
events = obj["events"],
|
events=obj["events"],
|
||||||
state = obj["state"],
|
state=obj["state"],
|
||||||
modified = datetime.fromtimestamp(obj["modified"])
|
modified=datetime.fromtimestamp(obj["modified"])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,11 +35,11 @@ class JobqClient(object):
|
||||||
for job in self._session.post(self._url + "/api/v0/job",
|
for job in self._session.post(self._url + "/api/v0/job",
|
||||||
json={"query": query or [],
|
json={"query": query or [],
|
||||||
"limit": limit})\
|
"limit": limit})\
|
||||||
.json()\
|
.json()\
|
||||||
.get("jobs"):
|
.get("jobs"):
|
||||||
yield Job.from_json(job)
|
yield Job.from_json(job)
|
||||||
|
|
||||||
def poll(self, query, state) -> DehydratedJob:
|
def poll(self, query, state) -> Job:
|
||||||
"""Poll the job queue for the first job matching the given query, atomically advancing it to the given state and returning the advanced Job."""
|
"""Poll the job queue for the first job matching the given query, atomically advancing it to the given state and returning the advanced Job."""
|
||||||
|
|
||||||
return Job.from_json(
|
return Job.from_json(
|
||||||
|
@ -49,7 +49,7 @@ class JobqClient(object):
|
||||||
"state": state})
|
"state": state})
|
||||||
.json())
|
.json())
|
||||||
|
|
||||||
def create(self, payload: object, state=None) -> DehydratedJob:
|
def create(self, payload: object, state=None) -> Job:
|
||||||
"""Create a new job in the system."""
|
"""Create a new job in the system."""
|
||||||
|
|
||||||
return Job.from_json(
|
return Job.from_json(
|
||||||
|
@ -59,7 +59,7 @@ class JobqClient(object):
|
||||||
"state": state})
|
"state": state})
|
||||||
.json())
|
.json())
|
||||||
|
|
||||||
def fetch(self, job: Job) -> HydratedJob:
|
def fetch(self, job: Job) -> Job:
|
||||||
"""Fetch the current state of a job."""
|
"""Fetch the current state of a job."""
|
||||||
|
|
||||||
return Job.from_json(
|
return Job.from_json(
|
||||||
|
@ -77,7 +77,7 @@ class JobqClient(object):
|
||||||
"new": state})
|
"new": state})
|
||||||
.json())
|
.json())
|
||||||
|
|
||||||
def event(self, job: Job, event: object) -> HydratedJob:
|
def event(self, job: Job, event: object) -> Job:
|
||||||
"""Attempt to record an event against a job."""
|
"""Attempt to record an event against a job."""
|
||||||
|
|
||||||
return Job.from_json(
|
return Job.from_json(
|
||||||
|
|
|
@ -54,14 +54,14 @@ def repl(opts, args, runtime):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
expr = parse_expr(line)
|
expr = parse_expr(line)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = lil_eval(runtime, module, Bindings("__root__", None), expr)
|
result = lil_eval(runtime, module, Bindings("__root__", None), expr)
|
||||||
print_([("class:result", f"⇒ {result!r}")], style=STYLE)
|
print_([("class:result", f"⇒ {result!r}")], style=STYLE)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -145,15 +145,15 @@ def main():
|
||||||
|
|
||||||
def py(runtime=None, module=None, expr=None, body=None, name=None):
|
def py(runtime=None, module=None, expr=None, body=None, name=None):
|
||||||
"""The implementation of the Python lang as an eval type."""
|
"""The implementation of the Python lang as an eval type."""
|
||||||
g = globals().copy()
|
globs = globals().copy()
|
||||||
l = {}
|
locs = {}
|
||||||
body = (
|
body = (
|
||||||
f"def _shim():\n"
|
"def _shim():\n"
|
||||||
+ "\n".join(" " + l for l in body.splitlines())
|
+ "\n".join(" " + line for line in body.splitlines())
|
||||||
+ "\n\n_escape = _shim()"
|
+ "\n\n_escape = _shim()"
|
||||||
)
|
)
|
||||||
exec(body, g, l)
|
exec(body, globs, locs)
|
||||||
return l["_escape"]
|
return locs["_escape"]
|
||||||
|
|
||||||
def lil(runtime=None, module=None, expr=None, body=None, name=None):
|
def lil(runtime=None, module=None, expr=None, body=None, name=None):
|
||||||
"""The implementation of the Lilith lang as an eval type."""
|
"""The implementation of the Lilith lang as an eval type."""
|
||||||
|
|
|
@ -141,7 +141,7 @@ class Proquint(object):
|
||||||
"""Encode an integer into a proquint string."""
|
"""Encode an integer into a proquint string."""
|
||||||
|
|
||||||
if width % 8 != 0 or width < 8:
|
if width % 8 != 0 or width < 8:
|
||||||
raise ValueError(f"Width must be a positive power of 2 greater than 8")
|
raise ValueError("Width must be a positive power of 2 greater than 8")
|
||||||
|
|
||||||
return cls.encode_bytes(val.to_bytes(width // 8, "big"))
|
return cls.encode_bytes(val.to_bytes(width // 8, "big"))
|
||||||
|
|
||||||
|
|
|
@ -5,25 +5,25 @@ from hypothesis.strategies import integers
|
||||||
import proquint
|
import proquint
|
||||||
|
|
||||||
|
|
||||||
@given(integers(min_value=0, max_value=1<<16))
|
@given(integers(min_value=0, max_value=1 << 16))
|
||||||
def test_round_trip_16(val):
|
def test_round_trip_16(val):
|
||||||
assert proquint.Proquint.decode(
|
assert proquint.Proquint.decode(
|
||||||
proquint.Proquint.encode(val, 16)) == val
|
proquint.Proquint.encode(val, 16)) == val
|
||||||
|
|
||||||
|
|
||||||
@given(integers(min_value=0, max_value=1<<32))
|
@given(integers(min_value=0, max_value=1 << 32))
|
||||||
def test_round_trip_32(val):
|
def test_round_trip_32(val):
|
||||||
assert proquint.Proquint.decode(
|
assert proquint.Proquint.decode(
|
||||||
proquint.Proquint.encode(val, 32)) == val
|
proquint.Proquint.encode(val, 32)) == val
|
||||||
|
|
||||||
|
|
||||||
@given(integers(min_value=0, max_value=1<<64))
|
@given(integers(min_value=0, max_value=1 << 64))
|
||||||
def test_round_trip_64(val):
|
def test_round_trip_64(val):
|
||||||
assert proquint.Proquint.decode(
|
assert proquint.Proquint.decode(
|
||||||
proquint.Proquint.encode(val, 64)) == val
|
proquint.Proquint.encode(val, 64)) == val
|
||||||
|
|
||||||
|
|
||||||
@given(integers(min_value=0, max_value=1<<512))
|
@given(integers(min_value=0, max_value=1 << 512))
|
||||||
def test_round_trip_512(val):
|
def test_round_trip_512(val):
|
||||||
assert proquint.Proquint.decode(
|
assert proquint.Proquint.decode(
|
||||||
proquint.Proquint.encode(val, 512)) == val
|
proquint.Proquint.encode(val, 512)) == val
|
||||||
|
|
Loading…
Reference in a new issue