@@ -82,7 +82,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
82
82
stderr = (subprocess .PIPE if hide_stderr else None ),
83
83
)
84
84
break
85
- except EnvironmentError :
85
+ except OSError :
86
86
e = sys .exc_info ()[1 ]
87
87
if e .errno == errno .ENOENT :
88
88
continue
@@ -92,7 +92,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
92
92
return None , None
93
93
else :
94
94
if verbose :
95
- print ("unable to find command, tried %s" % ( commands ,) )
95
+ print (f "unable to find command, tried { commands } " )
96
96
return None , None
97
97
stdout = p .communicate ()[0 ].strip ().decode ()
98
98
if p .returncode != 0 :
@@ -143,22 +143,21 @@ def git_get_keywords(versionfile_abs):
143
143
# _version.py.
144
144
keywords = {}
145
145
try :
146
- f = open (versionfile_abs , "r" )
147
- for line in f .readlines ():
148
- if line .strip ().startswith ("git_refnames =" ):
149
- mo = re .search (r'=\s*"(.*)"' , line )
150
- if mo :
151
- keywords ["refnames" ] = mo .group (1 )
152
- if line .strip ().startswith ("git_full =" ):
153
- mo = re .search (r'=\s*"(.*)"' , line )
154
- if mo :
155
- keywords ["full" ] = mo .group (1 )
156
- if line .strip ().startswith ("git_date =" ):
157
- mo = re .search (r'=\s*"(.*)"' , line )
158
- if mo :
159
- keywords ["date" ] = mo .group (1 )
160
- f .close ()
161
- except EnvironmentError :
146
+ with open (versionfile_abs ) as f :
147
+ for line in f .readlines ():
148
+ if line .strip ().startswith ("git_refnames =" ):
149
+ mo = re .search (r'=\s*"(.*)"' , line )
150
+ if mo :
151
+ keywords ["refnames" ] = mo .group (1 )
152
+ if line .strip ().startswith ("git_full =" ):
153
+ mo = re .search (r'=\s*"(.*)"' , line )
154
+ if mo :
155
+ keywords ["full" ] = mo .group (1 )
156
+ if line .strip ().startswith ("git_date =" ):
157
+ mo = re .search (r'=\s*"(.*)"' , line )
158
+ if mo :
159
+ keywords ["date" ] = mo .group (1 )
160
+ except OSError :
162
161
pass
163
162
return keywords
164
163
@@ -182,11 +181,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
182
181
if verbose :
183
182
print ("keywords are unexpanded, not using" )
184
183
raise NotThisMethod ("unexpanded keywords, not a git-archive tarball" )
185
- refs = set ([ r .strip () for r in refnames .strip ("()" ).split ("," )])
184
+ refs = { r .strip () for r in refnames .strip ("()" ).split ("," )}
186
185
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
187
186
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
188
187
TAG = "tag: "
189
- tags = set ([ r [len (TAG ) :] for r in refs if r .startswith (TAG )])
188
+ tags = { r [len (TAG ) :] for r in refs if r .startswith (TAG )}
190
189
if not tags :
191
190
# Either we're using git < 1.8.3, or there really are no tags. We use
192
191
# a heuristic: assume all version tags have a digit. The old git %d
@@ -195,7 +194,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
195
194
# between branches and tags. By ignoring refnames without digits, we
196
195
# filter out many common branch names like "release" and
197
196
# "stabilization", as well as "HEAD" and "master".
198
- tags = set ([ r for r in refs if re .search (r"\d" , r )])
197
+ tags = { r for r in refs if re .search (r"\d" , r )}
199
198
if verbose :
200
199
print ("discarding '%s', no digits" % "," .join (refs - tags ))
201
200
if verbose :
@@ -298,10 +297,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
298
297
if verbose :
299
298
fmt = "tag '%s' doesn't start with prefix '%s'"
300
299
print (fmt % (full_tag , tag_prefix ))
301
- pieces ["error" ] = "tag '%s' doesn't start with prefix '%s'" % (
302
- full_tag ,
303
- tag_prefix ,
304
- )
300
+ pieces ["error" ] = f"tag '{ full_tag } ' doesn't start with prefix '{ tag_prefix } '"
305
301
return pieces
306
302
pieces ["closest-tag" ] = full_tag [len (tag_prefix ) :]
307
303
0 commit comments