chore: add pyupgrade pre-commit hook

- add --py3-plus flag to pyupgrade hook
- add --py36-plus flag to pyupgrade hook
This commit is contained in:
jo 2022-01-25 23:45:00 +01:00 committed by Kyle Robbertze
parent 21aaf9bca1
commit 32cb67806a
26 changed files with 90 additions and 86 deletions

View file

@ -77,7 +77,7 @@ class MessageListener:
self.wait_for_messages()
except (KeyboardInterrupt, SystemExit):
break # Break out of the while loop and exit the application
except select.error:
except OSError:
pass
except pika.exceptions.AMQPError as e:
if self._shutdown:
@ -141,9 +141,7 @@ class MessageListener:
Here we parse the message, spin up an analyzer process, and report the
metadata back to the Airtime web application (or report an error).
"""
logger.info(
" - Received '%s' on routing_key '%s'" % (body, method_frame.routing_key)
)
logger.info(f" - Received '{body}' on routing_key '{method_frame.routing_key}'")
# Declare all variables here so they exist in the exception handlers below, no matter what.
audio_file_path = ""

View file

@ -53,7 +53,7 @@ def process_http_requests(ipc_queue, http_retry_queue_path):
try:
with open(http_retry_queue_path, "rb") as pickle_file:
retry_queue = pickle.load(pickle_file)
except IOError as e:
except OSError as e:
if e.errno == 2:
pass
else:

View file

@ -25,7 +25,7 @@ def analyze_metadata(filename: str, metadata: Dict[str, Any]):
"metadata must be a dict. Was of type " + type(metadata).__name__
)
if not os.path.exists(filename):
raise FileNotFoundError("audio file not found: {}".format(filename))
raise FileNotFoundError(f"audio file not found: {filename}")
# Airtime <= 2.5.x nonsense:
metadata["ftype"] = "audioclip"
@ -186,6 +186,6 @@ def _analyze_wave(filename, metadata):
metadata["length_seconds"] = length_seconds
metadata["cueout"] = metadata["length"]
except wave.Error as ex:
logger.error("Invalid WAVE file: {}".format(str(ex)))
logger.error(f"Invalid WAVE file: {str(ex)}")
raise
return metadata

View file

@ -46,7 +46,7 @@ def organise_file(audio_file_path, import_directory, original_filename, metadata
"metadata must be a dict. Was of type " + type(metadata).__name__
)
if not os.path.exists(audio_file_path):
raise FileNotFoundError("audio file not found: {}".format(audio_file_path))
raise FileNotFoundError(f"audio file not found: {audio_file_path}")
# Import the file over to it's final location.
# TODO: Also, handle the case where the move fails and write some code
@ -80,7 +80,7 @@ def organise_file(audio_file_path, import_directory, original_filename, metadata
metadata["full_path"] = final_file_path
return metadata
base_file_path, file_extension = os.path.splitext(final_file_path)
final_file_path = "%s_%s%s" % (
final_file_path = "{}_{}{}".format(
base_file_path,
time.strftime("%m-%d-%Y-%H-%M-%S", time.localtime()),
file_extension,
@ -89,7 +89,7 @@ def organise_file(audio_file_path, import_directory, original_filename, metadata
# If THAT path exists, append a UUID instead:
while os.path.exists(final_file_path):
base_file_path, file_extension = os.path.splitext(final_file_path)
final_file_path = "%s_%s%s" % (
final_file_path = "{}_{}{}".format(
base_file_path,
str(uuid.uuid4()),
file_extension,
@ -99,7 +99,7 @@ def organise_file(audio_file_path, import_directory, original_filename, metadata
mkdir_p(os.path.dirname(final_file_path))
# Move the file into its final destination directory
logger.debug("Moving %s to %s" % (audio_file_path, final_file_path))
logger.debug(f"Moving {audio_file_path} to {final_file_path}")
shutil.move(audio_file_path, final_file_path)
metadata["full_path"] = final_file_path