summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-12-23 08:05:22 +0100
committerMartin Fischer <martin@push-f.com>2021-12-23 08:05:22 +0100
commit71127741d0720b9060b23348bbb92b44af287bce (patch)
tree1a6d36401c70d3f80f2be28e6b62078a66c0edfd
parent4466c97f475f7913dd3f8a31bbe59c2028520927 (diff)
cargo_check.py: handle pre-releases & add docstringHEADmaster
-rwxr-xr-xcargo_check.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/cargo_check.py b/cargo_check.py
index 0246881..d6469e5 100755
--- a/cargo_check.py
+++ b/cargo_check.py
@@ -1,5 +1,12 @@
#!/usr/bin/env python3
-# Written by Martin Fischer <martin@push-f.com> and licensed under MIT.
+"""
+Checks if a Cargo.toml file of a Rust Cargo package has
+dependencies that could be updated. This is different from
+'cargo update' which only performs updates that aren't
+breaking according to semantic versioning.
+
+Written by Martin Fischer <martin@push-f.com> and licensed under MIT.
+"""
from multiprocessing.dummy import Pool
import toml
import requests
@@ -19,13 +26,26 @@ with open('Cargo.toml') as f:
def check_package(info):
name, version = info
res = sess.get('https://crates.io/api/v1/crates/{}'.format(name))
- latest_version = res.json()['versions'][0]
- if latest_version['yanked']:
- print(name, 'was yanked')
- elif not latest_version['num'].startswith(version):
+ all_versions = res.json()['versions']
+
+ # filter semantic versioning pre-releases
+ releases = [v for v in all_versions if not '-' in v['num']]
+
+ if len(releases) == 0:
+ print('[error] {}: all versions are pre-releases'.format(name))
+ return
+
+ latest_release = releases[0]
+
+ if latest_release['yanked']:
+ print('[error] {}: latest release was yanked'.format(name))
+ elif not latest_release['num'].startswith(version):
+ if not any([1 for v in all_versions if v['num'].startswith(version)]):
+ print('[error] {}: version {} does not exist'.format(name, version))
+
print(
- '{} is outdated ({}), {} is available'.format(
- name, version, latest_version['num']
+ '[outdated] {} ({}): {} is available'.format(
+ name, version, latest_release['num']
)
)