3
3
import sys
4
4
from pathlib import Path
5
5
6
- def find_non_path_spacetimedb_deps (dev_deps ):
6
+ def find_non_path_spacetimedb_deps (dev_deps , cargo_toml_path ):
7
7
non_path_spacetimedb = []
8
8
for name , details in dev_deps .items ():
9
9
if not name .startswith ("spacetimedb" ):
@@ -15,10 +15,10 @@ def find_non_path_spacetimedb_deps(dev_deps):
15
15
else :
16
16
# String dependency = version from crates.io
17
17
non_path_spacetimedb .append (name )
18
- return non_path_spacetimedb
18
+ success = not non_path_spacetimedb
19
+ return success , non_path_spacetimedb
19
20
20
- def check_cargo_metadata (data ):
21
- package = data .get ("package" , {})
21
+ def check_cargo_metadata (package , cargo_toml_path ):
22
22
missing_fields = []
23
23
24
24
# Accept either license OR license-file
@@ -28,7 +28,31 @@ def check_cargo_metadata(data):
28
28
if "description" not in package :
29
29
missing_fields .append ("description" )
30
30
31
- return missing_fields
31
+ missing_license_file = None
32
+ if "license-file" in package :
33
+ license_file = package ["license-file" ]
34
+ license_path = cargo_toml_path .parent / license_file
35
+ if not license_path .exists ():
36
+ missing_license_file = license_path
37
+
38
+ success = not missing_fields and not missing_license_file
39
+ return success , missing_fields , missing_license_file
40
+
41
+ def run_checks (data , cargo_toml_path ):
42
+ result = {
43
+ "success" : True ,
44
+ }
45
+
46
+ success , bad_deps = find_non_path_spacetimedb_deps (data .get ("dev-dependencies" , {}), cargo_toml_path )
47
+ result ["success" ] = result ["success" ] and success
48
+ result ["bad_deps" ] = bad_deps
49
+
50
+ success , missing_fields , missing_license_file = check_cargo_metadata (data .get ("package" , {}), cargo_toml_path )
51
+ result ["missing_fields" ] = missing_fields
52
+ result ["missing_license_file" ] = missing_license_file
53
+ result ["success" ] = result ["success" ] and success
54
+
55
+ return result
32
56
33
57
if __name__ == "__main__" :
34
58
parser = argparse .ArgumentParser (description = "Check Cargo.toml for metadata and dev-dependencies." )
@@ -43,29 +67,18 @@ def check_cargo_metadata(data):
43
67
44
68
data = toml .load (cargo_toml_path )
45
69
46
- # Check dev-dependencies
47
- dev_deps = data .get ("dev-dependencies" , {})
48
- bad_deps = find_non_path_spacetimedb_deps (dev_deps )
49
-
50
- # Check license/license-file and description
51
- missing_fields = check_cargo_metadata (data )
52
-
53
- exit_code = 0
54
-
55
- if bad_deps :
56
- print (f"❌ These dev-dependencies in { cargo_toml_path } must be converted to use `path` in order to not impede crate publishing:" )
57
- for dep in bad_deps :
58
- print (f" - { dep } " )
59
- exit_code = 1
60
-
61
- if missing_fields :
62
- print (f"❌ Missing required fields in [package] of { cargo_toml_path } : { ', ' .join (missing_fields )} " )
63
- exit_code = 1
64
-
65
- if exit_code == 0 :
70
+ checks = run_checks (data , cargo_toml_path )
71
+ if checks ["success" ]:
66
72
print (f"✅ { cargo_toml_path } passed all checks." )
67
-
68
- sys .exit (exit_code )
73
+ else :
74
+ print (f"❌ { cargo_toml_path } failed checks:" )
75
+ if checks ["missing_fields" ]:
76
+ print (f" Missing required fields: { ', ' .join (checks ['missing_fields' ])} " )
77
+ if checks ["missing_license_file" ]:
78
+ print (f" Specified license file does not exist: { checks ['missing_license_file' ]} " )
79
+ if checks ["bad_deps" ]:
80
+ print (f" These dev-dependencies must be converted to use `path` in order to not impede crate publishing: { ', ' .join (checks ['bad_deps' ])} " )
81
+ sys .exit (1 )
69
82
70
83
except Exception as e :
71
84
print (f"⚠️ Error: { e } " )
0 commit comments