version
frequenz.repo.config.version ¤
Version information for a repository.
This module provides the
RepoVersionInfo
class to get information
about the repository version.
It handles many scenarios and queries, like:
- Is the current commit a tag or a branch?
- Is the current tag the latest tag?
- Is the current branch the latest branch?
- Is the current tag the last minor version for the major version?
- What is the next minor version for the current major branch?
- etc.
Repository tag names are expected to follow the semantic versioning
specification, but usually with a leading v
(e.g. v1.0.0
).
to_semver()
can be used to convert a version
string to a semantic version, even if it has a leading v
.
Repository branch names can be parsed with
BranchVersion.parse()
and are
expected follow the format:
vX.x.x
for major branches, whereX
is the major version number. For example,v1.x.x
is the major branch for the major version 1.
It represents an in-development major version, from which new minor branches including new features are created (including the first minor branch for the major version).
vX.Y.x
for minor branches, whereX
is the major version number andY
is the minor version number. For example,v1.0.x
is the minor branch for the major version 1 and minor version 0.
It represents a maintained minor version, from which new patch releases (with bug
fixes) are created. For example, v1.1.x
is the minor branch for the major version 1
and minor version 1.
Classes¤
frequenz.repo.config.version.BranchVersion
dataclass
¤
A branch version.
Versions can be compared with each other. If minor
is None
, it is considered to
be greater than any other minor
.
Source code in frequenz/repo/config/version.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
Attributes¤
Functions¤
__lt__ ¤
__lt__(other: BranchVersion) -> bool
Compare two branch version information.
If minor
is None
, it is considered to be greater than any other minor
.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other branch version information.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the current branch version information is less than the other. |
Source code in frequenz/repo/config/version.py
__post_init__ ¤
parse
classmethod
¤
Parse a branch name.
See the module documentation for the expected format of the branch name.
PARAMETER | DESCRIPTION |
---|---|
branch
|
The branch name.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self | None
|
The parsed branch version information or None if the branch name is not a valid branch name. |
Source code in frequenz/repo/config/version.py
frequenz.repo.config.version.RepoVersionInfo ¤
The information about a repository version.
The information includes if it is a tag, a branch, if tags and branches are well formed, the next minor version, etc.
This assumes tags follow semantic versioning and branches are in the form
"v
New minor releases are branched from a major branch, also creating a minor branch for patch releases for that minor. For example, if the current major version is 1, the current major branch is "v1.x.x" and the current minor branch is "v1.0.x". If the next minor version is 1.1, the new minor branch will be "v1.1.x".
Source code in frequenz/repo/config/version.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
|
Attributes¤
branches
property
¤
branches: dict[str, BranchVersion]
The branches of the repository.
The key is the branch name and the value is the parsed branch name.
current_branch
property
¤
current_branch: BranchVersion | None
The branch pointing to the current commit.
None
if there is no current branch or the name is invalid.
current_tag
property
¤
The tag pointing to the current commit.
None
if there is no tag or the name is invalid.
tags
property
¤
The tags of the repository.
The key is the tag name and the value is the parsed tag (semantic) version.
Functions¤
__init__ ¤
__init__(
sha: str,
ref: str,
tags: list[str] | None = None,
branches: list[str] | None = None,
) -> None
Initialize the environment variables.
PARAMETER | DESCRIPTION |
---|---|
sha
|
The current commit hash.
TYPE:
|
ref
|
The current reference full path (e.g.
TYPE:
|
tags
|
The tags of the repository. |
branches
|
The branches of the repository. |
Source code in frequenz/repo/config/version.py
find_last_tag ¤
Find the last tag.
RETURNS | DESCRIPTION |
---|---|
Version | None
|
If we are at a tag, return the current
tag. If we
are at a branch, return the last tag matching the branch major and minor
(if any). If there are no matching tags, return |
Source code in frequenz/repo/config/version.py
find_next_breaking_branch ¤
find_next_breaking_branch() -> BranchVersion | None
Find the next branch potentially introducing breaking changes.
RETURNS | DESCRIPTION |
---|---|
BranchVersion | None
|
If there is a last tag, use that as a base, otherwise use the current branch
as a base. If none is available, return |
Source code in frequenz/repo/config/version.py
find_next_minor_for_major_branch ¤
find_next_minor_for_major_branch() -> int | None
Find the next minor version for the current major branch.
RETURNS | DESCRIPTION |
---|---|
int | None
|
The next minor version or |
Source code in frequenz/repo/config/version.py
is_branch_latest ¤
is_branch_latest() -> bool
Tell whether the current branch is the latest.
The latest branch is the branch with the biggest major and minor, but if minor
is None
, then it is considered the biggest minor.
Source code in frequenz/repo/config/version.py
is_tag_last_minor_for_major ¤
is_tag_last_minor_for_major() -> bool
Tell whether the current tag is the last minor version for the major version.
If we are not at a tag or there are not tags in the repo, return False
.
If the current_tag
is a pre-release, only pre-release tags are considered and
if is not a pre-release, only stable tags are considered.
Source code in frequenz/repo/config/version.py
is_tag_latest ¤
is_tag_latest() -> bool
Tell whether the current tag is the latest tag.
The latest tag is the tag with the biggest major, minor and patch version. If the current tag is a prerelease, then only prereleases are used to determine the biggest.
Sorting is always according to semver.
Source code in frequenz/repo/config/version.py
Functions¤
frequenz.repo.config.version.strip_v ¤
frequenz.repo.config.version.to_semver ¤
to_semver(version: str) -> Version | None
Convert a version string to a semantic version.
PARAMETER | DESCRIPTION |
---|---|
version
|
The version string.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Version | None
|
The semantic version or |