Skip to content

Commit

Permalink
Formatted code, updated dev instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Nov 5, 2024
1 parent 70373b6 commit 23a8930
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 32 deletions.
1 change: 1 addition & 0 deletions README_DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ If you want to contribute to osxphotos, please open a pull request. Here's how t
- Make your changes
- Add tests for your changes
- Run the tests: `pytest`
- Format the code: `isort .` then `black .`
- Update the README.md and other files as needed
- Add your changes using `git add`
- Commit your changes: `git commit -m "My changes description"`
Expand Down
10 changes: 6 additions & 4 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
black
build
bump2version==1.0.1
bump2version==1.0.1
cogapp>=3.3.0,<4.0.0
furo
isort
m2r2==0.3.3.post2
pdbpp
pyinstaller==5.13.2
pytest-cov==4.0.0
pytest-cov==4.0.0
pytest-mock
pytest==7.4.0
ruff==0.0.286
ruff==0.7.2
Sphinx
sphinx_click
sphinx_rtd_theme
sphinx-copybutton
sphinxcontrib-programoutput
twine
wheel
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
8 changes: 6 additions & 2 deletions examples/add_finder_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def add_metadata_to_photo(
):
"""Add Finder tags to matching photo in Photos library as keywords."""
tags = get_finder_tags(filepath, include, exclude)
echo(f"Finder tags for [filepath]{filepath}[/]: [i]{', '.join(tags) if tags else None}[/]")
echo(
f"Finder tags for [filepath]{filepath}[/]: [i]{', '.join(tags) if tags else None}[/]"
)
if matches := fq.possible_duplicates(filepath):
echo(
f"Adding Finder tags to [num]{len(matches)}[/] matching photo(s) in Photos library..."
Expand All @@ -128,7 +130,9 @@ def add_metadata_to_photo(
if not photo:
echo(f"Could not find photo with UUID [uuid]{match[0]}[/]", err=True)
continue
echo(f"Processing photo [filename]{photo.filename}[/] ([uuid]{photo.uuid}[/])")
echo(
f"Processing photo [filename]{photo.filename}[/] ([uuid]{photo.uuid}[/])"
)
add_keywords_to_photo(photo, tags, dry_run)
if caption:
add_comment_to_photo(photo, filepath, dry_run)
Expand Down
4 changes: 3 additions & 1 deletion examples/timewarp_function_creation_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def creation_date(
"""

if not path:
verbose(f"Could not get path for photo {photo.original_filename} ({photo.uuid}); skipping")
verbose(
f"Could not get path for photo {photo.original_filename} ({photo.uuid}); skipping"
)
return photo.date, tz_sec

# this example uses's the file's creation date/time; the timezone is not changed
Expand Down
1 change: 1 addition & 0 deletions examples/top_10_unnamed_faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ def main():
album = PhotosAlbum(album_name)
album.update(photos)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion osxphotos/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from osxphotos._constants import PROFILE_SORT_KEYS
from osxphotos._version import __version__
from osxphotos.disclaim import disclaim, pyinstaller, pyapp
from osxphotos.disclaim import disclaim, pyapp, pyinstaller
from osxphotos.platform import is_macos

from .about import about
Expand Down
2 changes: 1 addition & 1 deletion osxphotos/cli/photo_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def get_photo_type(photo: PhotoInfo) -> str:
if photo.screenshot:
photo_type += " screenshot"
if photo.screen_recording:
photo_type += " screen recording"
photo_type += " screen recording"
if photo.slow_mo:
photo_type += " slow-mo"
if photo.time_lapse:
Expand Down
10 changes: 7 additions & 3 deletions osxphotos/cli/push_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,14 @@ def compare_location(photo: PhotoInfo, file_data: dict[str, Any]) -> str:
exif_latitude_ref = file_data.get("EXIF:GPSLatitudeRef")
exif_longitude_ref = file_data.get("EXIF:GPSLongitudeRef")
elif photo.ismovie:
exif_coordinates = file_data.get('QuickTime:GPSCoordinates')
exif_latitude, exif_longitude = [float(x) for x in exif_coordinates.split()[:2]] if exif_coordinates else [ None, None]
exif_coordinates = file_data.get("QuickTime:GPSCoordinates")
exif_latitude, exif_longitude = (
[float(x) for x in exif_coordinates.split()[:2]]
if exif_coordinates
else [None, None]
)
exif_latitude_ref = None
exif_longitude_ref = None
exif_longitude_ref = None

if exif_longitude and exif_longitude_ref == "W":
exif_longitude = -exif_longitude
Expand Down
4 changes: 1 addition & 3 deletions osxphotos/cli/sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ def get_sidecar_file_with_template(
if not sidecar_file or not sidecar_file.exists():
if edited_suffix:
# try again with the edited suffix removed
filepath = strip_edited_suffix(
filepath, edited_suffix, exiftool_path
)
filepath = strip_edited_suffix(filepath, edited_suffix, exiftool_path)
return get_sidecar_file_with_template(
filepath,
sidecar,
Expand Down
8 changes: 5 additions & 3 deletions osxphotos/cli/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def import_metadata_for_photo(
# If --set use origin location in the destination photo
results += _set_location_for_photo(photo, metadata, dry_run, verbose)
elif "location" in merge:
# if --merge
# if --merge
# and property is set in the destination then no action is taken;
# if property is not set in the destination but is set in the source,
# then the value is copied to destination.
Expand All @@ -390,6 +390,7 @@ def import_metadata_for_photo(

return results


def _process_location_for_photo(
photo: PhotoInfo,
metadata: dict[str, Any],
Expand Down Expand Up @@ -433,7 +434,8 @@ def _process_location_for_photo(
field,
updated,
before,
value)
value,
)
return results


Expand Down Expand Up @@ -520,7 +522,7 @@ def _set_metadata_for_photo(

value = metadata[field]
before = getattr(photo, field)

if isinstance(value, list):
value = sorted(value)
if isinstance(before, list):
Expand Down
2 changes: 1 addition & 1 deletion osxphotos/cli/timewarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def timewarp_cli(

if inspect and compare_exif:
raise click.UsageError("--inspect and --compare-exif are mutually exclusive.")

if date and date_delta:
raise click.UsageError("--date and --date-delta are mutually exclusive.")

Expand Down
8 changes: 4 additions & 4 deletions osxphotos/compare_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ def timewarp_compare_exif(self, photo: Photo, plain: bool = False) -> ExifDiff:
Args:
photo (Photo): Photo object to compare
plain (bool): Flag to determine if plain (True) or markup (False) should be applied
"""
"""

def compare_values(photo_value: str, exif_value: str) -> tuple:
"""Compare two values and return them with or without markup.
Affects nonlocal variable diff (from timewarp_compare_exif) with result.
"""

Expand All @@ -110,7 +111,7 @@ def compare_values(photo_value: str, exif_value: str) -> tuple:
if not plain:
return no_change(photo_value), no_change(exif_value)
return photo_value, exif_value

# Get values from comparison function
photos_date, photos_tz, exif_date, exif_tz = self.compare_exif(photo)
diff = False
Expand All @@ -136,4 +137,3 @@ def compare_values(photo_value: str, exif_value: str) -> tuple:
exif_time,
exif_tz,
)

2 changes: 1 addition & 1 deletion osxphotos/export_db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import pathlib
import sqlite3
from typing import Any, Callable, Optional, Tuple, Union
import tenacity

import tenacity
import toml
from rich import print

Expand Down
11 changes: 7 additions & 4 deletions osxphotos/photoexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,7 @@ def _stage_photos_for_export(self, options: ExportOptions) -> StagedFiles:
staged = StagedFiles()

if options.use_photos_export:
return self._stage_missing_photos_for_export_helper(
options=options)
return self._stage_missing_photos_for_export_helper(options=options)

if options.raw_photo and self.photo.has_raw:
staged.raw = self.photo.path_raw
Expand Down Expand Up @@ -648,7 +647,8 @@ def _stage_missing_photos_for_export(
use_photokit=options.use_photokit,
)
missing_staged = self._stage_missing_photos_for_export_helper(
options=missing_options)
options=missing_options
)
staged |= missing_staged
return staged

Expand Down Expand Up @@ -1233,7 +1233,10 @@ def _export_aae(
if action == "skip":
if dest.exists():
options.export_db.set_history(
filename=str(dest), uuid=self.photo.uuid, action=f"AAE: {action}", diff=None
filename=str(dest),
uuid=self.photo.uuid,
action=f"AAE: {action}",
diff=None,
)
return ExportResults(aae_skipped=[str(dest)], skipped=[str(dest)])
else:
Expand Down
1 change: 1 addition & 0 deletions osxphotos/photoinfo_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

__all__ = ["PhotoInfoProtocol", "PhotoInfoMixin"]


@runtime_checkable
class PhotoInfoProtocol(Protocol):
@property
Expand Down
4 changes: 3 additions & 1 deletion osxphotos/photokit.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ def screenshot(self):
@property
def screen_recording(self):
"""return True if asset is screen recordings, otherwise False"""
return bool(self.media_subtypes & Photos.PHAssetMediaSubtypePhotoScreenRecording)
return bool(
self.media_subtypes & Photos.PHAssetMediaSubtypePhotoScreenRecording
)

@property
def live(self):
Expand Down
1 change: 1 addition & 0 deletions osxphotos/photokit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# seconds to sleep between authorization check
AUTHORIZATION_SLEEP = 0.25


def wait_for_photokit_authorization() -> bool:
"""Request and wait for authorization to access Photos library."""
if check_photokit_authorization():
Expand Down
1 change: 1 addition & 0 deletions osxphotos/photosalbum.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def extend(self, photos: Iterable[Photo]):
"""Add list of photos to album"""
self.update(photos)


class PhotosAlbumPhotoScriptByPath(PhotosAlbumPhotoScript):
"""Add photoscript.Photo objects to album"""

Expand Down
2 changes: 1 addition & 1 deletion osxphotos/photosdb/photosdb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
_PHOTOS_6_MODEL_VERSION,
_PHOTOS_7_MODEL_VERSION,
_PHOTOS_8_MODEL_VERSION,
_PHOTOS_9_14_6_MODEL_VERSION,
_PHOTOS_9_MODEL_VERSION,
_PHOTOS_10_MODEL_VERSION,
_PHOTOS_10B1_MODEL_VERSION,
_TESTED_DB_VERSIONS,
_PHOTOS_9_14_6_MODEL_VERSION,
)
from ..sqlite_utils import sqlite_open_ro

Expand Down
2 changes: 1 addition & 1 deletion osxphotos/phototemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys
from contextlib import suppress
from dataclasses import dataclass
from typing import List, Optional, Tuple, TYPE_CHECKING
from typing import TYPE_CHECKING, List, Optional, Tuple

from textx import TextXSyntaxError, metamodel_from_file

Expand Down
4 changes: 3 additions & 1 deletion tests/test_cli_push_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,9 @@ def test_cli_push_exif_metadata_arg(monkeypatch):
assert "EXIF:CreateDate" not in exif

# verify faces were pushed
assert sorted(get_exiftool_tag_as_list(photo, "XMP:RegionsRegionListName")) == sorted(photo.persons)
assert sorted(
get_exiftool_tag_as_list(photo, "XMP:RegionsRegionListName")
) == sorted(photo.persons)

# clear metadata
photosdb = PhotosDB(test_library)
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test_sync_export_import():
assert report_data[uuid]["albums"]["updated"]
assert not report_data[uuid]["error"]


@pytest.mark.test_sync
def test_sync_export_import_location():
"""Test --export and --import location"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_sidecar_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def test_get_sidecar_file_with_template(tmp_path, data):
(tmp_path / file).touch()

import logging

sidecar_name = get_sidecar_file_with_template(
tmp_path / data["files"][0],
data["sidecar"],
Expand Down
2 changes: 2 additions & 0 deletions tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ def test_timezone_by_offset():
assert tz.offset_str == "-05:00"
assert isinstance(tz.tzinfo(datetime.datetime.now()), ZoneInfo)


@pytest.mark.skipif(not is_macos, reason="macOS only")
def test_timezone_invalid_zone():
"""Test that Timezone creation fails with an invalid zone name."""
with pytest.raises(ValueError, match="Invalid timezone: Invalid/Zone"):
Timezone("Invalid/Zone")


@pytest.mark.skipif(not is_macos, reason="macOS only")
def test_timezone_invalid_offset():
"""Test that Timezone creation fails with bad input type."""
Expand Down

0 comments on commit 23a8930

Please sign in to comment.