Commit 8c0d3832 authored by meacer's avatar meacer Committed by Commit Bot

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/+/1978939Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Mustafa Emre Acer <meacer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727497}
parent e2b8d6ac
...@@ -4645,14 +4645,6 @@ def _CheckTranslationScreenshots(input_api, output_api): ...@@ -4645,14 +4645,6 @@ def _CheckTranslationScreenshots(input_api, output_api):
import sys import sys
from io import StringIO 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() new_or_added_paths = set(f.LocalPath()
for f in input_api.AffectedFiles() for f in input_api.AffectedFiles()
if (f.Action() == 'A' or f.Action() == 'M')) if (f.Action() == 'A' or f.Action() == 'M'))
...@@ -4663,6 +4655,9 @@ def _CheckTranslationScreenshots(input_api, output_api): ...@@ -4663,6 +4655,9 @@ def _CheckTranslationScreenshots(input_api, output_api):
affected_grds = [f for f in input_api.AffectedFiles() affected_grds = [f for f in input_api.AffectedFiles()
if (f.LocalPath().endswith('.grd') or if (f.LocalPath().endswith('.grd') or
f.LocalPath().endswith('.grdp'))] f.LocalPath().endswith('.grdp'))]
if not affected_grds:
return []
affected_png_paths = [f.AbsoluteLocalPath() affected_png_paths = [f.AbsoluteLocalPath()
for f in input_api.AffectedFiles() for f in input_api.AffectedFiles()
if (f.LocalPath().endswith('.png'))] if (f.LocalPath().endswith('.png'))]
...@@ -4706,6 +4701,13 @@ def _CheckTranslationScreenshots(input_api, output_api): ...@@ -4706,6 +4701,13 @@ def _CheckTranslationScreenshots(input_api, output_api):
if input_api.os_path.exists(sha1_path) and sha1_path not in removed_paths: if input_api.os_path.exists(sha1_path) and sha1_path not in removed_paths:
unnecessary_sha1_files.append(sha1_path) 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: for f in affected_grds:
file_path = f.LocalPath() file_path = f.LocalPath()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment