1414 DATA_DIR ,
1515 PLATFORMS ,
1616 REQUESTS_TIMEOUT ,
17- tags_data_load ,
1817 get_latest_release_from_url ,
1918)
2019
@@ -46,6 +45,8 @@ def __init__(self, repo):
4645 # tag
4746 self ._current = None
4847 self ._latest = None
48+ self .pinned_tag = None
49+ self ._available = []
4950
5051 def lib_dir (self , platform ):
5152 """
@@ -99,21 +100,27 @@ def requirements_for(self, library_name, toml_file=False):
99100 @property
100101 def current_tag (self ):
101102 """
102- Lazy load current cached tag from the BUNDLE_DATA json file.
103+ The current tag for the project. If the tag hasn't been explicitly set
104+ this will be the pinned tag, if one is set. If there is no pinned tag,
105+ this will be the latest available tag that is locally available.
103106
104- :return: The current cached tag value for the project.
107+ :return: The current tag value for the project.
105108 """
106109 if self ._current is None :
107- self ._current = tags_data_load (logger ).get (self .key , "0" )
110+ self ._current = self .pinned_tag or (
111+ # This represents the latest version locally available
112+ self ._available [- 1 ]
113+ if len (self ._available ) > 0
114+ else None
115+ )
108116 return self ._current
109117
110118 @current_tag .setter
111119 def current_tag (self , tag ):
112120 """
113- Set the current cached tag (after updating).
121+ Set the current tag (after updating).
114122
115123 :param str tag: The new value for the current tag.
116- :return: The current cached tag value for the project.
117124 """
118125 self ._current = tag
119126
@@ -130,6 +137,48 @@ def latest_tag(self):
130137 )
131138 return self ._latest
132139
140+ @property
141+ def available_tags (self ):
142+ """
143+ The locally available tags to use for the project.
144+
145+ :return: All tags available for the project.
146+ """
147+ return tuple (self ._available )
148+
149+ @available_tags .setter
150+ def available_tags (self , tags ):
151+ """
152+ Set the available tags.
153+
154+ :param str|list tags: The new value for the locally available tags.
155+ """
156+ if isinstance (tags , str ):
157+ tags = [tags ]
158+ self ._available = sorted (tags )
159+
160+ def add_tag (self , tag : str ) -> None :
161+ """
162+ Add a tag to the list of available tags.
163+
164+ This will add the tag if it isn't already present in the list of
165+ available tags. The tag will be added so that the list is sorted in an
166+ increasing order. This ensures that that last tag is always the latest.
167+
168+ :param str tag: The tag to add to the list of available tags.
169+ """
170+ if tag in self ._available :
171+ # The tag is already stored for some reason, lets not add it again
172+ return
173+
174+ for rev_i , available_tag in enumerate (reversed (self ._available )):
175+ if int (tag ) > int (available_tag ):
176+ i = len (self ._available ) - rev_i
177+ self ._available .insert (i , tag )
178+ break
179+ else :
180+ self ._available .insert (0 , tag )
181+
133182 def validate (self ):
134183 """
135184 Test the existence of the expected URLs (not their content)
@@ -166,5 +215,7 @@ def __repr__(self):
166215 "url_format" : self .url_format ,
167216 "current" : self ._current ,
168217 "latest" : self ._latest ,
218+ "pinned" : self .pinned_tag ,
219+ "available" : self ._available ,
169220 }
170221 )
0 commit comments