Exemple #1
0
def generate_dependency_graph(contract_specification, call_dependencies_repo,
                              call_dependents_repo):

    assert isinstance(contract_specification, ContractSpecification)
    dsl_module = dsl_parse(dsl_source=contract_specification.specification)
    assert isinstance(dsl_module, Module)
    dsl_globals = DslNamespace()
    function_defs, expressions = extract_defs_and_exprs(
        dsl_module, dsl_globals)
    dsl_expr = expressions[0]
    assert isinstance(dsl_expr, DslExpression)
    dsl_locals = DslNamespace()

    leaf_call_ids = []
    all_dependents = defaultdict(list)
    # Generate stubbed call from the parsed DSL module object.
    for stub in generate_stubbed_calls(contract_specification.id, dsl_module,
                                       dsl_expr, dsl_globals, dsl_locals):
        assert isinstance(stub, StubbedCall)
        call_id = stub.call_id
        dsl_source = stub.dsl_source
        effective_present_time = stub.effective_present_time
        dependencies = stub.dependencies

        # Register the call requirements.
        register_call_requirement(call_id, dsl_source, effective_present_time)

        # Register the call dependencies.
        register_call_dependencies(call_id, dependencies)

        # Keep track of the leaves and the dependents.
        if len(dependencies) == 0:
            leaf_call_ids.append(call_id)
        else:
            for dependency_call_id in dependencies:
                all_dependents[dependency_call_id].append(call_id)

    # Register the call dependents.
    for call_id, dependents in all_dependents.items():
        register_call_dependents(call_id, dependents)
    register_call_dependents(contract_specification.id, [])
    # Generate and register the call order.
    link_id = contract_specification.id
    for call_id in generate_execution_order(leaf_call_ids,
                                            call_dependents_repo,
                                            call_dependencies_repo):
        register_call_link(link_id, call_id)
        link_id = call_id
Exemple #2
0
 def register_call_requirement(self, call_id, dsl_source,
                               effective_present_time):
     """
     A call requirement is a node of the dependency graph.
     """
     return register_call_requirement(
         call_id=call_id,
         dsl_source=dsl_source,
         effective_present_time=effective_present_time)
Exemple #3
0
 def register_call_requirement(self, call_id, dsl_source, effective_present_time):
     """
     A call requirement is a node of the dependency graph.
     """
     return register_call_requirement(
         call_id=call_id,
         dsl_source=dsl_source,
         effective_present_time=effective_present_time
     )
    def test_register_call_requirements(self):
        call_id = create_uuid4()

        self.assertRaises(KeyError, self.app.call_requirement_repo.__getitem__,
                          call_id)

        dsl_source = '1 + 1'
        effective_present_time = datetime.datetime(2015, 9, 7, 0, 0, 0)

        register_call_requirement(
            call_id=call_id,
            dsl_source=dsl_source,
            effective_present_time=effective_present_time)

        call_requirement = self.app.call_requirement_repo[call_id]
        assert isinstance(call_requirement, CallRequirement)
        self.assertEqual(call_requirement.dsl_source, dsl_source)
        self.assertEqual(call_requirement.effective_present_time,
                         effective_present_time)
Exemple #5
0
def generate_dependency_graph(contract_specification, call_dependencies_repo, call_dependents_repo):

    assert isinstance(contract_specification, ContractSpecification)
    dsl_module = dsl_parse(dsl_source=contract_specification.specification)
    assert isinstance(dsl_module, Module)
    dsl_globals = DslNamespace()
    function_defs, expressions = extract_defs_and_exprs(dsl_module, dsl_globals)
    dsl_expr = expressions[0]
    assert isinstance(dsl_expr, DslExpression)
    dsl_locals = DslNamespace()

    leaf_call_ids = []
    all_dependents = defaultdict(list)
    # Generate stubbed call from the parsed DSL module object.
    for stub in generate_stubbed_calls(contract_specification.id, dsl_module, dsl_expr, dsl_globals, dsl_locals):
        assert isinstance(stub, StubbedCall)
        call_id = stub.call_id
        dsl_source = stub.dsl_source
        effective_present_time = stub.effective_present_time
        dependencies = stub.dependencies

        # Register the call requirements.
        register_call_requirement(call_id, dsl_source, effective_present_time)

        # Register the call dependencies.
        register_call_dependencies(call_id, dependencies)

        # Keep track of the leaves and the dependents.
        if len(dependencies) == 0:
            leaf_call_ids.append(call_id)
        else:
            for dependency_call_id in dependencies:
                all_dependents[dependency_call_id].append(call_id)

    # Register the call dependents.
    for call_id, dependents in all_dependents.items():
        register_call_dependents(call_id, dependents)
    register_call_dependents(contract_specification.id, [])
    # Generate and register the call order.
    link_id = contract_specification.id
    for call_id in generate_execution_order(leaf_call_ids, call_dependents_repo, call_dependencies_repo):
        register_call_link(link_id, call_id)
        link_id = call_id
Exemple #6
0
def generate_dependency_graph(contract_specification, call_dependencies_repo, call_dependents_repo, call_leafs_repo,
                              call_requirement_repo):

    assert isinstance(contract_specification, ContractSpecification)
    dsl_module = dsl_parse(dsl_source=contract_specification.specification)
    assert isinstance(dsl_module, Module)
    dsl_globals = DslNamespace()
    function_defs, expressions = extract_defs_and_exprs(dsl_module, dsl_globals)
    dsl_expr = expressions[0]
    assert isinstance(dsl_expr, DslExpression)
    dsl_locals = DslNamespace()

    leaf_ids = []
    all_dependents = defaultdict(list)

    # Generate stubbed call from the parsed DSL module object.
    for stub in generate_stubbed_calls(contract_specification.id, dsl_module, dsl_expr, dsl_globals, dsl_locals):
        # assert isinstance(stub, StubbedCall)

        # Register the call requirements.
        call_id = stub.call_id
        dsl_source = str(stub.dsl_expr)
        effective_present_time = stub.effective_present_time
        call_requirement = register_call_requirement(call_id, dsl_source, effective_present_time)

        # Hold onto the dsl_expr, helps in "single process" modes....
        call_requirement._dsl_expr = stub.dsl_expr
        # - put the entity directly in the cache, otherwise the entity will be regenerated when it is next accessed
        #   and the _dsl_expr will be lost.
        call_requirement_repo.add_cache(call_id, call_requirement)

        # Register the call requirements.
        dependencies = stub.requirements
        register_call_dependencies(call_id, dependencies)

        # Keep track of the leaves and the dependents.
        if len(dependencies) == 0:
            leaf_ids.append(call_id)
        else:
            for dependency_call_id in dependencies:
                all_dependents[dependency_call_id].append(call_id)

    # Register the call dependents.
    for call_id, dependents in all_dependents.items():
        register_call_dependents(call_id, dependents)
    register_call_dependents(contract_specification.id, [])

    # Generate and register the call order.
    link_id = contract_specification.id
    for call_id in generate_execution_order(leaf_ids, call_dependents_repo, call_dependencies_repo):
        register_call_link(link_id, call_id)
        link_id = call_id

    # Register the leaf ids.
    register_call_leafs(contract_specification.id, leaf_ids)
    def test_register_call_requirements(self):
        call_id = create_uuid4()
        contract_specification_id = create_uuid4()

        self.assertRaises(KeyError, self.app.call_requirement_repo.__getitem__, call_id)

        dsl_source = '1 + 1'
        present_time = datetime.datetime(2015, 9, 7, 0, 0, 0)

        register_call_requirement(
            call_id=call_id,
            dsl_source=dsl_source,
            present_time=present_time,
            contract_specification_id=contract_specification_id,
            cost=1,
        )

        call_requirement = self.app.call_requirement_repo[call_id]
        assert isinstance(call_requirement, CallRequirement)
        self.assertEqual(call_requirement.dsl_source, dsl_source)
        self.assertEqual(call_requirement.present_time, present_time)
        self.assertEqual(call_requirement.contract_specification_id, contract_specification_id)
Exemple #8
0
    def test_register_call_requirements(self):
        call_id = create_uuid4()
        contract_specification_id = create_uuid4()

        self.assertRaises(KeyError, self.app.call_requirement_repo.__getitem__,
                          call_id)

        dsl_source = '1 + 1'
        present_time = datetime.datetime(2015, 9, 7, 0, 0, 0)

        register_call_requirement(
            call_id=call_id,
            dsl_source=dsl_source,
            present_time=present_time,
            contract_specification_id=contract_specification_id,
            cost=1,
        )

        call_requirement = self.app.call_requirement_repo[call_id]
        assert isinstance(call_requirement, CallRequirement)
        self.assertEqual(call_requirement.dsl_source, dsl_source)
        self.assertEqual(call_requirement.present_time, present_time)
        self.assertEqual(call_requirement.contract_specification_id,
                         contract_specification_id)
def generate_dependency_graph(contract_specification, call_dependencies_repo, call_dependents_repo,
                              call_requirement_repo, dsl_classes=None):
    assert isinstance(contract_specification, ContractSpecification)
    dsl_module = dsl_parse(
        dsl_source=contract_specification.source_code,
        dsl_classes=dsl_classes,
    )
    assert isinstance(dsl_module, Module)
    dsl_globals = dsl_module.namespace.copy()
    function_defs, expressions = extract_defs_and_exprs(dsl_module, dsl_globals)
    dsl_expr = expressions[0]
    assert isinstance(dsl_expr, DslExpression)
    dsl_locals = DslNamespace()

    leaf_ids = []
    all_dependents = defaultdict(list)

    # Generate stubbed call from the parsed DSL module object.
    for stubed_call in generate_stubbed_calls(contract_specification.id, dsl_expr, dsl_globals, dsl_locals,
                                              contract_specification.observation_date):
        # assert isinstance(stub, StubbedCall)

        # Estimate the cost of evaluating this expression.
        estimated_cost = stubed_call.dsl_expr.cost_expression()

        # Register the call requirements.
        call_id = stubed_call.call_id
        dsl_source = str(stubed_call.dsl_expr)
        present_time = stubed_call.present_time
        call_requirement = register_call_requirement(
            call_id=call_id,
            dsl_source=dsl_source,
            present_time=present_time,
            contract_specification_id=contract_specification.id,
            cost=estimated_cost,
        )

        # Hold onto the dsl_expr, helps in "single process" modes.
        # - put the entity directly in the cache, otherwise the entity will be
        # regenerated when it is next accessed and the _dsl_expr will be "lost"
        call_requirement._dsl_expr = stubed_call.dsl_expr
        call_requirement_repo.add_cache(call_id, call_requirement)

        # Register the call dependencies (things needed by this call).
        dependencies = stubed_call.requirements
        register_call_dependencies(call_id, dependencies)

        # Keep track of the leaves and the dependents.
        if len(dependencies) == 0:
            leaf_ids.append(call_id)
        else:
            for dependency_call_id in dependencies:
                all_dependents[dependency_call_id].append(call_id)

    # Register the call dependents.
    for call_id, dependents in all_dependents.items():
        register_call_dependents(call_id, dependents)
    register_call_dependents(contract_specification.id, [])

    # Generate and register the call order.
    link_id = contract_specification.id
    for call_id in generate_execution_order(leaf_ids, call_dependents_repo, call_dependencies_repo):
        register_call_link(link_id, call_id)
        link_id = call_id

    # Register the leaf ids.
    register_call_leafs(contract_specification.id, leaf_ids)
Exemple #10
0
def generate_dependency_graph(contract_specification,
                              call_dependencies_repo,
                              call_dependents_repo,
                              call_requirement_repo,
                              dsl_classes=None):
    assert isinstance(contract_specification, ContractSpecification)
    dsl_module = dsl_parse(
        dsl_source=contract_specification.source_code,
        dsl_classes=dsl_classes,
    )
    assert isinstance(dsl_module, Module)
    dsl_globals = dsl_module.namespace.copy()
    function_defs, expressions = extract_defs_and_exprs(
        dsl_module, dsl_globals)
    dsl_expr = expressions[0]
    assert isinstance(dsl_expr, DslExpression)
    dsl_locals = DslNamespace()

    leaf_ids = []
    all_dependents = defaultdict(list)

    # Generate stubbed call from the parsed DSL module object.
    for stubed_call in generate_stubbed_calls(
            contract_specification.id, dsl_expr, dsl_globals, dsl_locals,
            contract_specification.observation_date):
        # assert isinstance(stub, StubbedCall)

        # Estimate the cost of evaluating this expression.
        estimated_cost = stubed_call.dsl_expr.cost_expression()

        # Register the call requirements.
        call_id = stubed_call.call_id
        dsl_source = str(stubed_call.dsl_expr)
        present_time = stubed_call.present_time
        call_requirement = register_call_requirement(
            call_id=call_id,
            dsl_source=dsl_source,
            present_time=present_time,
            contract_specification_id=contract_specification.id,
            cost=estimated_cost,
        )

        # Hold onto the dsl_expr, helps in "single process" modes.
        # - put the entity directly in the cache, otherwise the entity will be
        # regenerated when it is next accessed and the _dsl_expr will be "lost"
        call_requirement._dsl_expr = stubed_call.dsl_expr
        call_requirement_repo.add_cache(call_id, call_requirement)

        # Register the call dependencies (things needed by this call).
        dependencies = stubed_call.requirements
        register_call_dependencies(call_id, dependencies)

        # Keep track of the leaves and the dependents.
        if len(dependencies) == 0:
            leaf_ids.append(call_id)
        else:
            for dependency_call_id in dependencies:
                all_dependents[dependency_call_id].append(call_id)

    # Register the call dependents.
    for call_id, dependents in all_dependents.items():
        register_call_dependents(call_id, dependents)
    register_call_dependents(contract_specification.id, [])

    # Generate and register the call order.
    link_id = contract_specification.id
    for call_id in generate_execution_order(leaf_ids, call_dependents_repo,
                                            call_dependencies_repo):
        register_call_link(link_id, call_id)
        link_id = call_id

    # Register the leaf ids.
    register_call_leafs(contract_specification.id, leaf_ids)