From 4d65912d65e18e71462a03e903f6eb71c0edf9bd Mon Sep 17 00:00:00 2001 From: Manu <3916435+m3nu@users.noreply.github.com> Date: Sat, 29 Apr 2023 12:26:01 +0100 Subject: [PATCH] Fix pyobjc imports, bump minimum Python version (#1698) --- .github/workflows/test.yml | 10 +++++----- setup.cfg | 8 ++++---- src/vorta/autostart.py | 39 ++++++++++++++++++++----------------- src/vorta/keyring/darwin.py | 7 +++---- src/vorta/notifications.py | 7 +++++-- 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 53c5bd9a..ac5a0dd9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,10 +16,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Python 3.8 - uses: actions/setup-python@2c3dd9e7e29afd70cc0950079bde6c979d1f69f9 # v4.3.1 + - name: Set up Python 3.11 + uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.11 - name: Install Vorta run: | pip install . @@ -37,13 +37,13 @@ jobs: fail-fast: false matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11'] os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@2c3dd9e7e29afd70cc0950079bde6c979d1f69f9 # v4.3.1 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} diff --git a/setup.cfg b/setup.cfg index c2c92037..76187557 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ packages = find: package_dir = =src include_package_data = true -python_requires = >=3.7 +python_requires = >=3.8 install_requires = platformdirs >=3.0.0, <4.0.0; sys_platform == 'darwin' # for macOS: breaking changes in 3.0.0, platformdirs >=2.6.0, <4.0.0; sys_platform != 'darwin' # for others: 2.6+ works consistently. @@ -44,9 +44,9 @@ install_requires = psutil setuptools secretstorage; sys_platform != 'darwin' - pyobjc-core < 9.1; sys_platform == 'darwin' - pyobjc-framework-Cocoa < 9.1; sys_platform == 'darwin' - pyobjc-framework-LaunchServices < 9.1; sys_platform == 'darwin' + pyobjc-core < 10; sys_platform == 'darwin' + pyobjc-framework-Cocoa < 10; sys_platform == 'darwin' + pyobjc-framework-LaunchServices < 10; sys_platform == 'darwin' tests_require = pytest pytest-qt diff --git a/src/vorta/autostart.py b/src/vorta/autostart.py index bd1c2273..6e0f5d92 100644 --- a/src/vorta/autostart.py +++ b/src/vorta/autostart.py @@ -1,5 +1,25 @@ import sys +try: + from Cocoa import NSURL, NSBundle + from CoreFoundation import kCFAllocatorDefault + from Foundation import NSDictionary + from LaunchServices import ( + LSSharedFileListCopySnapshot, + LSSharedFileListCreate, + LSSharedFileListInsertItemURL, + LSSharedFileListItemRemove, + LSSharedFileListItemResolve, + kLSSharedFileListItemHidden, + kLSSharedFileListItemLast, + kLSSharedFileListNoUserInteraction, + kLSSharedFileListSessionLoginItems, + ) + + APP_PATH = NSBundle.mainBundle().bundlePath() +except ImportError: + pass + AUTOSTART_DELAY = """StartupNotify=false X-GNOME-Autostart-enabled=true X-GNOME-Autostart-Delay=20""" @@ -11,25 +31,8 @@ def open_app_at_startup(enabled=True): while on Linux it adds a .desktop file at ~/.config/autostart """ if sys.platform == 'darwin': - from Cocoa import NSURL, NSBundle - from CoreFoundation import kCFAllocatorDefault - from Foundation import NSDictionary - # CF = CDLL(find_library('CoreFoundation')) - from LaunchServices import ( - LSSharedFileListCopySnapshot, - LSSharedFileListCreate, - LSSharedFileListInsertItemURL, - LSSharedFileListItemRemove, - LSSharedFileListItemResolve, - kLSSharedFileListItemHidden, - kLSSharedFileListItemLast, - kLSSharedFileListNoUserInteraction, - kLSSharedFileListSessionLoginItems, - ) - - app_path = NSBundle.mainBundle().bundlePath() - url = NSURL.alloc().initFileURLWithPath_(app_path) + url = NSURL.alloc().initFileURLWithPath_(APP_PATH) login_items = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None) props = NSDictionary.dictionaryWithObject_forKey_(True, kLSSharedFileListItemHidden) diff --git a/src/vorta/keyring/darwin.py b/src/vorta/keyring/darwin.py index d0f52a3c..91f93610 100644 --- a/src/vorta/keyring/darwin.py +++ b/src/vorta/keyring/darwin.py @@ -9,6 +9,9 @@ Adapted from https://gist.github.com/apettinen/5dc7bf1f6a07d148b2075725db6b1950 """ import logging import sys +from ctypes import c_char +import objc +from Foundation import NSBundle from .abc import VortaKeyring logger = logging.getLogger(__name__) @@ -23,8 +26,6 @@ class VortaDarwinKeyring(VortaKeyring): """ Lazy import to avoid conflict with pytest-xdist. """ - import objc - from Foundation import NSBundle Security = NSBundle.bundleWithIdentifier_('com.apple.security') @@ -121,7 +122,5 @@ class VortaDarwinKeyring(VortaKeyring): def _resolve_password(password_length, password_buffer): - from ctypes import c_char - s = (c_char * password_length).from_address(password_buffer.__pointer__)[:] return s.decode() diff --git a/src/vorta/notifications.py b/src/vorta/notifications.py index 320f1e3e..8141951e 100644 --- a/src/vorta/notifications.py +++ b/src/vorta/notifications.py @@ -3,6 +3,11 @@ import sys from PyQt6 import QtCore, QtDBus from vorta.store.models import SettingsModel +try: + from Foundation import NSUserNotification, NSUserNotificationCenter +except ImportError: + pass + logger = logging.getLogger(__name__) @@ -50,8 +55,6 @@ class DarwinNotifications(VortaNotifications): if self.notifications_suppressed(level): return - from Foundation import NSUserNotification, NSUserNotificationCenter - notification = NSUserNotification.alloc().init() notification.setTitle_(title) notification.setInformativeText_(text)