Skip to content

Commit 2cc02d3

Browse files
authored
Add back addBatchSystemFactory function (#3754)
1 parent 7a8c923 commit 2cc02d3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/toil/batchSystems/registry.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
# limitations under the License.
1414

1515

16+
from typing import Callable, Type, TYPE_CHECKING
17+
18+
if TYPE_CHECKING:
19+
from toil.batchSystems.abstractBatchSystem import AbstractBatchSystem
20+
21+
1622
def gridengine_batch_system_factory():
1723
from toil.batchSystems.gridengine import GridEngineBatchSystem
1824
return GridEngineBatchSystem
@@ -71,3 +77,10 @@ def kubernetes_batch_system_factory():
7177
}
7278
BATCH_SYSTEMS = list(BATCH_SYSTEM_FACTORY_REGISTRY.keys())
7379
DEFAULT_BATCH_SYSTEM = 'single_machine'
80+
81+
def addBatchSystemFactory(key: str, batchSystemFactory: Callable[[], Type['AbstractBatchSystem']]):
82+
"""
83+
Adds a batch system to the registry for workflow-supplied batch systems.
84+
"""
85+
BATCH_SYSTEMS.append(key)
86+
BATCH_SYSTEM_FACTORY_REGISTRY[key] = batchSystemFactory

src/toil/test/batchSystems/batchSystemTest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
# protected by annotations.
3535
from toil.batchSystems.mesos.test import MesosTestSupport
3636
from toil.batchSystems.parasol import ParasolBatchSystem
37+
from toil.batchSystems.registry import (BATCH_SYSTEM_FACTORY_REGISTRY,
38+
BATCH_SYSTEMS,
39+
single_machine_batch_system_factory,
40+
addBatchSystemFactory)
3741
from toil.test.batchSystems.parasolTestSupport import ParasolTestSupport
3842
from toil.batchSystems.singleMachine import SingleMachineBatchSystem
3943
from toil.common import Config, Toil
@@ -307,6 +311,14 @@ def _waitForJobsToStart(self, numJobs, tries=20):
307311
time.sleep(1)
308312
return runningIDs
309313

314+
def testAddBatchSystemFactory(self):
315+
def test_batch_system_factory():
316+
return SingleMachineBatchSystem
317+
318+
addBatchSystemFactory('testBatchSystem', test_batch_system_factory)
319+
assert ('testBatchSystem', test_batch_system_factory) in BATCH_SYSTEM_FACTORY_REGISTRY.items()
320+
assert 'testBatchSystem' in BATCH_SYSTEMS
321+
310322
class AbstractBatchSystemJobTest(ToilTest, metaclass=ABCMeta):
311323
"""
312324
An abstract base class for batch system tests that use a full Toil workflow rather

0 commit comments

Comments
 (0)