Run black on entire project

This commit is contained in:
Sumner Evans
2020-04-23 20:17:45 -06:00
parent e5b3e659ff
commit 0ed2c266d8
52 changed files with 2603 additions and 2917 deletions

View File

@@ -6,7 +6,7 @@ from datetime import datetime
from pathlib import Path
from typing import Any, Dict, Optional, Sequence, Tuple
from sublime.adapters.api_objects import (Playlist, PlaylistDetails)
from sublime.adapters.api_objects import Playlist, PlaylistDetails
from . import models
from .. import CacheMissError, CachingAdapter, ConfigParamDescriptor
@@ -16,6 +16,7 @@ class FilesystemAdapter(CachingAdapter):
"""
Defines an adapter which retrieves its data from the local filesystem.
"""
# Configuration and Initialization Properties
# =========================================================================
@staticmethod
@@ -25,19 +26,15 @@ class FilesystemAdapter(CachingAdapter):
}
@staticmethod
def verify_configuration(
config: Dict[str, Any]) -> Dict[str, Optional[str]]:
def verify_configuration(config: Dict[str, Any]) -> Dict[str, Optional[str]]:
return {}
def __init__(
self,
config: dict,
data_directory: Path,
is_cache: bool = False,
self, config: dict, data_directory: Path, is_cache: bool = False,
):
self.data_directory = data_directory
self.is_cache = is_cache
database_filename = data_directory.joinpath('cache.db')
database_filename = data_directory.joinpath("cache.db")
models.database.init(database_filename)
models.database.connect()
@@ -45,7 +42,7 @@ class FilesystemAdapter(CachingAdapter):
models.database.create_tables(models.ALL_TABLES)
def shutdown(self):
logging.info('Shutdown complete')
logging.info("Shutdown complete")
# Usage Properties
# =========================================================================
@@ -59,7 +56,7 @@ class FilesystemAdapter(CachingAdapter):
# Data Helper Methods
# =========================================================================
def _params_hash(self, *params: Any) -> str:
return hashlib.sha1(bytes(json.dumps(params), 'utf8')).hexdigest()
return hashlib.sha1(bytes(json.dumps(params), "utf8")).hexdigest()
# Data Retrieval Methods
# =========================================================================
@@ -74,20 +71,17 @@ class FilesystemAdapter(CachingAdapter):
# not, cache miss.
function_name = CachingAdapter.FunctionNames.GET_PLAYLISTS
if not models.CacheInfo.get_or_none(
models.CacheInfo.query_name == function_name):
models.CacheInfo.query_name == function_name
):
raise CacheMissError()
return playlists
can_get_playlist_details: bool = True
def get_playlist_details(
self,
playlist_id: str,
) -> PlaylistDetails:
playlist = models.Playlist.get_or_none(
models.Playlist.id == playlist_id)
def get_playlist_details(self, playlist_id: str,) -> PlaylistDetails:
playlist = models.Playlist.get_or_none(models.Playlist.id == playlist_id)
if not playlist and not self.is_cache:
raise Exception(f'Playlist {playlist_id} does not exist.')
raise Exception(f"Playlist {playlist_id} does not exist.")
# If we haven't ingested data for this playlist before, raise a
# CacheMissError with the partial playlist data.
@@ -106,11 +100,11 @@ class FilesystemAdapter(CachingAdapter):
@models.database.atomic()
def ingest_new_data(
self,
function: 'CachingAdapter.FunctionNames',
function: "CachingAdapter.FunctionNames",
params: Tuple[Any, ...],
data: Any,
):
assert self.is_cache, 'FilesystemAdapter is not in cache mode'
assert self.is_cache, "FilesystemAdapter is not in cache mode"
models.CacheInfo.insert(
query_name=function,
@@ -119,24 +113,25 @@ class FilesystemAdapter(CachingAdapter):
).on_conflict_replace().execute()
if function == CachingAdapter.FunctionNames.GET_PLAYLISTS:
models.Playlist.insert_many(map(
asdict, data)).on_conflict_replace().execute()
models.Playlist.insert_many(
map(asdict, data)
).on_conflict_replace().execute()
elif function == CachingAdapter.FunctionNames.GET_PLAYLIST_DETAILS:
playlist_data = asdict(data)
playlist, playlist_created = models.Playlist.get_or_create(
id=playlist_data['id'],
defaults=playlist_data,
id=playlist_data["id"], defaults=playlist_data,
)
# Handle the songs.
songs = []
for index, song_data in enumerate(playlist_data['songs']):
for index, song_data in enumerate(playlist_data["songs"]):
# args = dict(filter(lambda kv: kv[0] in f, song_data.items()))
song_data['index'] = index
song_data["index"] = index
song, song_created = models.Song.get_or_create(
id=song_data['id'], defaults=song_data)
id=song_data["id"], defaults=song_data
)
keys = ('title', 'duration', 'path', 'index')
keys = ("title", "duration", "path", "index")
if not song_created:
for key in keys:
setattr(song, key, song_data[key])
@@ -145,7 +140,7 @@ class FilesystemAdapter(CachingAdapter):
songs.append(song)
playlist.songs = songs
del playlist_data['songs']
del playlist_data["songs"]
# Update the values if the playlist already existed.
if not playlist_created: