Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Add 3.11 to the supported versions, remove 3.7 #162

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 12 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v1

- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox==3.15.1 tox-gh-actions==1.2.0 pipenv==2020.6.2
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox==3.28.0 tox-poetry==0.5.0 tox-gh-actions==2.12.0 poetry==1.3.2

- name: Tests
run: tox
- name: Tests
run: tox
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:3.7-alpine3.8
FROM python:3.11.1-slim

RUN pip install python-shortcuts==0.10.0
RUN pip install python-shortcuts==0.11.0

ENTRYPOINT ["shortcuts"]
21 changes: 0 additions & 21 deletions Pipfile

This file was deleted.

458 changes: 0 additions & 458 deletions Pipfile.lock

This file was deleted.

790 changes: 790 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions shortcuts.py

This file was deleted.

103 changes: 51 additions & 52 deletions shortcuts/shortcut.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import plistlib
import uuid
from typing import Any, BinaryIO, Dict, List, Type

Expand All @@ -12,16 +11,16 @@

logger = logging.getLogger(__name__)

FMT_TOML = 'toml'
FMT_SHORTCUT = 'shortcut'
FMT_TOML = "toml"
FMT_SHORTCUT = "shortcut"


class Shortcut:
def __init__(
self,
name: str = '',
client_release: str = '2.0',
client_version: str = '700',
name: str = "",
client_release: str = "2.0",
client_version: str = "700",
minimal_client_version: int = 411,
actions: List = None,
) -> None:
Expand All @@ -32,25 +31,25 @@ def __init__(
self.actions = actions if actions else []

@classmethod
def load(cls, file_object: BinaryIO, file_format: str = FMT_TOML) -> 'Shortcut':
'''
def load(cls, file_object: BinaryIO, file_format: str = FMT_TOML) -> "Shortcut":
"""
Returns a Shortcut instance from given file_object

Params:
file_object (BinaryIO)
file_format: format of the string, FMT_TOML by default
'''
"""
return cls._get_loader_class(file_format).load(file_object)

@classmethod
def loads(cls, string: str, file_format: str = FMT_TOML) -> 'Shortcut':
'''
def loads(cls, string: str, file_format: str = FMT_TOML) -> "Shortcut":
"""
Returns a Shortcut instance from given string

Params:
string: representation of a shortcut in string
file_format: format of the string, FMT_TOML by default
'''
"""
return cls._get_loader_class(file_format).loads(string)

@classmethod
Expand All @@ -61,28 +60,28 @@ def _get_loader_class(self, file_format: str) -> Type[BaseLoader]:
FMT_TOML: TomlLoader,
}
if file_format in supported_formats:
logger.debug(f'Loading shortcut from file format: {file_format}')
logger.debug(f"Loading shortcut from file format: {file_format}")
return supported_formats[file_format]

raise RuntimeError(f'Unknown file_format: {file_format}')
raise RuntimeError(f"Unknown file_format: {file_format}")

def dump(self, file_object: BinaryIO, file_format: str = FMT_TOML) -> None:
'''
"""
Dumps the shortcut instance to file_object

Params:
file_object (BinaryIO)
file_format: format of the string, FMT_TOML by default
'''
"""
self._get_dumper_class(file_format)(shortcut=self).dump(file_object)

def dumps(self, file_format: str = FMT_TOML) -> str:
'''
"""
Dumps the shortcut instance and returns a string representation

Params:
file_format: format of the string, FMT_TOML by default
'''
"""
return self._get_dumper_class(file_format)(shortcut=self).dumps()

def _get_dumper_class(self, file_format: str) -> Type[BaseDumper]:
Expand All @@ -92,10 +91,10 @@ def _get_dumper_class(self, file_format: str) -> Type[BaseDumper]:
FMT_TOML: TomlDumper,
}
if file_format in supported_formats:
logger.debug(f'Dumping shortcut to file format: {file_format}')
logger.debug(f"Dumping shortcut to file format: {file_format}")
return supported_formats[file_format]

raise RuntimeError(f'Unknown file_format: {file_format}')
raise RuntimeError(f"Unknown file_format: {file_format}")

def _get_actions(self) -> List[str]:
"""returns list of all actions"""
Expand All @@ -115,30 +114,30 @@ def _set_group_ids(self):
ids = []
for action in self.actions:
# if action has GroupIDField, we may need to generate it's value automatically
if not isinstance(getattr(action, 'group_id', None), GroupIDField):
if not isinstance(getattr(action, "group_id", None), GroupIDField):
continue

control_mode = action.default_fields['WFControlFlowMode']
control_mode = action.default_fields["WFControlFlowMode"]
if control_mode == 0:
# 0 means beginning of the group
group_id = action.data.get('group_id', str(uuid.uuid4()))
action.data['group_id'] = group_id # if wasn't defined
group_id = action.data.get("group_id", str(uuid.uuid4()))
action.data["group_id"] = group_id # if wasn't defined
ids.append(group_id)
elif control_mode == 1:
# 1 - else, so we don't need to remove group_id from the stack
# we need to just use the latest one
action.data['group_id'] = ids[-1]
action.data["group_id"] = ids[-1]
elif control_mode == 2:
# end of the group, we must remove group_id
try:
action.data['group_id'] = ids.pop()
action.data["group_id"] = ids.pop()
except IndexError:
# if actions are correct, all groups must be compelted
# (group complete if it has start and end actions)
raise exceptions.IncompleteCycleError('Incomplete cycle')
raise exceptions.IncompleteCycleError("Incomplete cycle")

def _set_menu_items(self):
'''
"""
Menu consists of many items:
start menu
menu item 1
Expand All @@ -149,19 +148,19 @@ def _set_menu_items(self):
about them to a corresponding "start menu" action.

# todo: move to menu item logic
'''
"""
menus = []
for action in self.actions:
if isinstance(action, MenuStartAction):
action.data['menu_items'] = []
action.data["menu_items"] = []
menus.append(action)
elif isinstance(action, MenuItemAction):
menus[-1].data['menu_items'].append(action.data['title'])
menus[-1].data["menu_items"].append(action.data["title"])
elif isinstance(action, MenuEndAction):
try:
menus.pop()
except IndexError:
raise exceptions.IncompleteCycleError('Incomplete menu cycle')
raise exceptions.IncompleteCycleError("Incomplete menu cycle")

def _get_import_questions(self) -> List:
# todo: change me
Expand All @@ -170,29 +169,29 @@ def _get_import_questions(self) -> List:
def _get_icon(self) -> Dict[str, Any]:
# todo: change me
return {
'WFWorkflowIconGlyphNumber': 59511,
'WFWorkflowIconImageData': plistlib.Data(b''),
'WFWorkflowIconStartColor': 431817727,
"WFWorkflowIconGlyphNumber": 59511,
"WFWorkflowIconImageData": b"",
"WFWorkflowIconStartColor": 431817727,
}

def _get_input_content_item_classes(self) -> List[str]:
# todo: change me
return [
'WFAppStoreAppContentItem',
'WFArticleContentItem',
'WFContactContentItem',
'WFDateContentItem',
'WFEmailAddressContentItem',
'WFGenericFileContentItem',
'WFImageContentItem',
'WFiTunesProductContentItem',
'WFLocationContentItem',
'WFDCMapsLinkContentItem',
'WFAVAssetContentItem',
'WFPDFContentItem',
'WFPhoneNumberContentItem',
'WFRichTextContentItem',
'WFSafariWebPageContentItem',
'WFStringContentItem',
'WFURLContentItem',
"WFAppStoreAppContentItem",
"WFArticleContentItem",
"WFContactContentItem",
"WFDateContentItem",
"WFEmailAddressContentItem",
"WFGenericFileContentItem",
"WFImageContentItem",
"WFiTunesProductContentItem",
"WFLocationContentItem",
"WFDCMapsLinkContentItem",
"WFAVAssetContentItem",
"WFPDFContentItem",
"WFPhoneNumberContentItem",
"WFRichTextContentItem",
"WFSafariWebPageContentItem",
"WFStringContentItem",
"WFURLContentItem",
]
14 changes: 6 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
[tox]
envlist = black,flake8,mypy,py37,py36,py38
envlist = black,flake8,mypy,py311,py310,py39,py38
skipsdist = True

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38, mypy, flake8, black
3.8: py38
3.9: py39
3.10: py310
3.11: py311, mypy, flake8, black

[testenv]
whitelist_externals = pipenv
install_command = pipenv update {opts} {packages}
deps = --dev
commands = pytest --cov=shortcuts {posargs}
commands = pytest --cov=shortcuts

[testenv:flake8]
commands = flake8 shortcuts
Expand Down