Add pre-commit to automatically run formatting when committing

This commit is contained in:
Vincent Emonet 2023-07-23 13:24:15 +02:00
commit 25168ba6e1
14 changed files with 74 additions and 34 deletions

View file

@ -170,7 +170,7 @@ _default_options_objects = [
'name': 'UPDATE_MODELS',
'default_value': False,
'value_type': 'bool'
},
},
{
'name': 'METRICS',
'default_value': False,

View file

@ -44,7 +44,7 @@ def get_alternate_locale_links():
tmpl = os.environ.get("LT_LOCALE_LINK_TEMPLATE")
if tmpl is None:
return []
locales = get_available_locale_codes()
result = []
for l in locales:

View file

@ -8,6 +8,6 @@ class Limiter:
return f(*args, **kwargs)
return wrapper
def init_app(self, app):
pass

View file

@ -18,7 +18,7 @@ def setup(args):
if args.api_keys and args.require_api_key_secret:
scheduler.add_job(func=rotate_secrets, trigger="interval", minutes=30)
scheduler.start()
# Shut down the scheduler when exiting the app

View file

@ -12,7 +12,7 @@ def rotate_secrets():
secret_1 = s.get_str("secret_1")
s.set_str("secret_0", secret_1)
s.set_str("secret_1", generate_secret())
def secret_match(secret):
s = get_storage()

View file

@ -31,22 +31,22 @@ class Storage:
raise Exception("not implemented")
def dec_hash_int(self, ns, key):
raise Exception("not implemented")
def get_hash_keys(self, ns):
raise Exception("not implemented")
def del_hash(self, ns, key):
raise Exception("not implemented")
class MemoryStorage(Storage):
def __init__(self):
self.store = {}
def exists(self, key):
return key in self.store
def set_bool(self, key, value):
self.store[key] = bool(value)
def get_bool(self, key):
return bool(self.store[key])
@ -55,10 +55,10 @@ class MemoryStorage(Storage):
def get_int(self, key):
return int(self.store.get(key, 0))
def set_str(self, key, value):
self.store[key] = value
def get_str(self, key):
return str(self.store.get(key, ""))
@ -74,7 +74,7 @@ class MemoryStorage(Storage):
def inc_hash_int(self, ns, key):
if ns not in self.store:
self.store[ns] = {}
if key not in self.store[ns]:
self.store[ns][key] = 0
else:
@ -83,7 +83,7 @@ class MemoryStorage(Storage):
def dec_hash_int(self, ns, key):
if ns not in self.store:
self.store[ns] = {}
if key not in self.store[ns]:
self.store[ns][key] = 0
else:
@ -103,13 +103,13 @@ class RedisStorage(Storage):
def __init__(self, redis_uri):
self.conn = redis.from_url(redis_uri)
self.conn.ping()
def exists(self, key):
return bool(self.conn.exists(key))
def set_bool(self, key, value):
self.conn.set(key, "1" if value else "0")
def get_bool(self, key):
return bool(self.conn.get(key))
@ -122,24 +122,24 @@ class RedisStorage(Storage):
return 0
else:
return v
def set_str(self, key, value):
self.conn.set(key, value)
def get_str(self, key):
v = self.conn.get(key)
if v is None:
return ""
else:
return v.decode('utf-8')
def get_hash_int(self, ns, key):
v = self.conn.hget(ns, key)
if v is None:
return 0
else:
return int(v)
def set_hash_int(self, ns, key, value):
self.conn.hset(ns, key, value)