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

Avoid computing expensive default values when the value is overridden… #624

Merged
merged 1 commit into from
Jan 9, 2025
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 src/taskgraph/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _get_defaults(repo_root=None):
"do_not_optimize": [],
"enable_always_target": True,
"existing_tasks": {},
"files_changed": repo.get_changed_files("AM"),
"files_changed": lambda: repo.get_changed_files("AM"),
"filters": ["target_tasks_method"],
"head_ref": repo.branch or repo.head_rev,
"head_repository": repo_url,
Expand Down Expand Up @@ -210,7 +210,7 @@ def _fill_defaults(repo_root=None, **kwargs):

for name, default in defaults.items():
if name not in kwargs:
kwargs[name] = default
kwargs[name] = default() if callable(default) else default
return kwargs

def check(self):
Expand Down
9 changes: 7 additions & 2 deletions test/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ def test_extend_parameters_schema(monkeypatch):
}
),
)
monkeypatch.setattr(
parameters,
"defaults_functions",
list(parameters.defaults_functions),
)

with pytest.raises(ParameterMismatch):
Parameters(strict=False).check()
Expand Down Expand Up @@ -437,7 +442,7 @@ def test_extend_parameters_schema(monkeypatch):
),
),
)
def test_get_defaults(
def test_defaults(
monkeypatch, repo_root, is_repo, raises, expected_repo_root, expected
):
def mock_get_repository(repo_root):
Expand Down Expand Up @@ -478,4 +483,4 @@ def mock_parse(url):
monkeypatch.setattr(parameters, "datetime", datetime_mock)
monkeypatch.setattr(parameters, "get_version", lambda *_, **__: "1.0.0")

assert parameters._get_defaults(repo_root) == expected
assert parameters.Parameters(strict=False, repo_root=repo_root) == expected
Loading