Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e3.anod.spec.Anod.deps_source_list #606

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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":
leocardao marked this conversation as resolved.
Show resolved Hide resolved
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
Loading