Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pyobjc imports, bump minimum Python version #1698

Merged
merged 5 commits into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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 }}

Expand Down
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
39 changes: 21 additions & 18 deletions src/vorta/autostart.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand All @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions src/vorta/keyring/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"""
import logging
import sys
from ctypes import c_char
import objc
from Foundation import NSBundle
from .abc import VortaKeyring

logger = logging.getLogger(__name__)
Expand All @@ -23,8 +26,6 @@ def _set_keychain(self):
"""
Lazy import to avoid conflict with pytest-xdist.
"""
import objc
from Foundation import NSBundle

Security = NSBundle.bundleWithIdentifier_('com.apple.security')

Expand Down Expand Up @@ -121,7 +122,5 @@ def is_system(self):


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()
7 changes: 5 additions & 2 deletions src/vorta/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from PyQt6 import QtCore, QtDBus
from vorta.store.models import SettingsModel

try:
from Foundation import NSUserNotification, NSUserNotificationCenter
except ImportError:
pass

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -50,8 +55,6 @@ def deliver(self, title, text, level='info'):
if self.notifications_suppressed(level):
return

from Foundation import NSUserNotification, NSUserNotificationCenter

notification = NSUserNotification.alloc().init()
notification.setTitle_(title)
notification.setInformativeText_(text)
Expand Down