lastversion.py
This is the main module of lastversion package. To use it, import it and invoke any function documented here. For example:
from lastversion import lastversion
lastversion.has_update(repo='mautic/mautic', current_version='1.2.3')
build_changelog_bullets(res, repo_arg)
¤
Build changelog bullets for a release dict using upstream notes and OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
dict
|
Release metadata containing upstream notes. |
required |
repo_arg
|
str
|
Repository identifier used for the release lookup. |
required |
Returns:
| Type | Description |
|---|---|
Optional[List[str]]
|
Optional[List[str]]: Generated changelog bullets, or None when notes are unavailable or generation fails. |
Source code in src/lastversion/lastversion.py
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
check_version(value)
¤
Given a version string, raises argparse.ArgumentTypeError if it does not contain any version. In lastversion CLI app, this is used as argument parser helper for --newer-than (-gt) option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Free-format string which is meant to contain a user-supplied version |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Exception in a case version was not found in the input string |
Returns:
| Name | Type | Description |
|---|---|---|
Version |
Version
|
Parsed version object |
Source code in src/lastversion/lastversion.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | |
clear_cache(repo=None)
¤
Clear the HTTP cache for lastversion.
This function is useful for webhook handlers that need to invalidate cache when a new release is published.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
str
|
Optional repository identifier (e.g., "owner/repo"). If provided, attempts to clear cache for that repo only. If None, clears the entire cache. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of cache entries cleared (or 1 for full cache clear) |
Example
In a webhook handler for GitHub release events:¤
from lastversion import clear_cache, latest
def handle_github_webhook(payload): repo = payload.get("repository", {}).get("full_name") clear_cache(repo) # Optionally fetch fresh version version = latest(repo, output_format='json') return version
Source code in src/lastversion/lastversion.py
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 | |
expand_spec_macros(value, macros)
¤
Expand %{macro} / %macro references using macros defined in the spec.
Unknown macros are left as-is. Nested definitions are resolved with a bounded number of passes so self-referencing macros cannot loop forever.
Source code in src/lastversion/lastversion.py
63 64 65 66 67 68 69 70 71 72 73 74 | |
find_preferred_url(spec_urls)
¤
Given a list of URLs of a project, return preferred one that might lead to version info. Basically returns the first URL that matches a handler by matching its primary domain.
Source code in src/lastversion/lastversion.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
get_repo_data_from_spec(rpmspec_filename)
¤
Extract repo data and CLI args from a spec file.
The project (repo) is specified inside the .spec file GitHub repo is resolved via %{upstream_github} + %{name}/%{upstream_name} No upstream_github global means that the spec was not prepared for lastversion Optional: use of spec_tag macros if the source is from GitHub. In edge cases we check new version via GitHub, but prepared sources are elsewhere
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rpmspec_filename
|
str
|
Path to the RPM spec file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Repository metadata and CLI options parsed from the spec file. |
Source code in src/lastversion/lastversion.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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 | |
get_repo_data_from_yml(repo)
¤
Get repo data from YAML file.
Source code in src/lastversion/lastversion.py
205 206 207 208 209 210 211 212 213 214 215 216 | |
get_rpm_packager()
¤
Get RPM packager name from ~/.rpmmacros
Source code in src/lastversion/lastversion.py
568 569 570 571 572 573 574 575 576 577 578 | |
has_update(repo, current_version, pre_ok=False, at=None)
¤
Given an existing version for a repo, checks if there is an update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
str
|
Repository specifier in any form. |
required |
current_version
|
str
|
A version you want to check update for. |
required |
pre_ok
|
bool
|
Specifies whether pre-releases can be accepted as a newer version. |
False
|
at
|
str
|
Specifies repo hosting more precisely, only useful if repo argument was specified as one word. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Version |
Union[Version, bool]
|
Newer version as an object, if found. Otherwise, False |
Source code in src/lastversion/lastversion.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | |
install_app_image(url, install_name)
¤
Install an AppImage from a URL to ~/Applications/<install_name>
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL where AppImage file is hosted |
required |
install_name
|
str
|
Short name that the AppImage will be renamed to |
required |
Source code in src/lastversion/lastversion.py
815 816 817 818 819 820 821 822 823 824 825 | |
install_debs(_res, debs, args)
¤
Install deb packages using apt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_res
|
dict
|
Release metadata, unused but kept for API consistency with install_rpms. |
required |
debs
|
List[str]
|
Debian package URLs to download and install. |
required |
args
|
Namespace
|
Parsed CLI arguments. |
required |
Source code in src/lastversion/lastversion.py
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 | |
install_release(res, args)
¤
Install latest release.
Prefers native package formats (RPM/deb) over AppImages for better integration with package managers and architecture compatibility.
Source code in src/lastversion/lastversion.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | |
install_rpms(res, rpms, args)
¤
Install RPMs using package manager
Source code in src/lastversion/lastversion.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
install_standalone_binary(url, install_name)
¤
Install a standalone binary from a URL to ~/Applications/<install_name>
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL where the binary file is hosted |
required |
install_name
|
str
|
Filename that the binary will be renamed to |
required |
Source code in src/lastversion/lastversion.py
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 | |
latest(repo, output_format='version', pre_ok=False, assets_filter=None, short_urls=False, major=None, only=None, at=None, having_asset=None, exclude=None, even=False, formal=False, changelog=False, cache_ttl=None, skip_release_cache=False)
¤
Find the latest release version for a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
major
|
str
|
Only consider versions which are "descendants" of this major version string |
None
|
short_urls
|
bool
|
Whether we should try to return shorter URLs for release data |
False
|
assets_filter
|
Union[str, Pattern]
|
Regular expression for filtering assets for the latest release |
None
|
only
|
str
|
Only consider tags with this text. Useful for repos with multiple projects.
The argument supports negation and regular expressions. To indicate a regex,
start it with tilde sign, to negate the expression, start it with exclamation
point. See |
None
|
repo
|
str
|
Repository specifier in any form. |
required |
output_format
|
str
|
Affects the return format. Possible values |
'version'
|
pre_ok
|
bool
|
Specifies whether pre-releases can be accepted as a newer version. |
False
|
at
|
str
|
Specifies repo hosting more precisely, only useful if repo argument was specified as one word. |
None
|
having_asset
|
Union[str, bool]
|
Only consider releases with the given asset.
Pass |
None
|
exclude
|
str
|
Only consider releases NOT containing this text/regular expression. |
None
|
even
|
bool
|
Consider as stable only releases with even minor component, e.g. 1.2.3 |
False
|
formal
|
bool
|
Consider as stable only releases with formal tags set up in Web UI |
False
|
changelog
|
bool
|
Populate release["changelog"] using upstream notes (if True) |
False
|
cache_ttl
|
int
|
Optional TTL override for release data cache (seconds). Only used when release cache is enabled in config. |
None
|
skip_release_cache
|
bool
|
Skip the release data cache entirely (both read and write). Useful when you need fresh data from the source. |
False
|
Examples:
Find the latest version of Mautic, it is OK to consider betas.
>>> latest("mautic/mautic", output_format='version', pre_ok=True)
<Version('4.4.4')>
Consider only tags without letters:
>>> latest("openssl/openssl", output_format='version', only=r'!~\w')
<Version('3.0.7')>
Returns:
| Type | Description |
|---|---|
Any
|
Union[Version, dict, str, None]: Release data in the requested format, or None when no matching release is found. |
Source code in src/lastversion/lastversion.py
219 220 221 222 223 224 225 226 227 228 229 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 | |
parse_version(tag)
¤
Parse version to a Version object. Argument may not be a version but a URL or a repo name, in which case return False E.g., used in lastversion repo-name -gt 1.2.3 (and repo-name is passed here as tag)
Source code in src/lastversion/lastversion.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
update_spec_commit(spec_file, commit_info, repo_data)
¤
Update spec file for commit-based (snapshot) releases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec_file
|
str
|
Path to the spec file. |
required |
commit_info
|
dict
|
Commit metadata with sha, short_sha, date, and message fields. |
required |
repo_data
|
dict
|
Repository metadata parsed from the spec file. |
required |
Updates
- %global commit
- %global commit_date
- Release: 0.%{snapinfo}%{?dist} (if no releases) or 1.%{snapinfo}%{?dist}
Source code in src/lastversion/lastversion.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 | |
RPM changelog generation¤
When updating a .spec file, you can ask lastversion to generate a concise RPM %changelog entry from upstream release notes:
lastversion path/to/package.spec --changelog
Environment variables:
OPENAI_API_KEYorLASTVERSION_OPENAI_API_KEYLASTVERSION_OPENAI_MODEL(default:gpt-4o-mini)
Behavior:
- Tries conventional changelog files at the tag (e.g.,
CHANGELOG.md,NEWS) via raw Git first, then falls back to API. - Produces 1–7 short bullets focusing on user-facing changes, fixes, security, and compatibility.
- Falls back to a single line
- upstream release v<version>if upstream notes are unavailable or the API call fails.