Skip to content
Open
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
10 changes: 6 additions & 4 deletions src/taskgraph/util/python_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# 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
from typing import Callable


def find_object(path):
def find_object(path: str) -> Callable:
"""
Find a Python object given a path of the form <modulepath>:<objectpath>.
Conceptually equivalent to
Expand All @@ -19,11 +21,11 @@ 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)

assert callable(obj)
return obj


Expand Down
Loading