Skip to content

Commit

Permalink
style: applied `pyupgrade --py37-plus aw_core/**.py aw_datastore/**.p…
Browse files Browse the repository at this point in the history
…y aw_query/**.py aw_transform/**.py`
  • Loading branch information
ErikBjare committed Feb 3, 2022
1 parent ab7efc8 commit 6fcace7
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions aw_core/config.py
Expand Up @@ -41,14 +41,14 @@ def load_config_toml(
appname: str, default_config: str
) -> Union[dict, tomlkit.container.Container]:
config_dir = dirs.get_config_dir(appname)
config_file_path = os.path.join(config_dir, "{}.toml".format(appname))
config_file_path = os.path.join(config_dir, f"{appname}.toml")

# Run early to ensure input is valid toml before writing
default_config_toml = tomlkit.parse(default_config)

# Override defaults from existing config file
if os.path.isfile(config_file_path):
with open(config_file_path, "r") as f:
with open(config_file_path) as f:
config = f.read()
config_toml = tomlkit.parse(config)
else:
Expand All @@ -67,7 +67,7 @@ def save_config_toml(appname: str, config: str) -> None:
assert tomlkit.parse(config)

config_dir = dirs.get_config_dir(appname)
config_file_path = os.path.join(config_dir, "{}.toml".format(appname))
config_file_path = os.path.join(config_dir, f"{appname}.toml")

with open(config_file_path, "w") as f:
f.write(config)
Expand All @@ -86,11 +86,11 @@ def load_config(appname, default_config):
config = default_config

config_dir = dirs.get_config_dir(appname)
config_file_path = os.path.join(config_dir, "{}.toml".format(appname))
config_file_path = os.path.join(config_dir, f"{appname}.toml")

# Override defaults from existing config file
if os.path.isfile(config_file_path):
with open(config_file_path, "r") as f:
with open(config_file_path) as f:
config.read_file(f)

# Overwrite current config file (necessary in case new default would be added)
Expand All @@ -106,7 +106,7 @@ def load_config(appname, default_config):
)
def save_config(appname, config):
config_dir = dirs.get_config_dir(appname)
config_file_path = os.path.join(config_dir, "{}.ini".format(appname))
config_file_path = os.path.join(config_dir, f"{appname}.ini")
with open(config_file_path, "w") as f:
config.write(f)
# Flush and fsync to lower risk of corrupted files
Expand Down
2 changes: 1 addition & 1 deletion aw_core/decorators.py
Expand Up @@ -44,7 +44,7 @@ def g(*args, **kwargs):
except exception as e:
# TODO: Use warnings module instead?
logging.error(
"{} crashed due to exception, restarting.".format(f.__name__)
f"{f.__name__} crashed due to exception, restarting."
)
logging.error(e)
time.sleep(
Expand Down
2 changes: 1 addition & 1 deletion aw_core/log.py
Expand Up @@ -141,7 +141,7 @@ def _create_json_formatter() -> logging.Formatter: # pragma: no cover

def log_format(x):
"""Used to give JsonFormatter proper parameter format"""
return ["%({0:s})".format(i) for i in x]
return [f"%({i:s})" for i in x]

custom_format = " ".join(log_format(supported_keys))

Expand Down
4 changes: 2 additions & 2 deletions aw_core/models.py
Expand Up @@ -30,7 +30,7 @@ def _timestamp_parse(ts_in: ConvertableTimestamp) -> datetime:
if not ts.tzinfo:
# Needed? All timestamps should be iso8601 so ought to always contain timezone.
# Yes, because it is optional in iso8601
logger.warning("timestamp without timezone found, using UTC: {}".format(ts))
logger.warning(f"timestamp without timezone found, using UTC: {ts}")
ts = ts.replace(tzinfo=timezone.utc)
return ts

Expand Down Expand Up @@ -137,5 +137,5 @@ def duration(self, duration: Duration) -> None:
self["duration"] = timedelta(seconds=duration) # type: ignore
else:
raise TypeError(
"Couldn't parse duration of invalid type {}".format(type(duration))
f"Couldn't parse duration of invalid type {type(duration)}"
)
2 changes: 1 addition & 1 deletion aw_core/util.py
Expand Up @@ -22,4 +22,4 @@ def assert_version(required_version: Tuple[int, ...] = (3, 5)): # pragma: no co
+ " version to at least {}."
).format(required_version)
)
logger.debug("Python version: {}".format(_version_info_tuple()))
logger.debug(f"Python version: {_version_info_tuple()}")
6 changes: 3 additions & 3 deletions aw_datastore/benchmark.py
Expand Up @@ -59,14 +59,14 @@ def benchmark(storage: Callable[..., AbstractStorage]):

with temporary_bucket(ds) as bucket:
with ttt(" sum"):
with ttt(" single insert {} events".format(num_single_events)):
with ttt(f" single insert {num_single_events} events"):
for event in single_events:
bucket.insert(event)

with ttt(" bulk insert {} events".format(num_bulk_events)):
with ttt(f" bulk insert {num_bulk_events} events"):
bucket.insert(bulk_events)

with ttt(" replace last {}".format(num_replace_events)):
with ttt(f" replace last {num_replace_events}"):
for e in replace_events:
bucket.replace_last(e)

Expand Down
4 changes: 2 additions & 2 deletions aw_datastore/datastore.py
Expand Up @@ -52,14 +52,14 @@ def create_bucket(
created: datetime = datetime.now(timezone.utc),
name: Optional[str] = None,
) -> "Bucket":
self.logger.info("Creating bucket '{}'".format(bucket_id))
self.logger.info(f"Creating bucket '{bucket_id}'")
self.storage_strategy.create_bucket(
bucket_id, type, client, hostname, created.isoformat(), name=name
)
return self[bucket_id]

def delete_bucket(self, bucket_id: str):
self.logger.info("Deleting bucket '{}'".format(bucket_id))
self.logger.info(f"Deleting bucket '{bucket_id}'")
if bucket_id in self.bucket_instances:
del self.bucket_instances[bucket_id]
return self.storage_strategy.delete_bucket(bucket_id)
Expand Down
4 changes: 2 additions & 2 deletions aw_datastore/migration.py
Expand Up @@ -23,7 +23,7 @@ def detect_db_files(
db_files = [
filename
for filename in db_files
if filename.split(".")[1] == "v{}".format(version)
if filename.split(".")[1] == f"v{version}"
]
return db_files

Expand All @@ -49,7 +49,7 @@ def peewee_v2_to_sqlite_v1(datastore):
buckets = pw_db.buckets()
# Insert buckets and events to new db
for bucket_id in buckets:
logger.info("Migrating bucket {}".format(bucket_id))
logger.info(f"Migrating bucket {bucket_id}")
bucket = buckets[bucket_id]
datastore.create_bucket(
bucket["id"],
Expand Down
4 changes: 2 additions & 2 deletions aw_datastore/storages/peewee.py
Expand Up @@ -117,13 +117,13 @@ def __init__(self, testing: bool = True, filepath: str = None) -> None:
filename = (
"peewee-sqlite"
+ ("-testing" if testing else "")
+ ".v{}".format(LATEST_VERSION)
+ f".v{LATEST_VERSION}"
+ ".db"
)
filepath = os.path.join(data_dir, filename)
self.db = _db
self.db.init(filepath)
logger.info("Using database file: {}".format(filepath))
logger.info(f"Using database file: {filepath}")

self.db.connect()

Expand Down
4 changes: 2 additions & 2 deletions aw_datastore/storages/sqlite.py
Expand Up @@ -67,12 +67,12 @@ def __init__(self, testing, filepath: str = None, enable_lazy_commit=True) -> No
ds_name = self.sid + ("-testing" if testing else "")
if not filepath:
data_dir = get_data_dir("aw-server")
filename = ds_name + ".v{}".format(LATEST_VERSION) + ".db"
filename = ds_name + f".v{LATEST_VERSION}" + ".db"
filepath = os.path.join(data_dir, filename)

new_db_file = not os.path.exists(filepath)
self.conn = sqlite3.connect(filepath)
logger.info("Using database file: {}".format(filepath))
logger.info(f"Using database file: {filepath}")

# Create tables
self.conn.execute(CREATE_BUCKETS_TABLE)
Expand Down
2 changes: 1 addition & 1 deletion aw_query/functions.py
Expand Up @@ -35,7 +35,7 @@ def _verify_bucket_exists(datastore, bucketname):
if bucketname in datastore.buckets():
return
else:
raise QueryFunctionException("There's no bucket named '{}'".format(bucketname))
raise QueryFunctionException(f"There's no bucket named '{bucketname}'")


def _verify_variable_is_type(variable, t):
Expand Down
4 changes: 2 additions & 2 deletions aw_query/query2.py
Expand Up @@ -124,7 +124,7 @@ def __init__(self, name, args):
def interpret(self, datastore: Datastore, namespace: dict):
if self.name not in functions:
raise QueryInterpretException(
"Tried to call function '{}' which doesn't exist".format(self.name)
f"Tried to call function '{self.name}' which doesn't exist"
)
call_args = [datastore, namespace]
for arg in self.args:
Expand Down Expand Up @@ -345,7 +345,7 @@ def _parse_token(string: str, namespace: dict) -> Tuple[Tuple[Any, str], str]:
if token:
break
if not token:
raise QueryParseException("Syntax error: {}".format(string))
raise QueryParseException(f"Syntax error: {string}")
return (t, token), string


Expand Down

0 comments on commit 6fcace7

Please sign in to comment.