Fix pyobjc imports, bump minimum Python version (#1698)

This commit is contained in:
Manu 2023-04-29 12:26:01 +01:00 committed by GitHub
parent 20b7b4936c
commit 4d65912d65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 33 deletions

View File

@ -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 }}

View File

@ -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

View File

@ -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)

View File

@ -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()

View File

@ -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)