Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/taskgraph/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def register(self):
sys.path.insert(0, self.root_dir)
register_path = self["taskgraph"].get("register")
if register_path:
find_object(register_path)(self)
register = find_object(register_path)
assert callable(register)
register(self)

@property
def vcs_root(self):
Expand Down
6 changes: 3 additions & 3 deletions src/taskgraph/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ def get_decision_parameters(graph_config, options):
parameters["optimize_target_tasks"] = options["optimize_target_tasks"]

if "decision-parameters" in graph_config["taskgraph"]:
find_object(graph_config["taskgraph"]["decision-parameters"])(
graph_config, parameters
)
decision_params = find_object(graph_config["taskgraph"]["decision-parameters"])
assert callable(decision_params)
decision_params(graph_config, parameters)

if options.get("try_task_config_file"):
task_config_file = os.path.abspath(options.get("try_task_config_file"))
Expand Down
10 changes: 6 additions & 4 deletions src/taskgraph/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ class Kind:
config: Dict
graph_config: GraphConfig

def _get_loader(self):
def _get_loader(self) -> Callable:
try:
loader = self.config["loader"]
loader_path = self.config["loader"]
except KeyError:
loader = "taskgraph.loader.default:loader"
return find_object(loader)
loader_path = "taskgraph.loader.default:loader"
loader = find_object(loader_path)
assert callable(loader)
return loader

def load_tasks(self, parameters, loaded_tasks, write_artifacts):
loader = self._get_loader()
Expand Down
8 changes: 4 additions & 4 deletions src/taskgraph/util/python_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import importlib
import inspect
import os


def find_object(path):
def find_object(path: str):
"""
Find a Python object given a path of the form <modulepath>:<objectpath>.
Conceptually equivalent to
Expand All @@ -19,11 +20,10 @@ def find_object(modulepath, objectpath):
raise ValueError(f'python path {path!r} does not have the form "module:object"')

modulepath, objectpath = path.split(":")
obj = __import__(modulepath)
for a in modulepath.split(".")[1:]:
obj = getattr(obj, a)
obj = importlib.import_module(modulepath)
for a in objectpath.split("."):
obj = getattr(obj, a)

return obj


Expand Down
Loading