1515class ReviewHelper :
1616 """Helper for conducting code reviews."""
1717
18+ _SUPPORTED_PROJECTS_PATTERN = '|' .join (
19+ project .ProjectHelper .SUPPORTED_PROJECTS )
1820 _PROJECT_NAME_PREFIX_REGEX = re .compile (
19- r'\[({0:s})\] ' .format (
20- '|' .join (project .ProjectHelper .SUPPORTED_PROJECTS )))
21+ rf'\[({ _SUPPORTED_PROJECTS_PATTERN } )\] ' )
2122
2223 _CODE_INSPECTION_COMMANDS = frozenset ([
2324 'create-pr' , 'create_pr' , 'lint' , 'lint-test' , 'lint_test' ])
@@ -66,32 +67,32 @@ def CheckLocalGitState(self):
6667 if self ._command in (
6768 'close' , 'create-pr' , 'create_pr' , 'lint' , 'lint-test' , 'lint_test' ):
6869 if not self ._git_helper .CheckHasProjectUpstream ():
69- print ( '{0:s} aborted - missing project upstream.' . format (
70- self . _command . title ()) )
71- print ('Run: git remote add upstream {0 :s}' . format ( self . _git_repo_url ) )
70+ command_title = self . _command . title ()
71+ print ( f' { command_title :s } aborted - missing project upstream.' )
72+ print (f 'Run: git remote add upstream { self . _git_repo_url :s} ' )
7273 return False
7374
7475 if self ._command not in (
7576 'lint' , 'lint-test' , 'lint_test' , 'test' , 'update-version' ,
7677 'update_version' ):
7778 if self ._git_helper .CheckHasUncommittedChanges ():
78- print ( '{0:s} aborted - detected uncommitted changes.' . format (
79- self . _command . title ()) )
79+ command_title = self . _command . title ()
80+ print ( f' { command_title :s } aborted - detected uncommitted changes.' )
8081 print ('Run: git commit' )
8182 return False
8283
8384 if self ._github_organization in ('ForensicArtifacts' , 'log2timeline' ):
8485 self ._active_branch = self ._git_helper .GetActiveBranch ()
8586 if self ._command in ('create-pr' , 'create_pr' ):
8687 if self ._active_branch == 'main' :
87- print ( '{0:s} aborted - active branch is main.' . format (
88- self . _command . title ()) )
88+ command_title = self . _command . title ()
89+ print ( f' { command_title :s } aborted - active branch is main.' )
8990 return False
9091
9192 elif self ._command == 'close' :
9293 if self ._feature_branch == 'main' :
93- print ( '{0:s} aborted - feature branch cannot be main.' . format (
94- self . _command . title ()) )
94+ command_title = self . _command . title ()
95+ print ( f' { command_title :s } aborted - feature branch cannot be main.' )
9596 return False
9697
9798 if self ._active_branch != 'main' :
@@ -107,14 +108,15 @@ def Close(self):
107108 bool: True if the close was successful.
108109 """
109110 if not self ._git_helper .CheckHasBranch (self ._feature_branch ):
110- print ('No such feature branch: {0 :s}' . format ( self . _feature_branch ) )
111+ print (f 'No such feature branch: { self . _feature_branch :s} ' )
111112 else :
112113 self ._git_helper .RemoveFeatureBranch (self ._feature_branch )
113114
114115 if not self ._git_helper .SynchronizeWithUpstream ():
115- print ((
116- '{0:s} aborted - unable to synchronize with '
117- 'upstream/main.' ).format (self ._command .title ()))
116+ command_title = self ._command .title ()
117+ print (
118+ f'{ command_title :s} aborted - unable to synchronize with '
119+ f'upstream/main.' )
118120
119121 return True
120122
@@ -130,8 +132,8 @@ def InitializeHelpers(self):
130132
131133 self ._project_name = self ._project_helper .project_name
132134 if not self ._project_name :
133- print ( '{0:s} aborted - unable to determine project name.' . format (
134- self . _command . title ()) )
135+ command_title = self . _command . title ()
136+ print ( f' { command_title :s } aborted - unable to determine project name.' )
135137 return False
136138
137139 project_definition = self ._project_helper .ReadDefinitionFile ()
@@ -144,12 +146,15 @@ def InitializeHelpers(self):
144146 self ._github_organization , _ , _ = self ._github_organization .partition ('/' )
145147
146148 if not self ._github_organization :
147- print ('{0:s} aborted - unable to determine GitHub organization.' .format (
148- self ._command .title ()))
149+ command_title = self ._command .title ()
150+ print (
151+ f'{ command_title :s} aborted - unable to determine GitHub '
152+ f'organization.' )
149153 return False
150154
151- self ._git_repo_url = 'https://github.com/{0:s}/{1:s}.git' .format (
152- self ._github_organization , self ._project_name )
155+ self ._git_repo_url = (
156+ f'https://github.com/'
157+ f'{ self ._github_organization :s} /{ self ._project_name :s} .git' )
153158
154159 self ._git_helper = git .GitHelper (self ._git_repo_url )
155160
@@ -172,8 +177,11 @@ def Lint(self):
172177
173178 pylint_helper = pylint .PylintHelper ()
174179 if not pylint_helper .CheckUpToDateVersion ():
175- print ('{0:s} aborted - pylint version {1:s} or later required.' .format (
176- self ._command .title (), pylint .PylintHelper .MINIMUM_VERSION ))
180+ command_title = self ._command .title ()
181+ min_version = pylint .PylintHelper .MINIMUM_VERSION
182+ print (
183+ f'{ command_title :s} aborted - pylint version { min_version :s} '
184+ f'or later required.' )
177185 return False
178186
179187 if self ._all_files :
@@ -186,8 +194,8 @@ def Lint(self):
186194
187195 pylint_configuration = pylint_helper .GetRCFile (self ._project_path )
188196 if not pylint_helper .CheckFiles (changed_python_files , pylint_configuration ):
189- print ( '{0:s} aborted - unable to pass linter.' . format (
190- self . _command . title ()) )
197+ command_title = self . _command . title ()
198+ print ( f' { command_title :s } aborted - unable to pass linter.' )
191199
192200 return False
193201
@@ -208,11 +216,11 @@ def Test(self):
208216
209217 # TODO: determine why this alters the behavior of argparse.
210218 # Currently affects this script being used in plaso.
211- command = '{0 :s} run_tests.py'. format ( sys . executable )
219+ command = f' { sys . executable :s} run_tests.py'
212220 exit_code = subprocess .call (command , shell = True )
213221 if exit_code != 0 :
214- print ( '{0:s} aborted - unable to pass review.' . format (
215- self . _command . title ()) )
222+ command_title = self . _command . title ()
223+ print ( f' { command_title :s } aborted - unable to pass review.' )
216224
217225 return False
218226
0 commit comments