@vercel/python 6.32.0 → 6.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/python",
3
- "version": "6.32.0",
3
+ "version": "6.33.1",
4
4
  "main": "./dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
@@ -36,9 +36,9 @@
36
36
  "smol-toml": "1.5.2",
37
37
  "vitest": "2.1.4",
38
38
  "which": "3.0.0",
39
- "@vercel/build-utils": "13.16.0",
40
- "@vercel/python-runtime": "0.12.0",
41
- "@vercel/error-utils": "2.0.3"
39
+ "@vercel/build-utils": "13.17.0",
40
+ "@vercel/error-utils": "2.0.3",
41
+ "@vercel/python-runtime": "0.13.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "node ../../utils/build-builder.mjs",
@@ -0,0 +1,67 @@
1
+ """
2
+ Dynamically detect cron entries by calling get_crons() on a named object.
3
+
4
+ Usage: python -c <script> <module> <attribute>
5
+
6
+ The attribute must be an object with a get_crons() method that returns an
7
+ iterable of (module_function, schedule) pairs, where module_function uses
8
+ "module:function" format and schedule is a 5-field cron expression.
9
+
10
+ Prints JSON to stdout:
11
+ {"entries": [{"module_function": "jobs.cleanup:handler", "schedule": "0 0 * * *"}]}
12
+ On error:
13
+ {"error": "description"}
14
+ """
15
+
16
+ import importlib
17
+ import json
18
+ import sys
19
+ from typing import NoReturn
20
+
21
+
22
+ def _error(msg: str) -> NoReturn:
23
+ print(json.dumps({"error": msg}))
24
+ sys.exit(1)
25
+
26
+
27
+ def main():
28
+ if len(sys.argv) != 3:
29
+ _error(f"Expected 2 arguments (module, attribute), got {len(sys.argv) - 1}")
30
+
31
+ module_name = sys.argv[1]
32
+ attr_name = sys.argv[2]
33
+
34
+ try:
35
+ mod = importlib.import_module(module_name)
36
+ except ImportError as exc:
37
+ _error(f"Failed to import module '{module_name}': {exc}")
38
+
39
+ obj = getattr(mod, attr_name, None)
40
+ if obj is None:
41
+ _error(f"Module '{module_name}' has no attribute '{attr_name}'")
42
+
43
+ fn = getattr(obj, "get_crons", None)
44
+ if fn is None:
45
+ _error(
46
+ f"'{module_name}.{attr_name}' has no 'get_crons' method. "
47
+ f"The cron entrypoint object must define a get_crons() method that "
48
+ f"returns a list of (module:function, schedule) pairs."
49
+ )
50
+
51
+ if not callable(fn):
52
+ _error(f"'{module_name}.{attr_name}.get_crons' is not callable")
53
+
54
+ try:
55
+ result = fn()
56
+ entries = []
57
+ for item in result:
58
+ if not (isinstance(item, (list, tuple)) and len(item) == 2):
59
+ _error(f"Each cron entry must be a (module:function, schedule) pair, got: {item!r}")
60
+ module_function, schedule = item
61
+ entries.append({"module_function": str(module_function), "schedule": str(schedule)})
62
+ print(json.dumps({"entries": entries}))
63
+ except Exception as exc:
64
+ _error(f"Error calling '{module_name}.{attr_name}.get_crons()': {exc}")
65
+
66
+
67
+ main()