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 Jul 21, 2023
1 parent a5ac69c commit 18f516b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
23 changes: 19 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,22 @@ 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
spec_instance.source_list[dep.local_name] = set()
if not srcbuild_list:
raise AnodError(
f"{dep.local_name} is marked as source_pkg but not sources is "
"defined"
)
for srcbuild in srcbuild_list:
if srcbuild.name in spec_instance.source_list[dep.local_name]:
raise AnodError(
f"{srcbuild.name} defined two times in source_pkg_build"
)
spec_instance.source_list[dep.local_name].add(srcbuild.name) # type: ignore[attr-defined]

# Initialize a spec instance
spec = self.load(
Expand Down Expand Up @@ -669,7 +684,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
23 changes: 22 additions & 1 deletion src/e3/anod/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,28 @@ 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
self.anod_instance.source_list[e.local_name] = set()
if not srcbuild_list:
raise AnodError(
f"{e.local_name} is marked as source_pkg but not sources is"
" defined"
)
for srcbuild in srcbuild_list:
if (
srcbuild.name
in self.anod_instance.source_list[e.local_name]
):
raise AnodError(
f"{srcbuild.name} defined two times in source_pkg_build"
)
self.anod_instance.source_list[e.local_name].add( # type: ignore[attr-defined]
srcbuild.name
)

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.source_list: dict[str, Iterable[str]] = {}

self.kind = kind
self.jobs = jobs
Expand Down
11 changes: 7 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,10 @@ 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.source_list.keys()) == {"spec1"}
assert set(action.anod_instance.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 +524,12 @@ 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.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.source_list["spec1"]) == {"spec1-src"}

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

0 comments on commit 18f516b

Please sign in to comment.