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

feat: fail import if OS version unsupported #122

Merged
merged 5 commits into from
Feb 2, 2024
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
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
[flake8]
max-line-length = 120
per-file-ignores =
*.py: E203, E501
*.py: E501
src/windows_toasts/__init__.py: E402
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Unversioned
===========
- Importing the module now throws an exception if the Windows version is unsupported (#122)
- Replaced toasts_winrt with winrt-Namespace packages (#113)
- Dropped Python 3.8 support (#113)

Expand Down
4 changes: 3 additions & 1 deletion scripts/publish_gh_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def main(argv):
print("tag_name not given and $GITHUB_REF not set", file=sys.stderr)
return 1
if tag_name.startswith("refs/tags/"):
tag_name = tag_name[len("refs/tags/") :]
# fmt: off
tag_name = tag_name[len("refs/tags/"):]
# fmt: on

token = os.environ.get("GH_RELEASE_NOTES_TOKEN")
if not token:
Expand Down
12 changes: 12 additions & 0 deletions src/windows_toasts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import platform

from .exceptions import UnsupportedOSVersionException

# We'll assume it's Windows since if it's on another OS it should be self-explanatory
MIN_VERSION = 10240
if platform.system() == "Windows" and (osVersion := int(platform.version().split(".")[2])) < MIN_VERSION:
DatGuy1 marked this conversation as resolved.
Show resolved Hide resolved
raise UnsupportedOSVersionException(
f"Platform version {osVersion} is not supported. Required minimum is {MIN_VERSION}"
)

from ._version import __author__, __description__, __license__, __title__, __url__, __version__ # noqa: F401
from .events import ToastActivatedEventArgs, ToastDismissalReason, ToastDismissedEventArgs, ToastFailedEventArgs
from .exceptions import InvalidImageException, ToastNotFoundError
Expand Down Expand Up @@ -36,6 +47,7 @@
# exceptions.py
"InvalidImageException",
"ToastNotFoundError",
"UnsupportedOSVersionException",
# toast_audio.py
"AudioSource",
"ToastAudio",
Expand Down
4 changes: 4 additions & 0 deletions src/windows_toasts/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ class InvalidImageException(Exception):

class ToastNotFoundError(Exception):
"""The toast could not be found"""


class UnsupportedOSVersionException(ImportError):
"""The operating system version is not supported"""
17 changes: 17 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from unittest.mock import patch

from pytest import raises


# noinspection PyUnresolvedReferences
def test_import_current():
import importlib

# Successful import
import src.windows_toasts

# 6.1.7601 = Windows 7
with patch("platform.version", return_value="6.1.7601"):
with raises(src.windows_toasts.UnsupportedOSVersionException):
# Reload
importlib.reload(src.windows_toasts)
4 changes: 2 additions & 2 deletions tests/test_toasts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import copy

from pytest import raises, warns

from src.windows_toasts import InteractableWindowsToaster, Toast, WindowsToaster
Expand Down Expand Up @@ -150,6 +148,8 @@ def test_custom_timestamp_toast():


def test_input_toast():
import copy

from src.windows_toasts import ToastInputSelectionBox, ToastInputTextBox, ToastSelection

toastTextBoxInput = ToastInputTextBox("question", "How are you today?", "Enter here!")
Expand Down
Loading