Releases: aatle/pyriak
Releases · aatle/pyriak
0.5.0
Many API changes to simplify the framework.
Fixes
- Changed
Entity()constructor to use add behavior with initial components, instead of update behavior - error on duplicates
API Updates
- New tag components feature. Use component classes marked with
@tagdecorator to dynamically filter queries more- Added
tagandtagskeyword parameters toEntityManager.query() - Added
EntityManagertagged()andtagged_ids()methods - Component events will also give the component itself as an event key, if the component is a tag
QueryResultinstances have a read-onlytagsattribute- New
tag_componentmodule withtag_types(WeakSet) andtag(decorator)
- Added
space.query()removed. Usespace.entities.query()instead- Removed event skip functionality of handler callbacks
- Callback return value is now ignored
process()methods returnNoneinstead of abool
- Systems now should be modules (type
ModuleType) - Key handlers are now invoked with separate priority sorting from non-key handlers, to avoid the need for sorting
- Renamed
pyriak.eventkeymodule topyriak.event_key set_key()now has another available overload with 2 arguments, to set key functions directly without using as a decoratorspace.post()now only takes one argument, instead of a variable numberkey_functionsis now a directWeakKeyDictionary, typed as aMapping- Removed
EventKeyFunctionsclass
- Removed
Internal
_EventHandlernow supports rich comparison by priority, for native sorting capability onlyEntityManagernow stores and maintains a_tag_cache- Removed
SystemManagerhandler sorting methods and features - Simplified
EntityManageradd()andremove() - Simplified
space.pump() - Greatly simplified
SystemManager._get_bindings() - Rearranged order of attributes of
_EventHandler - Use
repr()formatting instead ofstr()formatting in error message f-strings for types - Added
ISC001ruff rule
Typing
- Removed some unused
type: ignorecomments _CallbackandBindingare no longer generic on the callback return type
Other
- Improved README
- Updated docstrings
- Changed formatting of docstring code examples
- License year range updated
0.4.2
More QOL improvements and an important bug fix.
Fixes
- Fixed major problems in system unbinding (when using
SystemManager.remove()) and improved performance - Fixed possible
RecursionErrorinEntity.__repr__()
API Updates
- New constant
NULL_ID: anEntityIdthat is never in theEntityManager - Added
discard()method toEntityManager,Entity, andStateManager - All built-in events are now dataclasses. Adds
__eq__and__repr__, and they are no longer hashable. - Added
__repr__()toEntityManager,SystemManager,StateManager,Binding, andQueryResult - Added
__eq__()toEntityManager,SystemManager,StateManager, andEventKeyFunctions- These types are no longer hashable
- Some methods of
EventKeyFunctionsno longer accept keyword arguments EventKeyFunctions.copy()returns anEventKeyFunctionsinstead ofWeakKeyDictionary
Typing
- Typing improvements, especially by annotating return type of dunder methods
- Fixed problem when using
dict()onEventKeyFunctions - Some internal variables marked with
Final - Implementations of overloaded methods are now also typed
Internal
- Formatted all code with standard conventions
- Rewrote
SystemManager._bind()
Other
- Rewrote README
- Added docstring for
QueryResult.__call__() - Added more mypy and ruff checks
0.4.1
This release features more API improvements and changes (based on observed pyriak usage), and also improved package documentation.
API Updates
tagclass()function removed- All
add()methods (Entity,StateManager,SystemManager,EntityManager) raiseValueErrorif the object has already been added- New
update()method that retains original behavior ofadd(): remove old object if not equal to new object
- New
- Added
__setitem__method toEntityandStateManagerthat has the behavior ofupdate() ComponentRemovedandEventHandlerRemovedevents are posted beforeEntityRemovedandSystemRemovedinstead of after- Raise a
ValueErrorinstead ofKeyErrorin some places bind()decorator will now raiseTypeErrorinstead ofValueErrorwhen keys are given for an event type with no key function
Typing
- The component, state, and event handler event types are now generic in their component/state/event type (invariant).
- The generic callback return type of
Bindingis now covariant instead of invariant - Generic event type of
Bindingintegrated into type of_event_type_attribute (type->type[_T]) - Removed unneeded field annotation in
SystemManager
Internal
_EventHandlercall only accepts(space, event)arguments instead of(*args, **kwargs)_EventHandleris now generic in its event type- Event handler events post after they are bound/unbound instead of before
- Removed redundant, unused type variables in top-level module
Other
- Rewrote
README.mdfile:- More formal and useful, added many sections
- Provides a guide on basic usage
- Badges for important info
- Removed the TODO list
- Improved PyPI package details: added PyPI classifiers and keywords
- Added more mypy checks/rules
- Updated docstrings of various things
0.4.0
pyriak has undergone some more massive changes.
However, the general API is likely to be more stable in the future.
API Updates
- Subtype polymorphism completely removed (from components, states, and events/handlers)
subclasses()andstrict_subclasses()functions removed- Removed
__call__functionality fromEntityandStateManager - Use
__call__instead of__getitem__forEntityManager.componentsandQueryResult key_functions(EventKeyFunctions) acts more like normal dict, removedexists()and__call__methods
bind()can no longer be applied multiple times on one object/callbackBindingclass removed,BindingWrapperrenamed toBinding- Renamed
Bindingclass contains binding info directly:_event_type_,_callback_,_priority_,_keys_
managerssubpackage removed/flattened: all manager files are in top-level package- manager files renamed to have underscore before "manager" for readability
first()function removed (as there are better ways to do things)key_functions(EventKeyFunctions) values can no longer beNone- Custom
__repr__()method added toEntity __weakref__slot removed fromEntity: entities are no longer weakly referenceable- Removed
__setitem__functionality fromEntityandStateManager Entity/StateManagerwhen removing by value, events contain original object instead of given oneprocess()andpump()have positional-only argumentsSystemManager.process()raisesRuntimeErrorinstead ofTypeErrorwhen its space isNone
Typing
- Removed overloads and return
Anytypes inQueryResultto fix typing issues forzip(),zip_entity() bind()annotated return type is no longer_Decoratorprotocol type (multibinding removed)clear()methods return type explicitly annotated withNone
Internal
- With no subtype polymorphism, greatly simplified source code
SystemManager._get_bindings()returnslist[tuple[Binding, _EventHandler]]- Removed
SystemManager_lazy_bind()and_lazy_key_bind()methods - Reduced code size for many methods
- EventHandler events have base
_EventHandlerEvent, and uses both binding and handler objects
EntityManager._component_typesrenamed to_type_cacheSystemManager._get_handlers()always returns a new list of handlers_Componentsclass now has__init__()method- All internal
type: ignorecomments have error codes QueryResult__iter__no longer set toNonespacemodule directly imports manager classes- Small optimizations for query methods
- Line length limit lowered from 90 to 88 (88 is default in Ruff)
- Ruff target version is no longer set to
py311- Ignore rule "PERF203"
- TODO list updated
Other
- Added and updated docstrings for almost entire API (google style)
- Removed upper python limit "<4.0"
- Overall, improved performance and memory usage
0.3.1
API Updates
- Querying overhauled:
- Removed
Queryclass - Removed
SpaceandEntityManagermethodsentity_query(),id_query()QueryResultis the only query result class
- New
QueryResultmethod.zip_entity() - Removed
query.py,QueryResultmoved toentitymanager.py
- Removed
system.pyrenamed tobind.pySystemtype alias moved to top-level module
- Removed built-in event
SpaceCallbackSystemManagerno longer postsSpaceCallbackfor system add/remove when no space available
- Removed built-in event
SendEvent SystemManager.process()method no longer takes optionalspaceargumenttagclass()now returns a new class instead of mutating the argumenttagclass()class instances are only equal if their types the same object, instead of subclasses- Removed
tagclass()overload that created a new class from scratch liketype()
Typing
- Fixed typing issue when using
bind()multiple times on one event handler BindingWrapper.__callback__andBindingWrapper.__call__()now have narrower type/signaturepyriak__all__list now includesEventQueuetype aliasentity.py__all__list now includesEntityIdQueryResultentitiesandtypesproperties have more abstract types- Typed
Space.process()as returningbool
Internal
EntityManagerandEntityquery cache updates restructuredbind()reuses a dedicated emptyfrozensetwhen no keys are givenSpace.__init__()constructor assigns in a different order
Other
- Added license as a code comment to top-level module
- Added module docstring, package description, to top-level module
- Improved error message when a duplicate event type is bound to an event handler
0.3.0
API Updates
Systemand_SystemInfoclasses removed._system_ = System()is no longer used- Any hashable object is now a valid
System, including classes. (Previously, only modules with_system_attribute were valid). Systemis now a TypeAlias forHashable- pyriak no longer hooks into import system,
_importer.pyremoved _BindingWrapperis nowBindingWrapper, and is no longer a temporary object on systems, refactored_Bindingclass is now a namedtupleBinding, and includesevent_type- system event handler bindings are now a
tupleinstead of aMappingProxy - query() methods raise
TypeErrorinstead ofValueErrorwhen no component types given
Typing
- Typecasting into
Systemis no longer necessary on most type checkers - Removed
NoReturnoverloads from query methods and class - Typed
QueryResult - Added mypy configuration in
pyproject.toml - Fixed
_SENTINELtyping issue and other issues
Other
- Created github workflow for publishing
- Updated README
0.2.0
API Updates
- Removed
mro()function - Removed
Callbackclass - Removed
NoKey,NoKeyType - Added
first()function to serve as a merge function - Added
strict_subclasses()function __setitem__ofStateManagerandEntitynow only pop at most one state/componentSystemManagerno longer possibly getsevent_queuefrom itsspaceSpace.event_queueis no longer a property that automatically sets the managers event queues- Multikeys from key functions now must be any iterator
Typing
- Added
py.typedfile, making package type annotations public - Events now typed with
objectinstead ofAny objectnow used in place of someAnyoccurrences- Type hinted
SpaceCallback - Added overloads to
get()andpop()methods to improve typing bind()now preserves return type of event handler callback- Generally improved typing, successful mypy check
Internal
SystemManagernow has separate collections for keyed and unkeyed handlers- Renamed
SystemManager._sorted_handlers()to_sort_handlers() - Increased performance of polymorphism-related
__getitem__()andget()methods - Rewrote internal imports to be more direct
- Removed internal
_EventHandlerEventbase class - Various default values now use internal
_SENTINELobject, orNone, instead ofEllipsis
Other
- Updated README
- Added dev dependencies
ruffandmypytopyproject.toml