@@ -47,12 +47,12 @@ <h1 class="title">Module <code>continuous_delivery_scripts.generate_news</code><
4747from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
4848from continuous_delivery_scripts.utils.logging import log_exception, set_log_level
4949from continuous_delivery_scripts.utils.filesystem_helpers import cd
50- from typing import Optional, Tuple
50+ from typing import Optional, Tuple, Dict
5151
5252logger = logging.getLogger(__name__)
5353
5454
55- def version_project(commit_type: CommitType) -> Tuple[bool, Optional[str]]:
55+ def version_project(commit_type: CommitType) -> Tuple[bool, Optional[str], Dict[str, str] ]:
5656 """Versions the project.
5757
5858 Args:
@@ -63,12 +63,12 @@ <h1 class="title">Module <code>continuous_delivery_scripts.generate_news</code><
6363 (is new version, the new version)
6464 """
6565 use_news_files = commit_type in [CommitType.BETA, CommitType.RELEASE]
66- is_new_version, new_version = _calculate_version(commit_type, use_news_files)
66+ is_new_version, new_version, version_elements = _calculate_version(commit_type, use_news_files)
6767 _generate_changelog(new_version, use_news_files)
68- return is_new_version, new_version
68+ return is_new_version, new_version, version_elements
6969
7070
71- def _calculate_version(commit_type: CommitType, use_news_files: bool) -> Tuple[bool, Optional[str]]:
71+ def _calculate_version(commit_type: CommitType, use_news_files: bool) -> Tuple[bool, Optional[str], Dict[str, str] ]:
7272 """Calculates the version for the release.
7373
7474 eg. "0.1.2"
@@ -99,13 +99,44 @@ <h1 class="title">Module <code>continuous_delivery_scripts.generate_news</code><
9999 # Autoversion second returned value is not actually the new version
100100 # There seem to be a bug in autoversion.
101101 # This is why the following needs to be done to determine the version
102- for k, v in updates.items():
103- if "version" in str(k).lower():
104- new_version = updates[k]
102+ version_elements = _get_version_elements(updates)
103+ new_version = version_elements.get(auto_version_tool.Constants.VERSION_FIELD, new_version)
105104 is_new_version = old != new_version
106105 logger.info(":: Determining the new version")
107106 logger.info(f"Version: {new_version}")
108- return is_new_version, new_version
107+ return is_new_version, new_version, version_elements
108+
109+
110+ def _update_version_string(
111+ commit_type: CommitType, new_version: Optional[str], version_elements: Dict[str, str]
112+ ) -> Optional[str]:
113+ """Updates the version string for development releases.
114+
115+ Args:
116+ commit_type: commit type
117+ new_version: the new version
118+ version_elements: version elements
119+ """
120+ if commit_type == CommitType.DEVELOPMENT:
121+ return "%s-%s.%s" % (
122+ new_version,
123+ auto_version_tool.config.BUILD_TOKEN,
124+ version_elements.get(auto_version_tool.Constants.COMMIT_FIELD),
125+ )
126+ return new_version
127+
128+
129+ def _get_version_elements(native_version_elements: Dict[str, str]) -> Dict[str, str]:
130+ """Determines the different version elements.
131+
132+ Args:
133+ native_version_elements: native version elements as understood by autoversion
134+ """
135+ return {
136+ key: native_version_elements[native]
137+ for native, key in auto_version_tool.config.key_aliases.items()
138+ if native in native_version_elements
139+ }
109140
110141
111142def _generate_changelog(version: Optional[str], use_news_files: bool) -> None:
@@ -135,7 +166,10 @@ <h1 class="title">Module <code>continuous_delivery_scripts.generate_news</code><
135166 set_log_level(args.verbose)
136167
137168 try:
138- version_project(CommitType.parse(args.release_type))
169+ commit_type = CommitType.parse(args.release_type)
170+ is_new_version, new_version, version_elements = version_project(commit_type)
171+ version_to_print = _update_version_string(commit_type, new_version, version_elements)
172+ print(version_to_print)
139173 except Exception as e:
140174 log_exception(logger, e)
141175 sys.exit(1)
@@ -172,14 +206,17 @@ <h2 class="section-title" id="header-functions">Functions</h2>
172206 set_log_level(args.verbose)
173207
174208 try:
175- version_project(CommitType.parse(args.release_type))
209+ commit_type = CommitType.parse(args.release_type)
210+ is_new_version, new_version, version_elements = version_project(commit_type)
211+ version_to_print = _update_version_string(commit_type, new_version, version_elements)
212+ print(version_to_print)
176213 except Exception as e:
177214 log_exception(logger, e)
178215 sys.exit(1)</ code > </ pre >
179216</ details >
180217</ dd >
181218< dt id ="continuous_delivery_scripts.generate_news.version_project "> < code class ="name flex ">
182- < span > def < span class ="ident "> version_project</ span > </ span > (< span > commit_type: < a title ="continuous_delivery_scripts.utils.definitions.CommitType " href ="utils/definitions.html#continuous_delivery_scripts.utils.definitions.CommitType "> CommitType</ a > ) ‑> Tuple[bool, Union[str, NoneType]]</ span >
219+ < span > def < span class ="ident "> version_project</ span > </ span > (< span > commit_type: < a title ="continuous_delivery_scripts.utils.definitions.CommitType " href ="utils/definitions.html#continuous_delivery_scripts.utils.definitions.CommitType "> CommitType</ a > ) ‑> Tuple[bool, Union[str, NoneType], Dict[str, str] ]</ span >
183220</ code > </ dt >
184221< dd >
185222< div class ="desc "> < p > Versions the project.</ p >
@@ -194,7 +231,7 @@ <h2 id="returns">Returns</h2>
194231< summary >
195232< span > Expand source code</ span >
196233</ summary >
197- < pre > < code class ="python "> def version_project(commit_type: CommitType) -> Tuple[bool, Optional[str]]:
234+ < pre > < code class ="python "> def version_project(commit_type: CommitType) -> Tuple[bool, Optional[str], Dict[str, str] ]:
198235 """Versions the project.
199236
200237 Args:
@@ -205,9 +242,9 @@ <h2 id="returns">Returns</h2>
205242 (is new version, the new version)
206243 """
207244 use_news_files = commit_type in [CommitType.BETA, CommitType.RELEASE]
208- is_new_version, new_version = _calculate_version(commit_type, use_news_files)
245+ is_new_version, new_version, version_elements = _calculate_version(commit_type, use_news_files)
209246 _generate_changelog(new_version, use_news_files)
210- return is_new_version, new_version</ code > </ pre >
247+ return is_new_version, new_version, version_elements </ code > </ pre >
211248</ details >
212249</ dd >
213250</ dl >
0 commit comments