Skip to content

Commit

Permalink
Add back addBatchSystemFactory function (#3754)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanxu18 authored Aug 25, 2021
1 parent 7a8c923 commit 2cc02d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/toil/batchSystems/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
# limitations under the License.


from typing import Callable, Type, TYPE_CHECKING

if TYPE_CHECKING:
from toil.batchSystems.abstractBatchSystem import AbstractBatchSystem


def gridengine_batch_system_factory():
from toil.batchSystems.gridengine import GridEngineBatchSystem
return GridEngineBatchSystem
Expand Down Expand Up @@ -71,3 +77,10 @@ def kubernetes_batch_system_factory():
}
BATCH_SYSTEMS = list(BATCH_SYSTEM_FACTORY_REGISTRY.keys())
DEFAULT_BATCH_SYSTEM = 'single_machine'

def addBatchSystemFactory(key: str, batchSystemFactory: Callable[[], Type['AbstractBatchSystem']]):
"""
Adds a batch system to the registry for workflow-supplied batch systems.
"""
BATCH_SYSTEMS.append(key)
BATCH_SYSTEM_FACTORY_REGISTRY[key] = batchSystemFactory
12 changes: 12 additions & 0 deletions src/toil/test/batchSystems/batchSystemTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
# protected by annotations.
from toil.batchSystems.mesos.test import MesosTestSupport
from toil.batchSystems.parasol import ParasolBatchSystem
from toil.batchSystems.registry import (BATCH_SYSTEM_FACTORY_REGISTRY,
BATCH_SYSTEMS,
single_machine_batch_system_factory,
addBatchSystemFactory)
from toil.test.batchSystems.parasolTestSupport import ParasolTestSupport
from toil.batchSystems.singleMachine import SingleMachineBatchSystem
from toil.common import Config, Toil
Expand Down Expand Up @@ -307,6 +311,14 @@ def _waitForJobsToStart(self, numJobs, tries=20):
time.sleep(1)
return runningIDs

def testAddBatchSystemFactory(self):
def test_batch_system_factory():
return SingleMachineBatchSystem

addBatchSystemFactory('testBatchSystem', test_batch_system_factory)
assert ('testBatchSystem', test_batch_system_factory) in BATCH_SYSTEM_FACTORY_REGISTRY.items()
assert 'testBatchSystem' in BATCH_SYSTEMS

class AbstractBatchSystemJobTest(ToilTest, metaclass=ABCMeta):
"""
An abstract base class for batch system tests that use a full Toil workflow rather
Expand Down

0 comments on commit 2cc02d3

Please sign in to comment.