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: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ repos:
exclude: template
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.12
rev: v0.12.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.7.9
rev: 0.7.17
hooks:
- id: uv-lock
- repo: https://github.com/adrienverge/yamllint.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def setup(app):
"""
Entry point for the Sphinx extension.
"""
from .autoschema import SchemaDocumenter
from .autoschema import SchemaDocumenter # noqa: PLC0415

# Register the custom autodocumenter.
app.add_autodocumenter(SchemaDocumenter)
Expand Down
4 changes: 2 additions & 2 deletions src/taskgraph/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def write_artifact(filename, data):
with open(path, "w") as f:
json.dump(data, f, sort_keys=True, indent=2)
elif filename.endswith(".gz"):
import gzip
import gzip # noqa: PLC0415

with gzip.open(path, "wb") as f:
f.write(json.dumps(data)) # type: ignore
Expand All @@ -393,7 +393,7 @@ def read_artifact(filename):
with open(path) as f:
return json.load(f)
elif filename.endswith(".gz"):
import gzip
import gzip # noqa: PLC0415

with gzip.open(path, "rb") as f:
return json.load(f)
Expand Down
10 changes: 5 additions & 5 deletions src/taskgraph/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@


def get_image_digest(image_name):
from taskgraph.generator import load_tasks_for_kind
from taskgraph.parameters import Parameters
from taskgraph.generator import load_tasks_for_kind # noqa: PLC0415
from taskgraph.parameters import Parameters # noqa: PLC0415

params = Parameters(
level=os.environ.get("MOZ_SCM_LEVEL", "3"),
Expand All @@ -56,9 +56,9 @@ def get_image_digest(image_name):


def load_image_by_name(image_name, tag=None):
from taskgraph.generator import load_tasks_for_kind
from taskgraph.optimize.strategies import IndexSearch
from taskgraph.parameters import Parameters
from taskgraph.generator import load_tasks_for_kind # noqa: PLC0415
from taskgraph.optimize.strategies import IndexSearch # noqa: PLC0415
from taskgraph.parameters import Parameters # noqa: PLC0415

params = Parameters(
level=os.environ.get("MOZ_SCM_LEVEL", "3"),
Expand Down
63 changes: 33 additions & 30 deletions src/taskgraph/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def format_taskgraph_labels(taskgraph):


def format_taskgraph_json(taskgraph):
from taskgraph.util import json
from taskgraph.util import json # noqa: PLC0415

return json.dumps(taskgraph.to_json(), sort_keys=True, indent=2)

Expand All @@ -69,9 +69,9 @@ def get_filtered_taskgraph(taskgraph, tasksregex, exclude_keys):
Filter all the tasks on basis of a regular expression
and returns a new TaskGraph object
"""
from taskgraph.graph import Graph
from taskgraph.task import Task
from taskgraph.taskgraph import TaskGraph
from taskgraph.graph import Graph # noqa: PLC0415
from taskgraph.task import Task # noqa: PLC0415
from taskgraph.taskgraph import TaskGraph # noqa: PLC0415

if tasksregex:
named_links_dict = taskgraph.graph.named_links_dict()
Expand Down Expand Up @@ -117,14 +117,14 @@ def get_filtered_taskgraph(taskgraph, tasksregex, exclude_keys):

def get_taskgraph_generator(root, parameters):
"""Helper function to make testing a little easier."""
from taskgraph.generator import TaskGraphGenerator
from taskgraph.generator import TaskGraphGenerator # noqa: PLC0415

return TaskGraphGenerator(root_dir=root, parameters=parameters)


def format_taskgraph(options, parameters, overrides, logfile=None):
import taskgraph
from taskgraph.parameters import parameters_loader
import taskgraph # noqa: PLC0415
from taskgraph.parameters import parameters_loader # noqa: PLC0415

if logfile:
handler = logging.FileHandler(logfile, mode="w")
Expand Down Expand Up @@ -153,7 +153,7 @@ def format_taskgraph(options, parameters, overrides, logfile=None):


def dump_output(out, path=None, params_spec=None):
from taskgraph.parameters import Parameters
from taskgraph.parameters import Parameters # noqa: PLC0415

params_name = Parameters.format_spec(params_spec)
fh = None
Expand All @@ -175,7 +175,7 @@ def dump_output(out, path=None, params_spec=None):


def generate_taskgraph(options, parameters, overrides, logdir):
from taskgraph.parameters import Parameters
from taskgraph.parameters import Parameters # noqa: PLC0415

def logfile(spec):
"""Determine logfile given a parameters specification."""
Expand Down Expand Up @@ -370,8 +370,8 @@ def logfile(spec):
"when multiple parameters files are passed.",
)
def show_taskgraph(options):
from taskgraph.parameters import Parameters, parameters_loader
from taskgraph.util.vcs import get_repository
from taskgraph.parameters import Parameters, parameters_loader # noqa: PLC0415
from taskgraph.util.vcs import get_repository # noqa: PLC0415

if options.pop("verbose", False):
logging.root.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -575,7 +575,7 @@ def show_taskgraph(options):
metavar="context.tar",
)
def build_image(args):
from taskgraph.docker import build_context, build_image
from taskgraph.docker import build_context, build_image # noqa: PLC0415

validate_docker()
if args["context_only"] is None:
Expand Down Expand Up @@ -609,7 +609,10 @@ def build_image(args):
"or mozilla-inbound)",
)
def load_image(args):
from taskgraph.docker import load_image_by_name, load_image_by_task_id
from taskgraph.docker import ( # noqa: PLC0415
load_image_by_name,
load_image_by_task_id,
)

if not args.get("image_name") and not args.get("task_id"):
print("Specify either IMAGE-NAME or TASK-ID")
Expand Down Expand Up @@ -641,7 +644,7 @@ def validate_docker():
"contents of the tree.",
)
def image_digest(args):
from taskgraph.docker import get_image_digest
from taskgraph.docker import get_image_digest # noqa: PLC0415

try:
digest = get_image_digest(args["image_name"])
Expand All @@ -668,7 +671,7 @@ def image_digest(args):
)
@argument("--user", default=None, help="Container user to start shell with.")
def load_task(args):
from taskgraph.docker import load_task
from taskgraph.docker import load_task # noqa: PLC0415

validate_docker()
return load_task(args["task_id"], remove=args["remove"], user=args["user"])
Expand Down Expand Up @@ -728,7 +731,7 @@ def load_task(args):
"--verbose", "-v", action="store_true", help="include debug-level logging output"
)
def decision(options):
from taskgraph.decision import taskgraph_decision
from taskgraph.decision import taskgraph_decision # noqa: PLC0415

taskgraph_decision(options)

Expand All @@ -753,10 +756,10 @@ def decision(options):
help="parameters file (.yml or .json; see `taskcluster/docs/parameters.rst`)`",
)
def actions(args):
from taskgraph.actions import render_actions_json
from taskgraph.generator import TaskGraphGenerator
from taskgraph.parameters import parameters_loader
from taskgraph.util import json
from taskgraph.actions import render_actions_json # noqa: PLC0415
from taskgraph.generator import TaskGraphGenerator # noqa: PLC0415
from taskgraph.parameters import parameters_loader # noqa: PLC0415
from taskgraph.util import json # noqa: PLC0415

if args.pop("verbose", False):
logging.root.setLevel(logging.DEBUG)
Expand All @@ -782,9 +785,9 @@ def actions(args):
help="root of the taskgraph definition relative to topsrcdir",
)
def action_callback(options):
from taskgraph.actions import trigger_action_callback
from taskgraph.actions.util import get_parameters
from taskgraph.util import json
from taskgraph.actions import trigger_action_callback # noqa: PLC0415
from taskgraph.actions.util import get_parameters # noqa: PLC0415
from taskgraph.util import json # noqa: PLC0415

try:
# the target task for this action (or null if it's a group action)
Expand Down Expand Up @@ -831,10 +834,10 @@ def action_callback(options):
@argument("--input", default=None, help="Action input (.yml or .json)")
@argument("callback", default=None, help="Action callback name (Python function name)")
def test_action_callback(options):
import taskgraph.actions
import taskgraph.parameters
from taskgraph.config import load_graph_config
from taskgraph.util import json, yaml
import taskgraph.actions # noqa: PLC0415
import taskgraph.parameters # noqa: PLC0415
from taskgraph.config import load_graph_config # noqa: PLC0415
from taskgraph.util import json, yaml # noqa: PLC0415

def load_data(filename):
with open(filename) as f:
Expand Down Expand Up @@ -900,10 +903,10 @@ def load_data(filename):
help=argparse.SUPPRESS, # used for testing
)
def init_taskgraph(options):
from cookiecutter.main import cookiecutter
from cookiecutter.main import cookiecutter # noqa: PLC0415

import taskgraph
from taskgraph.util.vcs import get_repository
import taskgraph # noqa: PLC0415
from taskgraph.util.vcs import get_repository # noqa: PLC0415

repo = get_repository(os.getcwd())
root = Path(repo.path)
Expand Down
4 changes: 2 additions & 2 deletions src/taskgraph/optimize/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def optimize_task_graph(
assigned taskId, including replacement tasks.
"""
# avoid circular import
from taskgraph.optimize.strategies import IndexSearch
from taskgraph.optimize.strategies import IndexSearch # noqa: PLC0415

label_to_taskid = {}
if not existing_tasks:
Expand Down Expand Up @@ -294,7 +294,7 @@ def replace_tasks(
a side-effect.
"""
# avoid circular import
from taskgraph.optimize.strategies import IndexSearch
from taskgraph.optimize.strategies import IndexSearch # noqa: PLC0415

opt_counts = defaultdict(int)
replaced = set()
Expand Down
5 changes: 1 addition & 4 deletions test/mockedopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Imported from
# https://searchfox.org/mozilla-central/rev/c3ebaf6de2d481c262c04bb9657eaf76bf47e2ac/config/mozunit/mozunit/mozunit.py#116-232

import builtins
import os
import sys
from io import StringIO
Expand Down Expand Up @@ -85,8 +86,6 @@ def __call__(self, name, mode="r"):
return file

def __enter__(self):
import builtins

self.open = builtins.open
self._orig_path_exists = os.path.exists
self._orig_path_isdir = os.path.isdir
Expand All @@ -97,8 +96,6 @@ def __enter__(self):
os.path.isfile = self._wrapped_isfile

def __exit__(self, type, value, traceback):
import builtins

builtins.open = self.open
os.path.exists = self._orig_path_exists
os.path.isdir = self._orig_path_isdir
Expand Down
2 changes: 1 addition & 1 deletion test/test_util_python_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_find_object_no_such_object():

def test_find_object_exists():
"""find_object finds an existing object"""
from testmod.thing import TestObject
from testmod.thing import TestObject # noqa: PLC0415

obj = python_path.find_object("testmod.thing:TestObject.testClassProperty")
assert obj is TestObject.testClassProperty
Loading