8000 feat: add orjson by daxartio · Pull Request #417 · sportorg/pysport · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add orjson #417

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

Merged
merged 6 commits into from
Aug 28, 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@ cython_debug/
.idea
.vscode

data
data
!tests/data
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,36 @@ poetry run python SportOrg.pyw
### cx_Freeze

`python builder.py build`

## Commit Message Format

This project adheres to [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
A specification for adding human and machine readable meaning to commit messages.

### Commit Message Header

```
<type>(<scope>): <short summary>
│ │ │
│ │ └─⫸ Summary in present tense. Not capitalized. No period at the end.
│ │
│ └─⫸ Commit Scope
└─⫸ Commit Type: feat|fix|build|ci|docs|perf|refactor|test|chore
```

#### Type

| type | name | description |
|----------|--------------------------|--------------------------------------------------------------------------------------------------------|
| feat | Features | A new feature |
| fix | Bug Fixes | A bug fix |
| docs | Documentation | Documentation only changes |
| style | Styles | Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) |
| refactor | Code Refactoring | A code change that neither fixes a bug nor adds a feature |
| perf | Performance Improvements | A code change that improves performance |
| test | Tests | Adding missing tests or correcting existing tests |
| build | Builds | Changes that affect the build system or external dependencies (example scopes: mypy, pip, pytest) |
| ci | Continuous Integrations | Changes to our CI configuration files and scripts (example scopes: Github Actions) |
| chore | Chores | Other changes that don't modify src or test files |
| revert | Reverts | Reverts a previous commit |
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ run:

.PHONY: test
test:
$(POETRY_RUN) pytest --verbosity=2 --showlocals --strict --log-level=DEBUG $(args) --cov
$(POETRY_RUN) pytest --verbosity=2 --showlocals --strict-markers --log-level=DEBUG $(args) --cov

.PHONY: lint
lint:
Expand All @@ -35,4 +35,4 @@ format:

.PHONY: publish
publish:
@poetry publish --build --no-interaction --username=$(pypi_username) --password=$(pypi_password)
@poetry publish --build --no-interaction --username=$(pypi_username) --password=$(pypi_password)
162 changes: 116 additions & 46 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ chardet = "^5.2.0"
docxtpl = "^0"
jinja2 = "^2"
markupsafe = "2.0.1"
orjson = "^3.9.5"
polib = "^1"
pydantic = "^1"
PySide2 = "^5"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ branch = True
[coverage:report]
show_missing = True
skip_covered = True
fail_under = 5
fail_under = 43
2 changes: 1 addition & 1 deletion sportorg/common/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_sounds(path=None):


@singleton
class Audio(object):
class Audio:
def __init__(self):
self._queue = Queue()
self._thread = None
Expand Down
2 changes: 1 addition & 1 deletion sportorg/common/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def subscribe(self, call):


@singleton
class Broker(object):
class Broker:
def __init__(self):
self._consumers = {}
self._logger = logging.root
Expand Down
2 changes: 1 addition & 1 deletion sportorg/common/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Model(object):
class Model:
@classmethod
def create(cls, **kwargs):
o = cls()
Expand Down
3 changes: 2 additions & 1 deletion sportorg/common/otime.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def to_minute_str(self):
def get_msec(day=0, hour=0, minute=0, sec=0, msec=0):
ret = day * 86400000 + hour * 3600000 + minute * 60000 + sec * 1000 + msec
if ret < 0:
# emulation of midnight - add 1 day if time < 0. Note, that now we don't support races > 24h
# emulation of midnight - add 1 day if time < 0.
# Note, that now we don't support races > 24h
# TODO: real day difference, support races > 24h
ret += 86400000
return ret
Expand Down
2 changes: 1 addition & 1 deletion sportorg/common/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def singleton(cls, *args, **kw):
Decorator

>>>@singleton
>>>class SomeClass(object):
>>>class SomeClass:
>>> pass
"""
instances = {}
Expand Down
4 changes: 4 additions & 0 deletions sportorg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,7 @@ def style_dir(*paths):
}

logging.config.dictConfig(LOG_CONFIG)


def get_creator_name() -> str:
return f'{NAME} {VERSION}'
2 changes: 1 addition & 1 deletion sportorg/gui/dialogs/bib_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def apply_changes():
self.show()

def show_person_info(self):
bib_or_name = self.item_bib_or_name.text() # type: str
bib_or_name = self.item_bib_or_name.text()
self.label_person_info.setText('')
person = None
if bib_or_name:
Expand Down
4 changes: 2 additions & 2 deletions sportorg/gui/global_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@singleton
class GlobalAccess(object):
class GlobalAccess:
def __init__(self):
self.app = None

Expand All @@ -19,7 +19,7 @@ def get_main_window(self):


@singleton
class NumberClicker(object):
class NumberClicker:
def __init__(self):
self.key = ''
self.time = time.time()
Expand Down
14 changes: 9 additions & 5 deletions sportorg/gui/menu/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def execute(self):
)
if file_name != '':
try:
iof_xml.export_result_list(file_name)
iof_xml.export_result_list(file_name, creator=config.get_creator_name())
except Exception as e:
logging.exception(e)
QMessageBox.warning(
Expand All @@ -254,7 +254,9 @@ def execute(self):
)
if file_name != '':
try:
iof_xml.export_result_list(file_name, True)
iof_xml.export_result_list(
file_name, creator=config.get_creator_name(), all_splits=True
)
except Exception as e:
logging.exception(e)
QMessageBox.warning(
Expand All @@ -273,7 +275,7 @@ def execute(self):
)
if file_name != '':
try:
iof_xml.export_entry_list(file_name)
iof_xml.export_entry_list(file_name, creator=config.get_creator_name())
except Exception as e:
logging.error(str(e))
QMessageBox.warning(
Expand Down Expand Up @@ -310,7 +312,7 @@ def execute(self):
)
if file_name != '':
try:
iof_xml.export_start_list(file_name)
iof_xml.export_start_list(file_name, creator=config.get_creator_name())
except Exception as e:
logging.exception(str(e))
QMessageBox.warning(
Expand All @@ -331,7 +333,9 @@ def execute(self):
)
if file_name != '':
try:
iof_xml.export_competitor_list(file_name)
iof_xml.export_competitor_list(
file_name, creator=config.get_creator_name()
)
except Exception as e:
logging.exception(str(e))
QMessageBox.warning(
Expand Down
4 changes: 2 additions & 2 deletions sportorg/gui/menu/factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sportorg.gui.menu.actions import ActionFactory


class Factory(object):
class Factory:
def __init__(self, app):
self._actions = {}
for key, cls in ActionFactory.actions.items():
Expand All @@ -10,7 +10,7 @@ def __init__(self, app):
def get_action(self, key):
if key in self._actions:
return self._actions[key]
return lambda: print('...')
return lambda: ...

def execute(self, key):
self.get_action(key)()
26 changes: 13 additions & 13 deletions sportorg/libs/iof/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from lxml.builder import E
from lxml.etree import Element, ElementTree

from sportorg import config
from sportorg.models.memory import Person, Race, ResultStatus
from sportorg.models.memory import Race, ResultStatus
from sportorg.models.result.result_calculation import ResultCalculation


def otime_to_str(race_obj, otime):
"""Convert time to the date string, expressed in ISO 8601 format. Day is taken from settings of race"""
"""
Convert time to the date string, expressed in ISO 8601 format.
Day is taken from settings of race
"""
day = race_obj.data.get_start_datetime()
return day.strftime('%Y-%m-%d') + 'T' + otime.to_str(3)

Expand All @@ -26,7 +28,7 @@ def get_iof_status(status):
return 'Disqualified'


def generate_result_list(obj, all_splits=False):
def generate_result_list(obj, creator: str, all_splits: bool = False):
"""Generate the IOF XML ResultList string from the race data"""

xmlns = 'http://www.orienteering.org/datastandard/3.0'
Expand All @@ -36,7 +38,7 @@ def generate_result_list(obj, all_splits=False):
'{' + xmlns + '}ResultList',
nsmap={'xsi': xsi, None: xmlns},
iofVersion='3.0',
creator=config.NAME + ' ' + str(config.VERSION),
creator=creator,
createTime=datetime.now().strftime('%Y-%m-%dT%H:%M:%S'),
)
xml_rl.append(generate_evant(obj))
Expand All @@ -58,7 +60,6 @@ def generate_result_list(obj, all_splits=False):
person = result.person
organization = person.organization

# generate Result
xml_result = generate_result(obj, result, all_splits)

# compose PersonResult from organization, person and result
Expand Down Expand Up @@ -122,7 +123,7 @@ def generate_result_list(obj, all_splits=False):
return ElementTree(xml_rl)


def generate_entry_list(obj):
def generate_entry_list(obj, creator: str):
"""Generate the IOF XML EntryList string from the race data"""

xmlns = 'http://www.orienteering.org/datastandard/3.0'
Expand All @@ -132,13 +133,12 @@ def generate_entry_list(obj):
'{' + xmlns + '}EntryList',
nsmap={'xsi': xsi, None: xmlns},
iofVersion='3.0',
creator=config.NAME + ' ' + str(config.VERSION),
creator=creator,
createTime=datetime.now().strftime('%Y-%m-%dT%H:%M:%S'),
)
xml_el.append(generate_evant(obj))

for person in obj.persons:
assert isinstance(person, Person)
# Generate PersonEntry objects for each person
organization = person.organization
group = person.group
Expand All @@ -153,7 +153,7 @@ def generate_entry_list(obj):
return ElementTree(xml_el)


def generate_start_list(obj):
def generate_start_list(obj, creator: str):
"""Generate the IOF XML StartList string from the race data"""

if isinstance(obj, Race):
Expand All @@ -164,7 +164,7 @@ def generate_start_list(obj):
'{' + xmlns + '}StartList',
nsmap={'xsi': xsi, None: xmlns},
iofVersion='3.0',
creator=config.NAME + ' ' + str(config.VERSION),
creator=creator,
createTime=datetime.now().strftime('%Y-%m-%dT%H:%M:%S'),
)
xml_sl.append(generate_evant(obj))
Expand Down Expand Up @@ -197,7 +197,7 @@ def generate_start_list(obj):
return ElementTree(xml_sl)


def generate_competitor_list(obj):
def generate_competitor_list(obj, creator: str):
"""Generate the IOF XML CompetitorList string from the race data"""

if isinstance(obj, Race):
Expand All @@ -208,7 +208,7 @@ def generate_competitor_list(obj):
'{' + xmlns + '}CompetitorList',
nsmap={'xsi': xsi, None: xmlns},
iofVersion='3.0',
creator=config.NAME + ' ' + str(config.VERSION),
creator=creator,
createTime=datetime.now().strftime('%Y-%m-%dT%H:%M:%S'),
)
xml_cl.append(generate_evant(obj))
Expand Down
4 changes: 2 additions & 2 deletions sportorg/libs/iof/iof.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def indent(elem, level=0):
elem.tail = i


class BaseElement(object):
class BaseElement:
@abstractmethod
def to_elem(self) -> ET.Element:
pass
Expand Down Expand Up @@ -56,7 +56,7 @@ def write(self, file, **kwargs):
return ET.ElementTree(el).write(file, **kwargs)


class IOF30(object):
class IOF30:
def __init__(self):
self.iof_version = 3.0
self.xmlns = 'http://www.orienteering.org/datastandard/3.0'
Expand Down
2 changes: 1 addition & 1 deletion sportorg/libs/iof/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import xml.etree.ElementTree as ET


class IOFParseResult(object):
class IOFParseResult:
def __init__(self, name, data):
self.name = name
self.data = data
Expand Down
2 changes: 1 addition & 1 deletion sportorg/libs/sfr/sfrreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pywinusb.hid import HidDevice, HidDeviceFilter


class SFRReader(object):
class SFRReader:
SFR_DEBUG = False
SFR_ALLOW_DUPLICATE = False # Don't check card to be new, allow multiple reading of one card - used for debug only
TIMEOUT_STEP = 0.001 # Sleeping step while waiting for command response
Expand Down
Loading
0