cooptools 1.79__tar.gz → 1.80__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cooptools-1.79 → cooptools-1.80}/PKG-INFO +1 -1
- {cooptools-1.79 → cooptools-1.80}/cooptools/commandDesignPattern/commandController.py +30 -12
- {cooptools-1.79 → cooptools-1.80}/cooptools.egg-info/PKG-INFO +1 -1
- {cooptools-1.79 → cooptools-1.80}/setup.py +1 -1
- {cooptools-1.79 → cooptools-1.80}/tests/test_commandDesignPattern.py +58 -1
- {cooptools-1.79 → cooptools-1.80}/MANIFEST.in +0 -0
- {cooptools-1.79 → cooptools-1.80}/README.md +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/anchor.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/asyncable.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/cli/CliAtomicUserInteraction.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/cli/CliMenu.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/cli/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/cli/fileContentReturn.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/cnxn_info.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/colors.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/commandDesignPattern/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/commandDesignPattern/commandProtocol.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/commandDesignPattern/exceptions.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/common.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/config.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/coopDataclass.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/coopEnum.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/coopthreading.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/currency.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/dataRefresher/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/dataRefresher/dataHub.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/dataRefresher/dataRefresher.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/dataStore/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/dataStore/dataProcessor.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/dataStore/dataStoreProtocol.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/dataStore/dbConnectionURI.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/dataStore/inMemoryDataStore.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/date_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/decay.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/decor.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/dictPolicies.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/exceptions.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/expertise/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/expertise/expertiseArgs.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/expertise/expertiseSchedules.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/expertise/expertise_state.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/finance/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/finance/dicounted_cashflow_analysis.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/finance/fund_projection.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/finance/fund_projection_renderer.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/finance/futureValueProjector.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/finance/growth_projections.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/finance/reports.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/finance/utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/circle_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/common.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/curve_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/curves.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/line_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/polygon_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/rect_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/triangle_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/geometry_utils/vector_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/graphs/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/graphs/astar_results_viewer.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/graphs/draw.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/graphs/flow_field.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/graphs/graph.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/graphs/graph_dcs.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/graphs/graph_definitions.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/graphs/utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/actionItemTracker/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/actionItemTracker/ai_tracker.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/actionItemTracker/dcs.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/discreteEventSimulator/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/discreteEventSimulator/discreteEventSimulator.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/jsonIO.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/metrics.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/triggerActionSystem/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/triggerActionSystem/signal.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/ideas/triggerActionSystem/trigger.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/loggingHelpers.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/marchingSquares.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/materialHandling/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/materialHandling/cli.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/materialHandling/dcs.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/materialHandling/selectionCriteria.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/matrixManipulation.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/os_manip.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pandasHelpers.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/catmullRomFollower.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/demo/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/demo/server.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/kinematicGoalSeeker.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/motion_profile_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/orbit_fuzzer.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/path_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/straightLineFollower.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/trajectory_provider.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/waypoint.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/pathing/waypointFollower.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/persistence/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/persistence/enum_state.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/persistence/stateful.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/physics/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/physics/kinematic.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/physics/kinematic_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/physics/movement.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/physics/trajectory.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/plotting.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/printing.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/protocols.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/qualifiers/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/qualifiers/cli.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/qualifiers/qualifier.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/randoms.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/register.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/reservation/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/reservation/dcs.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/reservation/enums.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/reservation/reservationmanager.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/retry.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/grids/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/grids/gridState.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/grids/grid_base.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/grids/hexGrid.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/grids/rectGrid.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/hex_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/sect_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/sectorTree/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/sectors/sectorTree/sectorTree.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/statistics/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/statistics/activityReport.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/statistics/controlChart/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/statistics/controlChart/controlChart.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/statistics/controlChart/plotting.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/statistics/oee/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/statistics/oee/oeeHub.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/taskProcessing/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/taskProcessing/dcs.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/taskProcessing/taskProcessor.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/timeTracker/__init__.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/timeTracker/decay.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/timeTracker/timeTracker.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/timeWindow.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/toggles.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/transform.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/trends.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/typeProviders.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/typevalidation.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools/version.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools.egg-info/SOURCES.txt +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools.egg-info/dependency_links.txt +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools.egg-info/not-zip-safe +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools.egg-info/requires.txt +0 -0
- {cooptools-1.79 → cooptools-1.80}/cooptools.egg-info/top_level.txt +0 -0
- {cooptools-1.79 → cooptools-1.80}/requirements.txt +0 -0
- {cooptools-1.79 → cooptools-1.80}/setup.cfg +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_CliAtomicUserInteraction.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_asyncable.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_catmullRomFollower.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_cdp_bugs.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_common.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_config.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_coopEnum.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_currency.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_curves.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_date_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_expertise_state.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_flow_field.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_flow_field_perf.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_fund_projection.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_graph_node_classification.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_kinematicGoalSeeker.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_kinematic_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_os_manip.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_pandas.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_path_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_persistence.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_printing.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_qualifiers.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_sectors.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_sectors_hex.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_sectors_sectorTree.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_statistics.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_straightLineFollower.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_target_seek.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_tasks.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_toggles.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_trajectory.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_trends.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_typevalidation.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_vector_utils.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_version.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/test_waypointFollower.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/tests_graph.py +0 -0
- {cooptools-1.79 → cooptools-1.80}/tests/tests_gridsystem.py +0 -0
|
@@ -11,6 +11,13 @@ logger = logging.getLogger(__name__)
|
|
|
11
11
|
|
|
12
12
|
T = TypeVar('T')
|
|
13
13
|
|
|
14
|
+
|
|
15
|
+
def share_state(state: T) -> T:
|
|
16
|
+
"""A `copy_state` for controllers whose commands always return a new state and
|
|
17
|
+
never modify the one they are given. Snapshots then cost nothing, because an old
|
|
18
|
+
state can never change underneath the reference kept to it."""
|
|
19
|
+
return state
|
|
20
|
+
|
|
14
21
|
class CommandStore(Protocol):
|
|
15
22
|
def __init__(self, reset_state: bool = False):
|
|
16
23
|
if reset_state:
|
|
@@ -99,9 +106,15 @@ class InMemoryCommandStore(CommandStore):
|
|
|
99
106
|
|
|
100
107
|
@dataclass
|
|
101
108
|
class CommandController:
|
|
109
|
+
"""`copy_state` takes every snapshot the controller keeps: the initial state, the
|
|
110
|
+
rollback point before a batch, cached states, and the starting point of a replay.
|
|
111
|
+
It defaults to a deep copy, which is required when commands modify state in place.
|
|
112
|
+
Pass `share_state` when commands return new state instead; with large or frequently
|
|
113
|
+
changed state the deep copies otherwise dominate the cost of `execute`."""
|
|
102
114
|
init_state: T = None
|
|
103
115
|
cache_interval: int = 100
|
|
104
116
|
command_store: CommandStore = field(default_factory=InMemoryCommandStore)
|
|
117
|
+
copy_state: Callable[[T], T] = copy.deepcopy
|
|
105
118
|
cursor: int = field(default=0, init=False)
|
|
106
119
|
_lock: threading.RLock = field(default_factory=threading.RLock, init=False)
|
|
107
120
|
_live_state: T = field(default=None, init=False)
|
|
@@ -117,15 +130,16 @@ class CommandController:
|
|
|
117
130
|
raise ValueError(f"The init state must be set for command stores that have not been initialized")
|
|
118
131
|
|
|
119
132
|
if not has_init and self.init_state is not None:
|
|
120
|
-
self._live_state =
|
|
121
|
-
self.command_store.add_cached(
|
|
133
|
+
self._live_state = self.copy_state(self.init_state)
|
|
134
|
+
self.command_store.add_cached(self.copy_state(self._live_state), self.cursor)
|
|
122
135
|
else:
|
|
123
136
|
# the cursor has to land before the resolve, because resolve() replays up to it; a store
|
|
124
137
|
# restored from persistence otherwise resolves at 0 and hands back the (absent) init state
|
|
125
138
|
self.cursor = len(self.command_store.get_commands(start_cursor=idx)) + idx
|
|
126
139
|
self._live_state = self.resolve()
|
|
127
140
|
|
|
128
|
-
logger.
|
|
141
|
+
if logger.isEnabledFor(logging.INFO):
|
|
142
|
+
logger.info(f"Init State: {pprint.pformat(self._live_state)}")
|
|
129
143
|
|
|
130
144
|
def _needsLock(foo):
|
|
131
145
|
def magic(self, *args, **kwargs):
|
|
@@ -148,10 +162,11 @@ class CommandController:
|
|
|
148
162
|
self.command_store.remove_cached_at_cursor(ii)
|
|
149
163
|
|
|
150
164
|
# snapshot for atomic rollback on failure
|
|
151
|
-
pre_batch_state =
|
|
165
|
+
pre_batch_state = self.copy_state(self._live_state)
|
|
152
166
|
pre_batch_cursor = self.cursor
|
|
153
167
|
|
|
154
|
-
logger.
|
|
168
|
+
if logger.isEnabledFor(logging.INFO):
|
|
169
|
+
logger.info(f"Executing commands {pprint.pformat(commands)} [idx: {self.cursor}]")
|
|
155
170
|
|
|
156
171
|
command = None
|
|
157
172
|
try:
|
|
@@ -170,7 +185,7 @@ class CommandController:
|
|
|
170
185
|
cached_cursors = self.command_store.get_cached().keys()
|
|
171
186
|
last_cached_cursor = max(cached_cursors) if cached_cursors else 0
|
|
172
187
|
if self.cursor - last_cached_cursor >= self.cache_interval:
|
|
173
|
-
self.command_store.add_cached(
|
|
188
|
+
self.command_store.add_cached(self.copy_state(self._live_state), self.cursor)
|
|
174
189
|
|
|
175
190
|
return self._live_state
|
|
176
191
|
|
|
@@ -184,21 +199,22 @@ class CommandController:
|
|
|
184
199
|
# a store restored from persistence has a cursor-0 snapshot but no init_state in hand
|
|
185
200
|
cached_at_origin = self.command_store.get_cached().get(0, None)
|
|
186
201
|
if cached_at_origin is not None:
|
|
187
|
-
return
|
|
188
|
-
return
|
|
202
|
+
return self.copy_state(cached_at_origin)
|
|
203
|
+
return self.copy_state(self.init_state)
|
|
189
204
|
|
|
190
205
|
try:
|
|
191
206
|
# Get latest cached
|
|
192
207
|
last_cached_state, last_cached_idx = self.command_store.last_cached(max_idx=idx)
|
|
193
208
|
|
|
194
|
-
last_cached_state =
|
|
209
|
+
last_cached_state = self.copy_state(last_cached_state)
|
|
195
210
|
|
|
196
211
|
for command in self.command_store.get_commands(last_cached_idx, idx):
|
|
197
212
|
last_cached_state = command.execute(last_cached_state)
|
|
198
213
|
if last_cached_state is None:
|
|
199
214
|
raise Exception("The command.execute() operation returned a None value")
|
|
200
215
|
|
|
201
|
-
logger.
|
|
216
|
+
if logger.isEnabledFor(logging.INFO):
|
|
217
|
+
logger.info(pprint.pformat(last_cached_state))
|
|
202
218
|
return last_cached_state
|
|
203
219
|
except Exception as e:
|
|
204
220
|
# raise the exception on the command that failed
|
|
@@ -213,7 +229,8 @@ class CommandController:
|
|
|
213
229
|
logger.info(f"Undo - [idx: {self.cursor}]")
|
|
214
230
|
|
|
215
231
|
self._live_state = self.resolve(self.cursor)
|
|
216
|
-
logger.
|
|
232
|
+
if logger.isEnabledFor(logging.INFO):
|
|
233
|
+
logger.info(pprint.pformat(self._live_state))
|
|
217
234
|
return self._live_state
|
|
218
235
|
|
|
219
236
|
@_needsLock
|
|
@@ -225,7 +242,8 @@ class CommandController:
|
|
|
225
242
|
logger.info(f"Redo - [idx: {self.cursor}]")
|
|
226
243
|
|
|
227
244
|
self._live_state = self.resolve(self.cursor)
|
|
228
|
-
logger.
|
|
245
|
+
if logger.isEnabledFor(logging.INFO):
|
|
246
|
+
logger.info(pprint.pformat(self._live_state))
|
|
229
247
|
return self._live_state
|
|
230
248
|
|
|
231
249
|
@property
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import unittest
|
|
2
|
-
from cooptools.commandDesignPattern import CommandBatch, CommandProtocol, CommandController, InMemoryCommandStore
|
|
2
|
+
from cooptools.commandDesignPattern import CommandBatch, CommandProtocol, CommandController, InMemoryCommandStore, share_state
|
|
3
|
+
import copy
|
|
3
4
|
from dataclasses import dataclass
|
|
4
5
|
from cooptools.commandDesignPattern.exceptions import ResolveBatchException, ResolveStateException
|
|
5
6
|
|
|
@@ -292,3 +293,59 @@ class Test_CommandDesignPattern(unittest.TestCase):
|
|
|
292
293
|
|
|
293
294
|
# assert
|
|
294
295
|
self.assertEqual(state.amount, 0)
|
|
296
|
+
|
|
297
|
+
def test__copy_state__takes_every_snapshot(self):
|
|
298
|
+
# arrange
|
|
299
|
+
copies = []
|
|
300
|
+
def spy(state):
|
|
301
|
+
copies.append(state)
|
|
302
|
+
return state
|
|
303
|
+
init = Dummy_State()
|
|
304
|
+
controller = CommandController(init, copy_state=spy)
|
|
305
|
+
|
|
306
|
+
# act
|
|
307
|
+
controller.execute([Dummy_PureCommand(adjustment=5)])
|
|
308
|
+
|
|
309
|
+
# assert
|
|
310
|
+
self.assertEqual(len(copies), 3) # live state at init, cached origin, pre-batch rollback point
|
|
311
|
+
self.assertIs(controller.CachedStates[0][1], init)
|
|
312
|
+
self.assertEqual(controller.State.amount, 5)
|
|
313
|
+
|
|
314
|
+
def test__share_state__failed_batch_rolls_back_to_the_previous_state(self):
|
|
315
|
+
# arrange
|
|
316
|
+
controller = CommandController(Dummy_State(), copy_state=share_state)
|
|
317
|
+
controller.execute([Dummy_PureCommand(adjustment=5)])
|
|
318
|
+
before = controller.State
|
|
319
|
+
|
|
320
|
+
# act
|
|
321
|
+
with self.assertRaises(ResolveStateException):
|
|
322
|
+
controller.execute([Dummy_PureCommand(adjustment=1), Dummy_CommandThatFails(adjustment=1)])
|
|
323
|
+
|
|
324
|
+
# assert
|
|
325
|
+
self.assertIs(controller.State, before)
|
|
326
|
+
self.assertEqual(controller.State.amount, 5)
|
|
327
|
+
|
|
328
|
+
def test__share_state__undo_resolves_earlier_states(self):
|
|
329
|
+
# arrange
|
|
330
|
+
controller = CommandController(Dummy_State(), cache_interval=2, copy_state=share_state)
|
|
331
|
+
for _ in range(5):
|
|
332
|
+
controller.execute([Dummy_PureCommand(adjustment=10)])
|
|
333
|
+
|
|
334
|
+
# act
|
|
335
|
+
state = controller.undo()
|
|
336
|
+
|
|
337
|
+
# assert
|
|
338
|
+
self.assertEqual(state.amount, 40)
|
|
339
|
+
self.assertEqual(controller.resolve(1).amount, 10)
|
|
340
|
+
|
|
341
|
+
def test__default_copy__isolates_snapshots_from_in_place_commands(self):
|
|
342
|
+
# arrange
|
|
343
|
+
controller = CommandController(Dummy_State())
|
|
344
|
+
controller.execute([Dummy_Command(adjustment=5)])
|
|
345
|
+
|
|
346
|
+
# act
|
|
347
|
+
state = controller.undo()
|
|
348
|
+
|
|
349
|
+
# assert
|
|
350
|
+
self.assertEqual(state.amount, 0)
|
|
351
|
+
self.assertIs(CommandController.copy_state, copy.deepcopy)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cooptools-1.79 → cooptools-1.80}/cooptools/ideas/discreteEventSimulator/discreteEventSimulator.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|