From 2f779d3061faa6665461c650e645437086cdfa9d Mon Sep 17 00:00:00 2001 From: Robert Iannucci Date: Thu, 23 May 2024 20:19:12 +0000 Subject: [PATCH] [git_cl] Minor type annotation and initialization cleanup. Noticed that the comments around lazily initialization on settings mentioned that it does logging or something like this, but in fact the __init__ method is purely vanilla. R=gavinmak@google.com Bug: 336351842 Change-Id: I9d8120001690b2bbd52ac2172d346ce95e2dddd3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5565083 Reviewed-by: Gavin Mak Auto-Submit: Robbie Iannucci Commit-Queue: Gavin Mak --- git_cl.py | 25 ++++++++----------------- tests/git_cl_test.py | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/git_cl.py b/git_cl.py index ead1cd1f9..3d50af954 100755 --- a/git_cl.py +++ b/git_cl.py @@ -6,6 +6,8 @@ # Copyright (C) 2008 Evan Martin """A git-command for integrating reviews on Gerrit.""" +from __future__ import annotations + import base64 import collections import datetime @@ -140,9 +142,6 @@ LAST_UPLOAD_HASH_CONFIG_KEY = 'last-upload-hash' # Shortcut since it quickly becomes repetitive. Fore = colorama.Fore -# Initialized in main() -settings = None - # Used by tests/git_cl_test.py to add extra logging. # Inside the weirdly failing test, add this: # >>> self.mock(git_cl, '_IS_BEING_TESTED', True) @@ -942,6 +941,9 @@ class Settings(object): return scm.GIT.GetConfig(self.GetRoot(), key, default) +settings = Settings() + + class _CQState(object): """Enum for states of CL with respect to CQ.""" NONE = 'none' @@ -1312,13 +1314,6 @@ class Changelist(object): **kwargs will be passed directly to Gerrit implementation. """ - # Poke settings so we get the "configure your server" message if - # necessary. - global settings - if not settings: - # Happens when git_cl.py is used as a utility library. - settings = Settings() - self.branchref = branchref if self.branchref: assert (branchref.startswith(('refs/heads/', 'refs/branch-heads/')) @@ -3920,7 +3915,9 @@ def color_for_status(status): }.get(status, Fore.WHITE) -def get_cl_statuses(changes, fine_grained, max_processes=None): +def get_cl_statuses(changes: List[Changelist], + fine_grained, + max_processes=None): """Returns a blocking iterable of (cl, status) for given branches. If fine_grained is true, this will fetch CL statuses from the server. @@ -6815,12 +6812,6 @@ class OptionParser(optparse.OptionParser): try: return self._parse_args(args) finally: - # Regardless of success or failure of args parsing, we want to - # report metrics, but only after logging has been initialized (if - # parsing succeeded). - global settings - settings = Settings() - if metrics.collector.config.should_collect_metrics: try: # GetViewVCUrl ultimately calls logging method. diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index dd3befae8..397e632d1 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -673,7 +673,7 @@ class TestGitCl(unittest.TestCase): mock.patch('scm.GIT.CaptureStatus', return_value=[('M', 'foo.txt')]).start() # It's important to reset settings to not have inter-tests interference. - git_cl.settings = None + git_cl.settings = git_cl.Settings() self.addCleanup(mock.patch.stopall) def tearDown(self):