@@ -89,11 +89,20 @@ class FontVersion(object):
8989
9090 :raises: IOError if fontpath does not exist
9191 """
92- def __init__ (self , font , develop = "DEV" , release = "RELEASE" , sha1_develop = "-dev" , sha1_release = "-release" ):
92+
93+ def __init__ (
94+ self ,
95+ font ,
96+ develop = "DEV" ,
97+ release = "RELEASE" ,
98+ sha1_develop = "-dev" ,
99+ sha1_release = "-release" ,
100+ ):
93101 try :
94102 # assume that it is a ttLib.TTFont object and attempt to call object attributes
95103 self .fontpath = font .reader .file .name
96- self .ttf = font # if it does not raise AttributeError, we guessed correctly, can set the ttf attr here
104+ # if it does not raise AttributeError, we guessed correctly, can set the ttf attr here
105+ self .ttf = font
97106 except AttributeError :
98107 # if above attempt to call TTFont attribute raises AttributeError (as it would with string file path)
99108 # then instantiate a ttLib.TTFont object and define the fontpath attribute with the file path string
@@ -155,8 +164,14 @@ def __str__(self):
155164
156165 :return: (string)
157166 """
158- return "<fontv.libfv.FontVersion> " + os .linesep + self .get_name_id5_version_string () + os .linesep + "file path:" \
159- " " + self .fontpath
167+ return (
168+ "<fontv.libfv.FontVersion> "
169+ + os .linesep
170+ + self .get_name_id5_version_string ()
171+ + os .linesep
172+ + "file path:"
173+ " " + self .fontpath
174+ )
160175
161176 # TODO: confirm comparisons of version numbers like "Version 1.001", "Version 1.01", "Version 1.1" as not the same
162177 # TODO: before this is released. Will need to be documented as such because this is not obvious behavior
@@ -187,9 +202,9 @@ def _parse(self):
187202 :return: None
188203 """
189204 # metadata parsing
190- self ._parse_metadata () # parse the metadata
191- self ._parse_state () # parse the state substring data
192- self ._parse_status () # parse the version substring dev/rel status indicator data
205+ self ._parse_metadata () # parse the metadata
206+ self ._parse_state () # parse the state substring data
207+ self ._parse_status () # parse the version substring dev/rel status indicator data
193208
194209 def _read_version_string (self ):
195210 """
@@ -200,7 +215,7 @@ def _read_version_string(self):
200215 """
201216
202217 # Read the name.ID=5 record
203- namerecord_list = self .ttf [' name' ].names
218+ namerecord_list = self .ttf [" name" ].names
204219 # read in name records
205220 for record in namerecord_list :
206221 if record .nameID == 5 :
@@ -211,7 +226,9 @@ def _read_version_string(self):
211226 # assert that at least one nameID 5 record was obtained from the font in order to instantiate
212227 # a FontVersion object
213228 if len (self .name_ID5_dict ) == 0 :
214- raise IndexError ("Unable to read nameID 5 version records from the font " + self .fontpath )
229+ raise IndexError (
230+ "Unable to read nameID 5 version records from the font " + self .fontpath
231+ )
215232
216233 # define the version string from the dictionary
217234 for vs in self .name_ID5_dict .values ():
@@ -225,7 +242,7 @@ def _read_version_string(self):
225242 self .version = self .version_string_parts [0 ]
226243
227244 # Read the head.fontRevision record (stored as a float)
228- self .head_fontRevision = self .ttf [' head' ].fontRevision
245+ self .head_fontRevision = self .ttf [" head" ].fontRevision
229246
230247 self ._parse () # update FontVersion object attributes based upon the data read in
231248
@@ -240,10 +257,12 @@ def _get_repo_commit(self):
240257 gitpy = repo .git
241258 # git rev-list --abbrev-commit --max-count=1 --format="%h" HEAD - abbreviated unique sha1 for the repository
242259 # number of sha1 hex characters determined by git (addresses https://github.com/source-foundry/font-v/issues/2)
243- full_git_sha_string = gitpy .rev_list ('--abbrev-commit' , '--max-count=1' , '--format="%h"' , 'HEAD' )
260+ full_git_sha_string = gitpy .rev_list (
261+ "--abbrev-commit" , "--max-count=1" , '--format="%h"' , "HEAD"
262+ )
244263 unicode_full_sha_string = tounicode (full_git_sha_string )
245264 sha_string_list = unicode_full_sha_string .split ("\n " )
246- final_sha_string = sha_string_list [1 ].replace ('"' , '' )
265+ final_sha_string = sha_string_list [1 ].replace ('"' , "" )
247266 return final_sha_string
248267
249268 def _parse_metadata (self ):
@@ -256,8 +275,9 @@ def _parse_metadata(self):
256275 :return: None
257276 """
258277 if len (self .version_string_parts ) > 1 :
259- self .contains_metadata = True # set to True if there are > 1 sub strings as others are defined as metadata
260- self .metadata = [] # reset to empty and allow following code to define the list items
278+ # set to True if there are > 1 sub strings as others are defined as metadata
279+ self .contains_metadata = True
280+ self .metadata = [] # reset to empty and allow following code to define the list items
261281 for metadata_item in self .version_string_parts [1 :]:
262282 self .metadata .append (metadata_item )
263283 else :
@@ -278,7 +298,9 @@ def _parse_state(self):
278298 # Test for regular expression pattern match for state substring at version string list position 1
279299 # as defined by OpenFV specification.
280300 # This method call returns tuple of (truth test for match, matched state string (or empty string))
281- response = self ._is_state_substring_return_state_match (self .version_string_parts [1 ])
301+ response = self ._is_state_substring_return_state_match (
302+ self .version_string_parts [1 ]
303+ )
282304 is_state_substring = response [0 ]
283305 state_substring_match = response [1 ]
284306 if is_state_substring is True :
@@ -302,8 +324,10 @@ def _parse_status(self):
302324 :return: None
303325 """
304326 if len (self .version_string_parts ) > 1 :
305- status_needle = self .version_string_parts [1 ] # define as list item 1 as per OpenFV specification
306- self .contains_status = False # reset each time there is a parse attempt and let logic below define
327+ # define as list item 1 as per OpenFV specification
328+ status_needle = self .version_string_parts [1 ]
329+ # reset each time there is a parse attempt and let logic below define
330+ self .contains_status = False
307331
308332 if self ._is_development_substring (status_needle ):
309333 self .contains_status = True
@@ -354,15 +378,27 @@ def _set_state_status_substring(self, state_status_string):
354378 prestring = self .version_string_parts [1 ]
355379 state_response = self ._is_state_substring_return_state_match (prestring )
356380 is_state_substring = state_response [0 ]
357- if self ._is_release_substring (prestring ) or self ._is_development_substring (prestring ) or is_state_substring :
381+ if (
382+ self ._is_release_substring (prestring )
383+ or self ._is_development_substring (prestring )
384+ or is_state_substring
385+ ):
358386 # directly replace when existing status substring
359387 self .version_string_parts [1 ] = state_status_string
360388 else :
361389 # if the second item of the substring list is not a status string, save it and all subsequent list items
362390 # then create a new list with inserted status string value
363- self .version_string_parts = [self .version_string_parts [0 ]] # redefine list as list with version number
364- self .version_string_parts .append (state_status_string ) # define the status substring as next item
365- for item in self .metadata : # iterate through all previous metadata substrings and append to list
391+ self .version_string_parts = [
392+ self .version_string_parts [0 ]
393+ ] # redefine list as list with version number
394+ self .version_string_parts .append (
395+ state_status_string
396+ ) # define the status substring as next item
397+ for (
398+ item
399+ ) in (
400+ self .metadata
401+ ): # iterate through all previous metadata substrings and append to list
366402 self .version_string_parts .append (item )
367403 else :
368404 # if the version string is defined as only a version number substring (i.e. list size = 1),
@@ -383,7 +419,10 @@ def _is_development_substring(self, needle):
383419
384420 :return: boolean True = is development substring and False = is not a development substring
385421 """
386- if self .develop_string == needle .strip () or self .sha1_develop in needle [- len (self .sha1_develop ):]:
422+ if (
423+ self .develop_string == needle .strip ()
424+ or self .sha1_develop in needle [- len (self .sha1_develop ):]
425+ ):
387426 return True
388427 else :
389428 return False
@@ -399,7 +438,10 @@ def _is_release_substring(self, needle):
399438
400439 :return: boolean True = is release substring and False = is not a release substring
401440 """
402- if self .release_string == needle .strip () or self .sha1_release in needle [- len (self .sha1_release ):]:
441+ if (
442+ self .release_string == needle .strip ()
443+ or self .sha1_release in needle [- len (self .sha1_release ):]
444+ ):
403445 return True
404446 else :
405447 return False
@@ -474,7 +516,9 @@ def get_version_number_tuple(self):
474516 version_number_string = match .group (0 )
475517 version_number_list = version_number_string .split ("." )
476518 version_number_major_int = int (version_number_list [0 ])
477- version_number_int_list .append (version_number_major_int ) # add major version integer
519+ version_number_int_list .append (
520+ version_number_major_int
521+ ) # add major version integer
478522
479523 for minor_int in version_number_list [1 ]:
480524 version_number_int_list .append (int (minor_int ))
@@ -491,7 +535,7 @@ def get_head_fontrevision_version_number(self):
491535 """
492536 return self .head_fontRevision
493537
494- # TODO: remove this deprecated method (commented out in v0.7.0)
538+ # TODO: remove this deprecated method (commented out in v0.7.0, deprecation warnings in v0.6.0 )
495539 # def get_version_string(self):
496540 # """
497541 # DEPRECATED: Please convert to use of FontVersion.get_name_id5_version_string() method
@@ -572,15 +616,21 @@ def set_state_git_commit_sha1(self, development=False, release=False):
572616 git_sha1_hash_formatted = "[" + git_sha1_hash + "]"
573617
574618 if development and release :
575- raise ValueError ("Cannot set both development parameter and release parameter to a value of True in "
576- "fontv.libfv.FontVersion.set_state_git_commit_sha1() method. These are mutually "
577- "exclusive." )
578-
579- if development : # if request for development status label, append FontVersion.sha1_develop to hash digest
619+ raise ValueError (
620+ "Cannot set both development parameter and release parameter to a value of True in "
621+ "fontv.libfv.FontVersion.set_state_git_commit_sha1() method. These are mutually "
622+ "exclusive."
623+ )
624+
625+ if (
626+ development
627+ ): # if request for development status label, append FontVersion.sha1_develop to hash digest
580628 hash_substring = git_sha1_hash_formatted + self .sha1_develop
581- elif release : # if request for release status label, append FontVersion.sha1_release to hash digest
629+ elif (
630+ release
631+ ): # if request for release status label, append FontVersion.sha1_release to hash digest
582632 hash_substring = git_sha1_hash_formatted + self .sha1_release
583- else : # else just use the hash digest
633+ else : # else just use the hash digest
584634 hash_substring = git_sha1_hash_formatted
585635
586636 self ._set_state_status_substring (hash_substring )
@@ -625,8 +675,8 @@ def set_version_number(self, version_number):
625675 """
626676 version_number_substring = "Version " + version_number
627677 self .version_string_parts [0 ] = version_number_substring
628- self .version = self .version_string_parts [0 ] # "Version X.XXX"
629- self .head_fontRevision = float (version_number ) # X.XXX
678+ self .version = self .version_string_parts [0 ] # "Version X.XXX"
679+ self .head_fontRevision = float (version_number ) # X.XXX
630680 self ._parse ()
631681
632682 def set_version_string (self , version_string ):
@@ -671,14 +721,14 @@ def write_version_string(self, fontpath=None):
671721 """
672722 # Write to name table ID 5 record
673723 version_string = self .get_name_id5_version_string ()
674- namerecord_list = self .ttf [' name' ].names
724+ namerecord_list = self .ttf [" name" ].names
675725 for record in namerecord_list :
676726 if record .nameID == 5 :
677727 # write to fonttools ttLib object name ID 5 table record for each nameID 5 record found in the font
678728 record .string = version_string
679729
680730 # Write version number to head table fontRevision record
681- self .ttf [' head' ].fontRevision = self .head_fontRevision
731+ self .ttf [" head" ].fontRevision = self .head_fontRevision
682732
683733 # Write changes out to the font binary path
684734 if fontpath is None :
0 commit comments