Skip to content

Commit

Permalink
Add e3.anod.spec.Anod.source_list
Browse files Browse the repository at this point in the history
e3.anod.spec.Anod.source_list contain the dependencies source list
(any e3.anod.deps.Dependency that require 'source_pkg')

e3.anod.spec.Anod.deps will not reference anymore the source_pkg
dependencies.
  • Loading branch information
leocardao committed Aug 3, 2023
1 parent 229302d commit c0eba37
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
17 changes: 13 additions & 4 deletions src/e3/anod/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from e3.error import E3Error

if TYPE_CHECKING:
from typing import cast, NoReturn, Optional, Tuple
from typing import cast, NoReturn, Optional
from collections.abc import Callable
from e3.anod.action import Action
from e3.anod.package import SourceBuilder
Expand All @@ -44,7 +44,7 @@
from e3.mypy import assert_never

# spec name, build env, target env, host env, qualifier, kind, source name
CacheKeyType = Tuple[
CacheKeyType = tuple[
str, Platform, Platform, Platform, Optional[str], Optional[str], Optional[str]
]
ResolverType = Callable[[Action, Decision], bool]
Expand Down Expand Up @@ -439,7 +439,16 @@ def add_dep(spec_instance: Anod, dep: Dependency, dep_instance: Anod) -> None:
spec_instance.name, dep.local_name
),
)
spec_instance.deps[dep.local_name] = dep_instance
if dep.kind != "source":
spec_instance.deps[dep.local_name] = dep_instance
else:
srcbuild_list = dep_instance.source_pkg_build
if not srcbuild_list:
spec_instance.deps_source_list[dep.local_name] = set()
else:
spec_instance.deps_source_list[dep.local_name] = {
srcbuild.name for srcbuild in srcbuild_list
}

# Initialize a spec instance
spec = self.load(
Expand Down Expand Up @@ -669,7 +678,7 @@ def add_dep(spec_instance: Anod, dep: Dependency, dep_instance: Anod) -> None:
add_dep(spec_instance=spec, dep=e, dep_instance=child_instance)
self.dependencies[spec.uid][e.local_name] = (
e,
spec.deps[e.local_name],
child_instance,
)

continue
Expand Down
12 changes: 11 additions & 1 deletion src/e3/anod/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ def activate(self, sandbox: SandBox, spec_repository: AnodSpecRepository) -> Non
kind=e.kind,
env=e.env(self.anod_instance, BaseEnv.from_env()),
)
self.anod_instance.deps[e.local_name] = dep_instance
if e.kind != "source":
self.anod_instance.deps[e.local_name] = dep_instance
else:
srcbuild_list = dep_instance.source_pkg_build
if not srcbuild_list:
dep_instance.deps_source_list[e.local_name] = set()
else:
dep_instance.deps_source_list[e.local_name] = {
srcbuild.name for srcbuild in srcbuild_list
}

e3.log.debug("activating spec %s", self.anod_instance.uid)

def call(self, action: str) -> Any:
Expand Down
3 changes: 2 additions & 1 deletion src/e3/anod/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Literal,
Union,
)
from collections.abc import Callable, Sequence
from collections.abc import Callable, Sequence, Iterable
from e3.anod.buildspace import BuildSpace
from e3.anod.sandbox import SandBox
from e3.env import BaseEnv
Expand Down Expand Up @@ -212,6 +212,7 @@ def __init__(
:raise: SpecError
"""
self.deps: dict[str, Anod] = {}
self.deps_source_list: dict[str, Iterable[str]] = {}

self.kind = kind
self.jobs = jobs
Expand Down
15 changes: 11 additions & 4 deletions tests/tests_e3/anod/context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,12 @@ def anod_action(
assert ctag["plan_line"] == "plan.txt:4"

# Also verify that the instance deps is properly loaded
assert set(action.anod_instance.deps.keys()) == {"spec1"}
assert action.anod_instance.deps["spec1"].__class__.__name__ == "Spec1"
assert not set(action.anod_instance.deps.keys())
# Also verify that the instance source list is properly loaded
assert set(action.anod_instance.deps_source_list.keys()) == {"spec1"}
assert set(action.anod_instance.deps_source_list["spec1"]) == {
"spec1-src"
}

# Also test that we are still able to extract the values
# after having scheduled the action graph.
Expand All @@ -522,11 +526,14 @@ def anod_action(
assert sched_dag.get_tag(uid)

# Also verify that the instance deps is properly loaded
assert set(action.anod_instance.deps.keys()) == {"spec1", "spec11"}
assert set(action.anod_instance.deps.keys()) == {"spec11"}
assert set(action.anod_instance.deps_source_list.keys()) == {"spec1"}
assert (
action.anod_instance.deps["spec11"].__class__.__name__ == "Spec11"
)
assert action.anod_instance.deps["spec1"].__class__.__name__ == "Spec1"
assert set(action.anod_instance.deps_source_list["spec1"]) == {
"spec1-src"
}

elif uid.endswith("spec3.build"):
assert sched_dag.get_tag(uid)
Expand Down

0 comments on commit c0eba37

Please sign in to comment.