From f9b2c04ef677b5d454774ae73f276c7977e60522 Mon Sep 17 00:00:00 2001 From: clach04 Date: Sun, 11 Dec 2022 10:36:14 -0800 Subject: [PATCH 1/2] Fix comment typos --- elodie/geolocation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elodie/geolocation.py b/elodie/geolocation.py index 8179870a..e8783a88 100644 --- a/elodie/geolocation.py +++ b/elodie/geolocation.py @@ -147,7 +147,7 @@ def place_name(lat, lon): # Try to get cached location first db = Db() - # 3km distace radious for a match + # 3km distance radius for a match cached_place_name = db.get_location_name(lat, lon, 3000) # We check that it's a dict to coerce an upgrade of the location # db from a string location to a dictionary. See gh-160. From 35c9d05f1770faa12ca0642d82c2258bfcb2597d Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Thu, 16 Oct 2025 00:05:10 -0400 Subject: [PATCH 2/2] Fix issues with deprecated packages not compatible with Python 3.10+ (gh-418) (#487) Closes gh-418 --- .circleci/config.yml | 3 ++- elodie/dependencies.py | 4 ++-- elodie/geolocation.py | 8 ++------ elodie/media/photo.py | 34 ++++++++----------------------- elodie/tests/dependencies_test.py | 8 ++++---- elodie/tests/elodie_test.py | 7 +++++-- elodie/tests/geolocation_test.py | 1 - elodie/tests/helper.py | 11 +++++----- elodie/tests/media/photo_test.py | 5 ----- requirements.txt | 7 ++++--- 10 files changed, 33 insertions(+), 55 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b94771b..59232d93 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,8 @@ orbs: jobs: build_and_test: - executor: python/default + docker: + - image: cimg/python:3.13 steps: - checkout - run: diff --git a/elodie/dependencies.py b/elodie/dependencies.py index e575b5d5..c67b15da 100644 --- a/elodie/dependencies.py +++ b/elodie/dependencies.py @@ -6,7 +6,7 @@ import os import sys -from distutils.spawn import find_executable +import shutil #: Error to print when exiftool can't be found. @@ -25,7 +25,7 @@ def get_exiftool(): :returns: str or None """ - path = find_executable('exiftool') + path = shutil.which('exiftool') # If exiftool wasn't found we try to brute force the homebrew location if path is None: path = '/usr/local/bin/exiftool' diff --git a/elodie/geolocation.py b/elodie/geolocation.py index 2606bb90..b9904beb 100644 --- a/elodie/geolocation.py +++ b/elodie/geolocation.py @@ -1,10 +1,6 @@ """Look up geolocation information for media objects.""" from __future__ import print_function from __future__ import division -from future import standard_library -from past.utils import old_div - -standard_library.install_aliases() # noqa from os import path @@ -84,8 +80,8 @@ def dms_to_decimal(degrees, minutes, seconds, direction=' '): if(direction[0] in 'WSws'): sign = -1 return ( - float(degrees) + old_div(float(minutes), 60) + - old_div(float(seconds), 3600) + float(degrees) + (float(minutes) / 60) + + (float(seconds) / 3600) ) * sign diff --git a/elodie/media/photo.py b/elodie/media/photo.py index 07f3e047..c80c8ec1 100644 --- a/elodie/media/photo.py +++ b/elodie/media/photo.py @@ -7,7 +7,6 @@ from __future__ import print_function from __future__ import absolute_import -import imghdr import os import re import time @@ -72,7 +71,7 @@ def get_date_taken(self): for key in self.exif_map['date_taken']: try: if(key in exif): - if(re.match('\d{4}(-|:)\d{2}(-|:)\d{2}', exif[key]) is not None): # noqa + if(re.match(r'\d{4}(-|:)\d{2}(-|:)\d{2}', exif[key]) is not None): # noqa dt, tm = exif[key].split(' ') dt_list = compile(r'-|:').split(dt) dt_list = dt_list + compile(r'-|:').split(tm) @@ -105,28 +104,13 @@ def is_valid(self): if(extension != 'heic'): # gh-4 This checks if the source file is an image. # It doesn't validate against the list of supported types. - # We check with imghdr and pillow. - if(imghdr.what(source) is None): - # Pillow is used as a fallback and if it's not available we trust - # what imghdr returned. - if(self.pillow is None): - return False - else: - # imghdr won't detect all variants of images (https://bugs.python.org/issue28591) - # see https://github.com/jmathai/elodie/issues/281 - # before giving up, we use `pillow` imaging library to detect file type - # - # It is important to note that the library doesn't decode or load the - # raster data unless it really has to. When you open a file, - # the file header is read to determine the file format and extract - # things like mode, size, and other properties required to decode the file, - # but the rest of the file is not processed until later. - try: - im = self.pillow.open(source) - except IOError: - return False - - if(im.format is None): - return False + # We use pillow imaging library to detect file type + try: + im = self.pillow.open(source) + except IOError: + return False + + if(im.format is None): + return False return extension in self.extensions diff --git a/elodie/tests/dependencies_test.py b/elodie/tests/dependencies_test.py index 49dc492d..b26b8660 100644 --- a/elodie/tests/dependencies_test.py +++ b/elodie/tests/dependencies_test.py @@ -3,13 +3,13 @@ from elodie.dependencies import get_exiftool -@mock.patch('elodie.dependencies.find_executable') +@mock.patch('elodie.dependencies.shutil') @mock.patch('elodie.dependencies.os') -def test_exiftool(mock_os, mock_find_executable): - mock_find_executable.return_value = '/path/to/exiftool' +def test_exiftool(mock_os, mock_shutil): + mock_shutil.which.return_value = '/path/to/exiftool' assert get_exiftool() == '/path/to/exiftool' - mock_find_executable.return_value = None + mock_shutil.which.return_value = None mock_os.path.isfile.return_value = True mock_os.path.access.return_value = True assert get_exiftool() == '/usr/local/bin/exiftool' diff --git a/elodie/tests/elodie_test.py b/elodie/tests/elodie_test.py index d03224f2..05de7de5 100644 --- a/elodie/tests/elodie_test.py +++ b/elodie/tests/elodie_test.py @@ -1,5 +1,5 @@ # Project imports -from imp import load_source +import importlib.util import unittest.mock as mock import os import sys @@ -15,7 +15,10 @@ sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))) import helper -elodie = load_source('elodie', os.path.abspath('{}/../../elodie.py'.format(os.path.dirname(os.path.realpath(__file__))))) +elodie_path = os.path.abspath('{}/../../elodie.py'.format(os.path.dirname(os.path.realpath(__file__)))) +spec = importlib.util.spec_from_file_location('elodie', elodie_path) +elodie = importlib.util.module_from_spec(spec) +spec.loader.exec_module(elodie) from elodie.config import load_config from elodie.localstorage import Db diff --git a/elodie/tests/geolocation_test.py b/elodie/tests/geolocation_test.py index e06b5958..966a4110 100644 --- a/elodie/tests/geolocation_test.py +++ b/elodie/tests/geolocation_test.py @@ -2,7 +2,6 @@ from __future__ import division from builtins import range import pytest -from past.utils import old_div # Project imports import unittest.mock as mock import os diff --git a/elodie/tests/helper.py b/elodie/tests/helper.py index bdadc82e..6cab474d 100644 --- a/elodie/tests/helper.py +++ b/elodie/tests/helper.py @@ -1,7 +1,6 @@ from __future__ import division from __future__ import unicode_literals from builtins import range -from past.utils import old_div import hashlib import os import random @@ -98,7 +97,7 @@ def random_decimal(): def random_coordinate(coordinate, precision): # Here we add to the decimal section of the coordinate by a given precision - return coordinate + ((old_div(10.0, (10.0**precision))) * random_decimal()) + return coordinate + (((10.0 / (10.0**precision))) * random_decimal()) def temp_dir(): return tempfile.gettempdir() @@ -116,13 +115,13 @@ def is_windows(): def path_tz_fix(file_name): if is_windows(): # Calculate the offset between UTC and local time - tz_shift = old_div((datetime.fromtimestamp(0) - - datetime.utcfromtimestamp(0)).seconds,3600) + tz_shift = (datetime.fromtimestamp(0) - + datetime.utcfromtimestamp(0)).seconds / 3600 # replace timestamp in file_name - m = re.search('(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})',file_name) + m = re.search(r'(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})',file_name) t_date = datetime.fromtimestamp(time.mktime(time.strptime(m.group(0), '%Y-%m-%d_%H-%M-%S'))) s_date_fix = (t_date-timedelta(hours=tz_shift)).strftime('%Y-%m-%d_%H-%M-%S') - return re.sub('\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}',s_date_fix,file_name) + return re.sub(r'\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}',s_date_fix,file_name) else: return file_name diff --git a/elodie/tests/media/photo_test.py b/elodie/tests/media/photo_test.py index 171b62a4..4b65d9d7 100644 --- a/elodie/tests/media/photo_test.py +++ b/elodie/tests/media/photo_test.py @@ -177,11 +177,6 @@ def test_is_valid_fallback_using_pillow(): assert photo.is_valid() -def test_pillow_not_loaded(): - photo = Photo(helper.get_file('imghdr-error.jpg')) - photo.pillow = None - - assert photo.is_valid() == False def test_set_album(): temporary_folder, folder = helper.create_working_folder() diff --git a/requirements.txt b/requirements.txt index 9ac538e9..c091b72f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,10 @@ click==6.6 -requests==2.20.0 +requests==2.32.5 +urllib3==2.5.0 Send2Trash==1.3.0 future==0.16.0 configparser==3.5.0 -tabulate==0.7.7 +tabulate==0.9.0 Pillow==6.2.2; python_version == '2.7' Pillow==10.4.0; python_version >= '3.6' -six==1.9 +six>=1.16.0