-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checkpoint on new builder/runner architecture
Signed-off-by: Matthew Ballance <[email protected]>
- Loading branch information
Showing
45 changed files
with
696 additions
and
952 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
from .package_def import * | ||
from .session import * | ||
from .task_graph_runner import * | ||
from .task import * | ||
from .task_data import * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import asyncio | ||
import os | ||
from ..task_graph_runner import TaskGraphRunner | ||
from ..util import loadProjPkgDef | ||
from ..task_graph_builder import TaskGraphBuilder | ||
from ..task_graph_runner_local import TaskGraphRunnerLocal | ||
from ..pkg_rgy import PkgRgy | ||
|
||
|
||
class CmdRun(object): | ||
|
||
def __call__(self, args): | ||
|
||
# First, find the project we're working with | ||
pkg = loadProjPkgDef(os.getcwd()) | ||
|
||
if pkg is None: | ||
raise Exception("Failed to find a 'flow.dv' file that defines a package in %s or its parent directories" % os.getcwd()) | ||
|
||
print("pkg: %s" % pkg.name) | ||
|
||
if len(args.tasks) > 0: | ||
pass | ||
else: | ||
# Print out available tasks | ||
tasks = [] | ||
for task in pkg.tasks: | ||
tasks.append(task) | ||
for frag in pkg.fragment_l: | ||
for task in frag.tasks: | ||
tasks.append(task) | ||
tasks.sort(key=lambda x: x.name) | ||
|
||
max_name_len = 0 | ||
for t in tasks: | ||
if len(t.name) > max_name_len: | ||
max_name_len = len(t.name) | ||
|
||
print("No task specified. Available Tasks:") | ||
for t in tasks: | ||
desc = t.desc | ||
if desc is None or t.desc == "": | ||
"<no descripion>" | ||
print("%s - %s" % (t.name.ljust(max_name_len), desc)) | ||
|
||
pass | ||
|
||
# Create a session around <pkg> | ||
# Need to select a backend | ||
# Need somewhere to store project config data | ||
# Maybe separate into a task-graph builder and a task-graph runner | ||
|
||
# TODO: allow user to specify run root -- maybe relative to some fixed directory? | ||
rundir = os.path.join(pkg.basedir, "rundir") | ||
|
||
builder = TaskGraphBuilder(root_pkg=pkg, rundir=rundir) | ||
runner = TaskGraphRunnerLocal(rundir) | ||
|
||
tasks = [] | ||
|
||
for spec in args.tasks: | ||
task = builder.mkTaskGraph(spec) | ||
tasks.append(task) | ||
|
||
asyncio.run(runner.run(tasks)) | ||
|
||
# rgy = PkgRgy.inst() | ||
# rgy.registerPackage(pkg) | ||
|
||
|
||
# srcdir = os.getcwd() | ||
|
||
# session = Session(srcdir, rundir) | ||
|
||
# package = session.load(srcdir) | ||
|
||
# graphs = [] | ||
# for task in args.tasks: | ||
# if task.find(".") == -1: | ||
# task = package.name + "." + task | ||
# subgraph = session.mkTaskGraph(task) | ||
# graphs.append(subgraph) | ||
|
||
# awaitables = [subgraph.do_run() for subgraph in graphs] | ||
# print("%d awaitables" % len(awaitables)) | ||
|
||
# out = asyncio.get_event_loop().run_until_complete(asyncio.gather(*awaitables)) | ||
|
||
# print("out: %s" % str(out)) | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import os | ||
import sys | ||
from typing import Dict, Tuple | ||
from .package_def import PackageDef | ||
|
||
class PkgRgy(object): | ||
_inst = None | ||
|
||
def __init__(self): | ||
self._pkgpath = [] | ||
self._pkg_m : Dict[str, Tuple[str,PackageDef]] = {} | ||
|
||
def hasPackage(self, name, search_path=False): | ||
if name in self._pkg_m.keys(): | ||
return True | ||
elif search_path: | ||
for p in self._pkgpath: | ||
if os.path.exists(os.path.join(p, name)): | ||
return True | ||
else: | ||
return False | ||
|
||
def getPackage(self, name): | ||
if name in self._pkg_m.keys(): | ||
if self._pkg_m[name][1] is None: | ||
pkg_def = PackageDef.load(self._pkg_m[name][0]) | ||
# Load the package | ||
self._pkg_m[name] = ( | ||
self._pkg_m[name][0], | ||
pkg_def | ||
) | ||
pass | ||
return self._pkg_m[name][1] | ||
else: | ||
# Go search the package path | ||
return None | ||
|
||
def registerPackage(self, pkg_def): | ||
if pkg_def.name in self._pkg_m.keys(): | ||
raise Exception("Duplicate package %s" % pkg_def.name) | ||
self._pkg_m[pkg_def.name] = pkg_def | ||
|
||
def _discover_plugins(self): | ||
# Register built-in package | ||
self._pkg_m["std"] = (os.path.join(os.path.dirname(__file__), "std/flow.dv"), None) | ||
|
||
if sys.version_info < (3,10): | ||
from importlib_metadata import entry_points | ||
else: | ||
from importlib.metadata import entry_points | ||
|
||
discovered_plugins = entry_points(group='dv_flow.mgr') | ||
for p in discovered_plugins: | ||
try: | ||
mod = p.load() | ||
|
||
if hasattr(mod, "dvfm_packages"): | ||
pkg_m = mod.dvfm_packages() | ||
|
||
for name,path in pkg_m.items(): | ||
if name in self._pkg_m.keys(): | ||
raise Exception("Package %s already registered using path %s. Conflicting path: %s" % ( | ||
name, self._pkg_m[name][0], path)) | ||
self._pkg_m[name] = (path, None) | ||
except Exception as e: | ||
print("Error loading plugin %s: %s" % (p.name, str(e))) | ||
raise e | ||
|
||
# self._pkgs = {} | ||
# for pkg in self._load_pkg_list(): | ||
# self._pkgs[pkg.name] = pkg | ||
|
||
@classmethod | ||
def inst(cls): | ||
if cls._inst is None: | ||
cls._inst = cls() | ||
cls._inst._discover_plugins() | ||
return cls._inst |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.