Translation screenshots presubmit: Import grd_helper only when needed
The presubmit currently imports grd_reader on all presubmit invocations
(i.e. git cl upload) even though it's only needed when the CL touches
a .grd or .grdp file. This CL does not import if no .grd/grdp files
are affected.
Bug: 1031189
Change-Id: Ib63873771a2ba6d0e60da76a457d2c22b89791b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1978939
Reviewed-by: Andrew Grieve <[email protected]>
Commit-Queue: Mustafa Emre Acer <[email protected]>
Cr-Commit-Position: refs/heads/master@{#727497}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index ec8806d4..2f769a3 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -4645,14 +4645,6 @@
import sys
from io import StringIO
- try:
- old_sys_path = sys.path
- sys.path = sys.path + [input_api.os_path.join(
- input_api.PresubmitLocalPath(), 'tools', 'translation')]
- from helper import grd_helper
- finally:
- sys.path = old_sys_path
-
new_or_added_paths = set(f.LocalPath()
for f in input_api.AffectedFiles()
if (f.Action() == 'A' or f.Action() == 'M'))
@@ -4663,6 +4655,9 @@
affected_grds = [f for f in input_api.AffectedFiles()
if (f.LocalPath().endswith('.grd') or
f.LocalPath().endswith('.grdp'))]
+ if not affected_grds:
+ return []
+
affected_png_paths = [f.AbsoluteLocalPath()
for f in input_api.AffectedFiles()
if (f.LocalPath().endswith('.png'))]
@@ -4706,6 +4701,13 @@
if input_api.os_path.exists(sha1_path) and sha1_path not in removed_paths:
unnecessary_sha1_files.append(sha1_path)
+ try:
+ old_sys_path = sys.path
+ sys.path = sys.path + [input_api.os_path.join(
+ input_api.PresubmitLocalPath(), 'tools', 'translation')]
+ from helper import grd_helper
+ finally:
+ sys.path = old_sys_path
for f in affected_grds:
file_path = f.LocalPath()