Skip to content

Commit

Permalink
Ran black (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull authored May 7, 2023
1 parent ee8053d commit f0aa69d
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 38 deletions.
4 changes: 3 additions & 1 deletion osxphotos/cli/click_rich_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def rich_echo(
# if not outputting to terminal, use a huge width to avoid wrapping
# otherwise tests fail
width = 10_000
console = get_rich_console() or Console(theme=theme or get_rich_theme(), width=width)
console = get_rich_console() or Console(
theme=theme or get_rich_theme(), width=width
)
if markdown:
message = Markdown(message)
# Markdown always adds a new line so disable unless explicitly specified
Expand Down
7 changes: 2 additions & 5 deletions osxphotos/cli/darkmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@
import objc
import Foundation


def theme():
with objc.autorelease_pool():
user_defaults = Foundation.NSUserDefaults.standardUserDefaults()
system_theme = user_defaults.stringForKey_("AppleInterfaceStyle")
return "dark" if system_theme == "Dark" else "light"


def is_dark_mode():
return theme() == "dark"


def is_light_mode():
return theme() == "light"

else:

def theme():
return "light"


def is_dark_mode():
return theme() == "dark"


def is_light_mode():
return theme() == "light"
4 changes: 2 additions & 2 deletions osxphotos/cli/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def dump(
print_template,
):
"""Print list of all photos & associated info from the Photos library.
NOTE: dump is DEPRECATED and will be removed in a future release.
NOTE: dump is DEPRECATED and will be removed in a future release.
Use `osxphotos query` instead.
"""

Expand Down
4 changes: 3 additions & 1 deletion osxphotos/cli/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ def get_help(self, ctx):

if is_macos:
formatter.write(
rich_text("## Extended Attributes", width=formatter.width, markdown=True)
rich_text(
"## Extended Attributes", width=formatter.width, markdown=True
)
)
formatter.write("\n")
formatter.write_text(
Expand Down
6 changes: 0 additions & 6 deletions osxphotos/cli/param_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def convert(self, value, param, ctx):


class DateTimeISO8601(click.ParamType):

name = "DATETIME"

def convert(self, value, param, ctx):
Expand All @@ -82,7 +81,6 @@ def convert(self, value, param, ctx):


class BitMathSize(click.ParamType):

name = "BITMATH"

def convert(self, value, param, ctx):
Expand All @@ -102,7 +100,6 @@ def convert(self, value, param, ctx):


class TimeISO8601(click.ParamType):

name = "TIME"

def convert(self, value, param, ctx):
Expand Down Expand Up @@ -141,7 +138,6 @@ def convert(self, value, param, ctx):


class ExportDBType(click.ParamType):

name = "EXPORTDB"

def convert(self, value, param, ctx):
Expand Down Expand Up @@ -279,7 +275,6 @@ def convert(self, value, param, ctx):


class Latitude(click.ParamType):

name = "Latitude"

def convert(self, value, param, ctx):
Expand All @@ -295,7 +290,6 @@ def convert(self, value, param, ctx):


class Longitude(click.ParamType):

name = "Longitude"

def convert(self, value, param, ctx):
Expand Down
25 changes: 15 additions & 10 deletions osxphotos/cli/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@
from .print_photo_info import print_photo_fields, print_photo_info
from .verbose import get_verbose_console

MACOS_OPTIONS = make_click_option_decorator(*[
click.Option(
["--add-to-album"],
metavar="ALBUM",
help="Add all photos from query to album ALBUM in Photos. Album ALBUM will be created "
"if it doesn't exist. All photos in the query results will be added to this album. "
"This only works if the Photos library being queried is the last-opened (default) library in Photos. "
"This feature is currently experimental. I don't know how well it will work on large query sets.",
),
] if is_macos else [])
MACOS_OPTIONS = make_click_option_decorator(
*[
click.Option(
["--add-to-album"],
metavar="ALBUM",
help="Add all photos from query to album ALBUM in Photos. Album ALBUM will be created "
"if it doesn't exist. All photos in the query results will be added to this album. "
"This only works if the Photos library being queried is the last-opened (default) library in Photos. "
"This feature is currently experimental. I don't know how well it will work on large query sets.",
),
]
if is_macos
else []
)


@click.command()
@DB_OPTION
Expand Down
1 change: 1 addition & 0 deletions osxphotos/cli/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def repl(ctx, cli_obj, db, emacs, beta, **kwargs):
import logging

from objexplore import explore

if is_macos:
from photoscript import Album, Photo, PhotosLibrary
from rich import inspect as _inspect
Expand Down
8 changes: 6 additions & 2 deletions osxphotos/cli/report_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ def __init__(
with suppress(FileNotFoundError):
os.unlink(self.output_file)

self._conn = sqlite3.connect(self.output_file, check_same_thread=SQLITE_CHECK_SAME_THREAD)
self._conn = sqlite3.connect(
self.output_file, check_same_thread=SQLITE_CHECK_SAME_THREAD
)
self._create_tables()
self.report_id = self._generate_report_id()

Expand Down Expand Up @@ -534,7 +536,9 @@ def __init__(
with suppress(FileNotFoundError):
os.unlink(self.output_file)

self._conn = sqlite3.connect(self.output_file, check_same_thread=SQLITE_CHECK_SAME_THREAD)
self._conn = sqlite3.connect(
self.output_file, check_same_thread=SQLITE_CHECK_SAME_THREAD
)
self._create_tables()
self.report_id = self._generate_report_id()

Expand Down
1 change: 1 addition & 0 deletions osxphotos/cli/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def get_photo_metadata(photos: list[PhotoInfo]) -> str:
photos_dict[k] = v
elif photos_dict[k] and v != photos_dict[k]:
photos_dict[k] = f"{photos_dict[k]} {v}"

# convert photos_dict to JSON string
# wouldn't it be nice if json encoder handled datetimes...
def default(o):
Expand Down
2 changes: 1 addition & 1 deletion osxphotos/datetime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"utc_offset_seconds",
]


# TODO: look at https://github.com/regebro/tzlocal for more robust implementation
def get_local_tz(dt: datetime.datetime) -> datetime.tzinfo:
"""Return local timezone as datetime.timezone tzinfo for dt
Expand Down Expand Up @@ -207,4 +208,3 @@ def utc_offset_seconds(dt: datetime.datetime) -> int:
return dt.tzinfo.utcoffset(dt).total_seconds()
else:
raise ValueError("dt does not have timezone info")

12 changes: 8 additions & 4 deletions osxphotos/photokit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import threading
import time

assert(sys.platform == "darwin")
assert sys.platform == "darwin"

import AVFoundation
import CoreServices
Expand Down Expand Up @@ -87,6 +87,7 @@
# minimum amount to sleep while waiting for export
MIN_SLEEP = 0.015


### utility functions
def NSURL_to_path(url):
"""Convert URL string as represented by NSURL to a path string"""
Expand Down Expand Up @@ -629,7 +630,8 @@ def _request_image_data(self, version=PHOTOS_VERSION_ORIGINAL):

def handler(imageData, dataUTI, orientation, info):
"""result handler for requestImageDataAndOrientationForAsset_options_resultHandler_
all returned by the request is set as properties of nonlocal data (Fetchdata object)"""
all returned by the request is set as properties of nonlocal data (Fetchdata object)
"""

nonlocal requestdata

Expand Down Expand Up @@ -676,7 +678,8 @@ def _request_resource_data(self, resource):

def handler(data):
"""result handler for requestImageDataAndOrientationForAsset_options_resultHandler_
all returned by the request is set as properties of nonlocal data (Fetchdata object)"""
all returned by the request is set as properties of nonlocal data (Fetchdata object)
"""

nonlocal requestdata

Expand Down Expand Up @@ -713,7 +716,8 @@ def _make_result_handle_(self, data):

def handler(imageData, dataUTI, orientation, info):
"""result handler for requestImageDataAndOrientationForAsset_options_resultHandler_
all returned by the request is set as properties of nonlocal data (Fetchdata object)"""
all returned by the request is set as properties of nonlocal data (Fetchdata object)
"""

nonlocal data

Expand Down
4 changes: 3 additions & 1 deletion osxphotos/photosdb/_photosdb_process_faceinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ def _process_faceinfo_5(photosdb):
face["righteyey"] = row[34]
face["roll"] = row[35]
face["size"] = row[36]
face["yaw"] = 0 # Photos 4 only (this is in Photos 5-7, but dropped in Ventura so just don't support it)
face[
"yaw"
] = 0 # Photos 4 only (this is in Photos 5-7, but dropped in Ventura so just don't support it)
face["pitch"] = 0 # not defined in Photos 5

photosdb._db_faceinfo_pk[pk] = face
Expand Down
1 change: 1 addition & 0 deletions osxphotos/placeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
],
)


# The following classes represent Photo Library Reverse Geolocation Info as stored
# in ZADDITIONALASSETATTRIBUTES.ZREVERSELOCATIONDATA
# These classes are used by bpylist.archiver to unarchive the serialized objects
Expand Down
2 changes: 1 addition & 1 deletion osxphotos/sqlgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def sqlgrep(
flags = re.IGNORECASE if ignore_case else 0
try:
with sqlite3.connect(f"file:{filename}?mode=ro", uri=True) as conn:
regex = re.compile(f'({pattern})', flags=flags)
regex = re.compile(f"({pattern})", flags=flags)
filename_header = f"{filename}: " if print_filename else ""
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
Expand Down
4 changes: 1 addition & 3 deletions osxphotos/timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ def format_offset_time(offset: int) -> str:
import Foundation
import objc


def known_timezone_names():
"""Get list of valid timezones on macOS"""
return Foundation.NSTimeZone.knownTimeZoneNames()


class Timezone:
"""Create Timezone object from either name (str) or offset from GMT (int)"""

Expand Down Expand Up @@ -63,6 +61,7 @@ def __eq__(self, other):
if isinstance(other, Timezone):
return self.timezone == other.timezone
return False

else:
import zoneinfo
from datetime import datetime
Expand All @@ -71,7 +70,6 @@ def known_timezone_names():
"""Get list of valid timezones"""
return zoneinfo.available_timezones()


class Timezone:
"""Create Timezone object from either name (str) or offset from GMT (int)"""

Expand Down
5 changes: 4 additions & 1 deletion osxphotos/uti.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,13 @@ def _load_uti_dict():
EXT_UTI_DICT[row["extension"]] = row["UTI"]
UTI_EXT_DICT[row["UTI"]] = row["preferred_extension"]


_load_uti_dict()

# OS version for determining which methods can be used
OS_VER, OS_MAJOR, _ = (int(x) for x in get_macos_version()) if is_macos else (None, None, None)
OS_VER, OS_MAJOR, _ = (
(int(x) for x in get_macos_version()) if is_macos else (None, None, None)
)


def _get_uti_from_mdls(extension):
Expand Down
3 changes: 3 additions & 0 deletions osxphotos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

is_macos = sys.platform == "darwin"


def assert_macos():
assert is_macos, "This feature only runs on macOS"

Expand Down Expand Up @@ -280,6 +281,8 @@ def list_photo_libraries():


T = TypeVar("T", bound=Union[str, pathlib.Path])


def normalize_fs_path(path: T) -> T:
"""Normalize filesystem paths with unicode in them"""
form = "NFD" if is_macos else "NFC"
Expand Down

0 comments on commit f0aa69d

Please sign in to comment.