1212logger = logging .getLogger (__name__ )
1313
1414DATE_FMT = "%Y-%m-%d %H:%M:%S %z"
15- DEFAULT_TAG_WHITELIST = r"^.* $"
16- DEFAULT_BRANCH_WHITELIST = r"^.*$ "
15+ DEFAULT_TAG_WHITELIST = r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*) $"
16+ DEFAULT_BRANCH_WHITELIST = r"(master|main) "
1717DEFAULT_REMOTE_WHITELIST = None
1818DEFAULT_RELEASED_PATTERN = r"^tags/.*$"
1919DEFAULT_OUTPUTDIR_FORMAT = r"{ref.name}"
4040)
4141
4242
43+ class TagFormatError (Exception ):
44+ """
45+ Exception raised for errors in the tag format.
46+
47+ The exception is raised when a tag is found to be incorrectly formatted.
48+ """
49+
50+
51+ class ExasolVersionTag :
52+
53+ def __init__ (self , version ):
54+ try :
55+ v = version .name .strip ()
56+ parts = v .split ("." )
57+ major , minor , patch = map (int , parts )
58+ except Exception as ex :
59+ msg = f"Invalid tag format: '{ version } ', details: { ex } "
60+ raise TagFormatError (msg ) from ex
61+
62+ self ._version = version
63+ self ._version_tripple = (major , minor , patch )
64+
65+ @property
66+ def version (self ):
67+ return self ._version
68+
69+ @property
70+ def version_triple (self ):
71+ return self ._version_tripple
72+
73+ @staticmethod
74+ def is_valid_tag (tag ):
75+ try :
76+ ExasolVersionTag (tag )
77+ except TagFormatError as ex :
78+ logger .warn ("%s" , ex )
79+ return False
80+ return True
81+
82+
4383class VersionInfo :
4484 def __init__ (self , app , context , metadata , current_version_name ):
4585 self .app = app
@@ -94,30 +134,14 @@ def in_development(self):
94134 ]
95135
96136 def __iter__ (self ):
97- def to_int (v ):
98- if v == '' :
99- return 0
100- return int (v , base = 0 )
101-
102- def version_key (version ):
103- version = version .strip ()
104- parts = version .split ("." )
105- try :
106- major = int (parts [0 ])
107- minor = int (parts [1 ])
108- patch = int (parts [2 ])
109- except ValueError as ex :
110- # TODO: skip tag and log that it was skipped
111- print (f'version:{ version } <<' )
112- print (f'parts:{ parts } <<' )
113- print (ex )
114- return (
115- major ,
116- minor ,
117- patch
118- )
137+ tags = (
138+ ExasolVersionTag (tag )
139+ for tag in self .tags if ExasolVersionTag .is_valid_tag (tag )
140+ )
119141 yield from self .branches
120- yield from sorted (self .tags , key = lambda v : version_key (v .name ), reverse = True )
142+ yield from [
143+ t .version for t in sorted (tags , key = lambda t : t .version_triple , reverse = True )
144+ ]
121145
122146 def __getitem__ (self , name ):
123147 v = self .metadata .get (name )
@@ -143,19 +167,22 @@ def vpathto(self, other_version_name):
143167 other_outputroot = os .path .abspath (other_version ["outputdir" ])
144168 outputroot = os .path .commonpath ((current_outputroot , other_outputroot ))
145169
146- current_outputroot = os .path .relpath (current_outputroot , start = outputroot )
170+ current_outputroot = os .path .relpath (
171+ current_outputroot , start = outputroot )
147172 other_outputroot = os .path .relpath (other_outputroot , start = outputroot )
148173
149174 # Ensure that we use POSIX separators in the path (for the HTML code)
150175 if os .sep != posixpath .sep :
151- current_outputroot = posixpath .join (* os .path .split (current_outputroot ))
176+ current_outputroot = posixpath .join (
177+ * os .path .split (current_outputroot ))
152178 other_outputroot = posixpath .join (* os .path .split (other_outputroot ))
153179
154180 # Find relative path to root of other_version's outputdir
155181 current_outputdir = posixpath .dirname (
156182 posixpath .join (current_outputroot , self .context ["pagename" ])
157183 )
158- other_outputdir = posixpath .relpath (other_outputroot , start = current_outputdir )
184+ other_outputdir = posixpath .relpath (
185+ other_outputroot , start = current_outputdir )
159186
160187 if not self .vhasdoc (other_version_name ):
161188 return posixpath .join (other_outputdir , "index.html" )
@@ -257,10 +284,14 @@ def setup(app):
257284 app .add_config_value ("smv_current_version" , "" , "html" )
258285 app .add_config_value ("smv_latest_version" , "master" , "html" )
259286 app .add_config_value ("smv_tag_whitelist" , DEFAULT_TAG_WHITELIST , "html" )
260- app .add_config_value ("smv_branch_whitelist" , DEFAULT_BRANCH_WHITELIST , "html" )
261- app .add_config_value ("smv_remote_whitelist" , DEFAULT_REMOTE_WHITELIST , "html" )
262- app .add_config_value ("smv_released_pattern" , DEFAULT_RELEASED_PATTERN , "html" )
263- app .add_config_value ("smv_outputdir_format" , DEFAULT_OUTPUTDIR_FORMAT , "html" )
287+ app .add_config_value ("smv_branch_whitelist" ,
288+ DEFAULT_BRANCH_WHITELIST , "html" )
289+ app .add_config_value ("smv_remote_whitelist" ,
290+ DEFAULT_REMOTE_WHITELIST , "html" )
291+ app .add_config_value ("smv_released_pattern" ,
292+ DEFAULT_RELEASED_PATTERN , "html" )
293+ app .add_config_value ("smv_outputdir_format" ,
294+ DEFAULT_OUTPUTDIR_FORMAT , "html" )
264295 app .add_config_value ("smv_build_targets" , DEFAULT_BUILD_TARGETS , "html" )
265296 app .add_config_value (
266297 "smv_clean_intermediate_files" ,
0 commit comments