callables 0.2.0__tar.gz → 0.3.1__tar.gz
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.
- {callables-0.2.0 → callables-0.3.1}/PKG-INFO +4 -4
- {callables-0.2.0 → callables-0.3.1}/README.md +3 -3
- {callables-0.2.0 → callables-0.3.1}/callables/GUIDE.md +8 -5
- {callables-0.2.0 → callables-0.3.1}/callables/__init__.py +1 -1
- {callables-0.2.0 → callables-0.3.1}/callables/cli.py +22 -1
- {callables-0.2.0 → callables-0.3.1}/callables/decorator.py +2 -2
- callables-0.3.1/callables/envfile.py +56 -0
- {callables-0.2.0 → callables-0.3.1}/callables/files.py +2 -2
- {callables-0.2.0 → callables-0.3.1}/callables/init.py +4 -13
- {callables-0.2.0 → callables-0.3.1}/callables/manifest.py +3 -3
- {callables-0.2.0 → callables-0.3.1}/callables/project.py +8 -6
- {callables-0.2.0 → callables-0.3.1}/callables/runtime.py +5 -5
- {callables-0.2.0 → callables-0.3.1}/callables.egg-info/PKG-INFO +4 -4
- {callables-0.2.0 → callables-0.3.1}/callables.egg-info/SOURCES.txt +2 -2
- {callables-0.2.0 → callables-0.3.1}/callables.egg-info/entry_points.txt +0 -1
- {callables-0.2.0 → callables-0.3.1}/callables.egg-info/top_level.txt +0 -1
- {callables-0.2.0 → callables-0.3.1}/pyproject.toml +1 -2
- {callables-0.2.0 → callables-0.3.1}/tests/test_agent_tools.py +1 -15
- callables-0.3.1/tests/test_envfile.py +113 -0
- {callables-0.2.0 → callables-0.3.1}/tests/test_files.py +5 -5
- {callables-0.2.0 → callables-0.3.1}/tests/test_project.py +17 -7
- {callables-0.2.0 → callables-0.3.1}/tests/test_sdk.py +3 -13
- callables-0.2.0/shipfn/__init__.py +0 -10
- callables-0.2.0/shipfn/__main__.py +0 -5
- {callables-0.2.0 → callables-0.3.1}/LICENSE +0 -0
- {callables-0.2.0 → callables-0.3.1}/callables/__main__.py +0 -0
- {callables-0.2.0 → callables-0.3.1}/callables/checks.py +0 -0
- {callables-0.2.0 → callables-0.3.1}/callables/commands.py +0 -0
- {callables-0.2.0 → callables-0.3.1}/callables/py.typed +0 -0
- {callables-0.2.0 → callables-0.3.1}/callables/schema.py +0 -0
- {callables-0.2.0 → callables-0.3.1}/callables.egg-info/dependency_links.txt +0 -0
- {callables-0.2.0 → callables-0.3.1}/callables.egg-info/requires.txt +0 -0
- {callables-0.2.0 → callables-0.3.1}/setup.cfg +0 -0
- {callables-0.2.0 → callables-0.3.1}/tests/test_command.py +0 -0
- {callables-0.2.0 → callables-0.3.1}/tests/test_groups.py +0 -0
- {callables-0.2.0 → callables-0.3.1}/tests/test_next.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: callables
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Decorate Python functions and push them to Callables: forms, schedules and run history for your team.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Homepage, https://callables.app
|
|
@@ -26,7 +26,7 @@ pip install callables
|
|
|
26
26
|
|
|
27
27
|
Docs: [callables.app/docs](https://callables.app/docs).
|
|
28
28
|
|
|
29
|
-
This installs the `call` command.
|
|
29
|
+
This installs the `call` command.
|
|
30
30
|
|
|
31
31
|
```python
|
|
32
32
|
from typing import Literal
|
|
@@ -42,7 +42,7 @@ def weekly_report(region: Literal["NA", "EMEA", "APAC"] = "NA", days: int = 7) -
|
|
|
42
42
|
- **Results** are shown by return type: `str` as Markdown, `list[dict]` (or a DataFrame) as a table with CSV download, `dict`/Pydantic model as a key-value list, `None` as "done".
|
|
43
43
|
- **Files in**: a `File` parameter becomes an upload field. Your function gets a `File` with `.path`, `.name`, `.read_text()`, `.read_bytes()` and `.open()`. Limit the picker with `Annotated[File, accept(".csv", ".xlsx")]`.
|
|
44
44
|
- **Files out**: return a `File` (or a `list[File]`) and people get download buttons. To hand back files alongside another result, call `save_file(path_or_bytes, name=...)`. Files are kept for 24 hours by default.
|
|
45
|
-
- **Secrets** you list are injected as environment variables at run time (`os.environ["SALES_API_TOKEN"]`); set their values in the Callables console.
|
|
45
|
+
- **Secrets** you list are injected as environment variables at run time (`os.environ["SALES_API_TOKEN"]`); set their values in the Callables console. Locally, `call local` and `call <group> <action>` load the project's `.env` instead (variables already set in your shell win).
|
|
46
46
|
- **Schedules** are cron expressions, in UTC.
|
|
47
47
|
|
|
48
48
|
```python
|
|
@@ -88,7 +88,7 @@ python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
|
88
88
|
.venv/bin/pytest
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
The platform (
|
|
91
|
+
The platform (callables-api) depends on this package and copies the installed version into every build, so a release only reaches deployed functions once the API is updated to it. See [RELEASING.md](RELEASING.md).
|
|
92
92
|
|
|
93
93
|
## License
|
|
94
94
|
|
|
@@ -8,7 +8,7 @@ pip install callables
|
|
|
8
8
|
|
|
9
9
|
Docs: [callables.app/docs](https://callables.app/docs).
|
|
10
10
|
|
|
11
|
-
This installs the `call` command.
|
|
11
|
+
This installs the `call` command.
|
|
12
12
|
|
|
13
13
|
```python
|
|
14
14
|
from typing import Literal
|
|
@@ -24,7 +24,7 @@ def weekly_report(region: Literal["NA", "EMEA", "APAC"] = "NA", days: int = 7) -
|
|
|
24
24
|
- **Results** are shown by return type: `str` as Markdown, `list[dict]` (or a DataFrame) as a table with CSV download, `dict`/Pydantic model as a key-value list, `None` as "done".
|
|
25
25
|
- **Files in**: a `File` parameter becomes an upload field. Your function gets a `File` with `.path`, `.name`, `.read_text()`, `.read_bytes()` and `.open()`. Limit the picker with `Annotated[File, accept(".csv", ".xlsx")]`.
|
|
26
26
|
- **Files out**: return a `File` (or a `list[File]`) and people get download buttons. To hand back files alongside another result, call `save_file(path_or_bytes, name=...)`. Files are kept for 24 hours by default.
|
|
27
|
-
- **Secrets** you list are injected as environment variables at run time (`os.environ["SALES_API_TOKEN"]`); set their values in the Callables console.
|
|
27
|
+
- **Secrets** you list are injected as environment variables at run time (`os.environ["SALES_API_TOKEN"]`); set their values in the Callables console. Locally, `call local` and `call <group> <action>` load the project's `.env` instead (variables already set in your shell win).
|
|
28
28
|
- **Schedules** are cron expressions, in UTC.
|
|
29
29
|
|
|
30
30
|
```python
|
|
@@ -70,7 +70,7 @@ python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
|
70
70
|
.venv/bin/pytest
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
The platform (
|
|
73
|
+
The platform (callables-api) depends on this package and copies the installed version into every build, so a release only reaches deployed functions once the API is updated to it. See [RELEASING.md](RELEASING.md).
|
|
74
74
|
|
|
75
75
|
## License
|
|
76
76
|
|
|
@@ -10,7 +10,7 @@ The person running an automation can't see the code, a traceback or a terminal.
|
|
|
10
10
|
|
|
11
11
|
1. Write or change a function decorated with `@deploy`.
|
|
12
12
|
2. `call check` (or `call check --json`) lists every problem a deploy would hit, with a fix for each. Exit code 1 means the deploy would fail.
|
|
13
|
-
3. `call local <name> -i key=value --json` runs the function on this machine, with the same input validation as the platform.
|
|
13
|
+
3. `call local <name> -i key=value --json` runs the function on this machine, with the same input validation as the platform. It loads the project's `.env` first, so it finds the secrets the platform would give it.
|
|
14
14
|
4. Push. The platform builds and deploys on push.
|
|
15
15
|
|
|
16
16
|
Run `call check` before every push. If any module fails to import, nothing is published.
|
|
@@ -44,7 +44,7 @@ def closed_deals(region: Literal["NA", "EMEA", "APAC"] = "NA", since: date | Non
|
|
|
44
44
|
- `name`: the function's identity on the platform. It defaults to the function name. **Renaming it creates a new automation**, and the old one's history and schedules stay behind. Pass `name="..."` to keep the identity if you rename the Python function.
|
|
45
45
|
- `title`: the card and page heading. It defaults to the name, turned into a sentence.
|
|
46
46
|
- `description`: the first paragraph of the docstring is the default. Write one plain-language sentence about what it does for the person.
|
|
47
|
-
- `secrets`: names of environment variables, which builders set in the web app. Read them with `os.environ["CRM_TOKEN"]`. Never hard-code credentials and never take them as inputs. A declared secret that nobody has set doesn't block the run: the variable is simply missing, and builders see a "missing secrets" warning. For an optional secret, declare it and read it with `os.environ.get(...)`. Each secret is a single value, so a key file such as a `.pem` goes in as the file's contents, and the code reads it from the variable.
|
|
47
|
+
- `secrets`: names of environment variables, which builders set in the web app. Read them with `os.environ["CRM_TOKEN"]`. Never hard-code credentials and never take them as inputs. A declared secret that nobody has set doesn't block the run: the variable is simply missing, and builders see a "missing secrets" warning. For an optional secret, declare it and read it with `os.environ.get(...)`. Locally, `call local` and `call <group> <action>` load `.env` from the build folder, then the folder you run from, without overriding variables already set in your shell. The platform never reads `.env`. Each secret is a single value, so a key file such as a `.pem` goes in as the file's contents, and the code reads it from the variable.
|
|
48
48
|
- `timeout`: in seconds. The default is 300 and the maximum is 900.
|
|
49
49
|
- `schedule`: a cron expression in UTC, for schedules owned by the code. Only use it when the user asks for one. Anyone can add a schedule in the web app, so you usually don't need it.
|
|
50
50
|
|
|
@@ -98,7 +98,7 @@ def render(slug: str, open_browser: bool = False) -> str:
|
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
- They run as `call audits render --slug x` and with `call local`, with flags from the type hints, like any action. `call check` lists them as "(local only)".
|
|
101
|
-
- They're never deployed: the platform doesn't see them and nobody can run them from the web app. `@command` takes `name`, `title`, `description` and `next`, but no `secrets`, `schedule` or `timeout`, because it runs in your own environment (
|
|
101
|
+
- They're never deployed: the platform doesn't see them and nobody can run them from the web app. `@command` takes `name`, `title`, `description` and `next`, but no `secrets`, `schedule` or `timeout`, because it runs in your own environment (`call` loads the project's `.env` for it). A deployed action's `next=` can't point at one.
|
|
102
102
|
- Their module is still imported when the platform builds, so keep imports that only work locally inside the function.
|
|
103
103
|
- Return the result instead of printing it. The CLI prints what you return (a table as aligned columns in a terminal, JSON when piped), so printing it as well shows it twice. Keep prints for progress.
|
|
104
104
|
- To deploy one later, change `@command` to `@deploy`. It keeps its name.
|
|
@@ -212,6 +212,7 @@ def clean_contacts(sheet: Annotated[File, accept(".csv")]) -> File:
|
|
|
212
212
|
- **Python version:** taken from `.python-version` (e.g. `3.13`), else the newest version your `pyproject.toml` `requires-python` allows, else 3.12. Supported: 3.11 to 3.14.
|
|
213
213
|
- **Python dependencies** come from `requirements.txt` at the repo root, or from `[project].dependencies` in `pyproject.toml`. **Don't list `callables`.** The platform installs its own matching copy.
|
|
214
214
|
- **Automations in a subfolder:** by default the whole repo is built. To build only one folder, add `callables.toml` at the repo root containing `root = "automations"` (or `[tool.callables] root = "automations"` in `pyproject.toml`). Then only that folder goes into the image, and its own `requirements.txt`, `apt.txt` and `.python-version` are used. Code in it can't import from the rest of the repo. `call check`, `local` and `manifest` use the same folder when run from the repo root.
|
|
215
|
+
- **Several projects from one repo:** one repo can back several projects, one per folder. Set **Folder** when creating the project in the web app (it takes priority over `root` in `callables.toml`), and each folder builds with its own `requirements.txt`, `apt.txt` and `.python-version`. A push rebuilds only the projects whose folder changed. Each project has its own secrets and counts toward the plan's project limit. Locally, pass `--root automations/email` to `call check`, `local` and `manifest`.
|
|
215
216
|
- **Writable space:** your home directory (`~`), and `/tmp`, which is limited to 256 MB. Your code in `/app` is read-only. Every run starts fresh, so nothing persists between runs. Keep state in your own database or storage.
|
|
216
217
|
- **Running downloaded binaries:** `/tmp` doesn't allow running programs, so a binary downloaded there fails with `Permission denied`. Put it under `~` and `chmod +x` it. Better still, install the tool with `apt.txt` (below).
|
|
217
218
|
- Every module that imports `callables` and mentions `deploy` is imported at build time. Keep import-time code cheap and free of side effects: no network calls, and no reading secrets at module level. Read secrets inside the function.
|
|
@@ -238,6 +239,8 @@ You don't size anything. A run can use memory and CPU up to your organisation's
|
|
|
238
239
|
|
|
239
240
|
If a run goes over the memory limit, it fails with an error that says so. Fix it by using less memory (process files in chunks, stream instead of loading everything, free large objects you're done with), or move to a bigger plan. Child processes count toward the same limit.
|
|
240
241
|
|
|
242
|
+
Each plan includes an amount of usage per billing period. On a trial or the Free plan, reaching it cancels queued and running runs, and new runs and schedules wait until the next period or until the workspace picks a plan. Paid plans keep running and are billed for the extra usage.
|
|
243
|
+
|
|
241
244
|
## Errors people will see
|
|
242
245
|
|
|
243
246
|
Raise exceptions with messages written for the person running the automation. They see `ValueError: No deals found for EMEA since 2026-01-01`, so make it say what to change. For bad input, raise `ValueError` with a message about that field.
|
|
@@ -245,8 +248,8 @@ Raise exceptions with messages written for the person running the automation. Th
|
|
|
245
248
|
## Commands
|
|
246
249
|
|
|
247
250
|
- `call check [--json]`: problems a deploy would hit, with fixes. Exit code 1 on errors.
|
|
248
|
-
- `call <group> <action> [--flags]` (or `call <function> [--flags]`): run a function like a CLI command. Each input is a flag (`days` becomes `--days`, a bool becomes `--dry-run/--no-dry-run`, a list takes several values). Add `--help` to see them.
|
|
249
|
-
- `call local <name> [-i key=value ...] [--json]`: run a function on this machine. Values are parsed as JSON when possible, and `@path` passes a file. `--json` prints one JSON object on stdout (`ok`, `value`, `files`, `error`, `field_errors`), and the function's own prints go to stderr.
|
|
251
|
+
- `call <group> <action> [--flags]` (or `call <function> [--flags]`): run a function like a CLI command. Each input is a flag (`days` becomes `--days`, a bool becomes `--dry-run/--no-dry-run`, a list takes several values). Add `--help` to see them. Loads the project's `.env` first, like `call local`.
|
|
252
|
+
- `call local <name> [-i key=value ...] [--json]`: run a function on this machine, after loading the project's `.env` (variables already set win). Values are parsed as JSON when possible, and `@path` passes a file. `--json` prints one JSON object on stdout (`ok`, `value`, `files`, `error`, `field_errors`), and the function's own prints go to stderr.
|
|
250
253
|
- `call manifest`: the full JSON the platform reads, including each input's JSON Schema. Local `@command`s are left out.
|
|
251
254
|
- `call docs`: prints this guide.
|
|
252
255
|
- `call init`: an example automation plus agent instructions (`.claude/skills/callables/SKILL.md` and an `AGENTS.md` section). Run it again after upgrading the SDK to refresh the instructions.
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
from callables.decorator import DeployedFunction, Group, Next, command, deploy, registry
|
|
3
3
|
from callables.files import File, accept, save_file
|
|
4
4
|
|
|
5
|
-
__version__ = "0.
|
|
5
|
+
__version__ = "0.3.1"
|
|
6
6
|
__all__ = ["deploy", "command", "Group", "Next", "DeployedFunction", "registry", "File", "accept", "save_file", "__version__"]
|
|
@@ -40,7 +40,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
40
40
|
p_init.add_argument("--no-example", action="store_true", help="Only write the agent instructions")
|
|
41
41
|
p_init.add_argument("--no-agents", action="store_true", help="Skip the agent instructions")
|
|
42
42
|
|
|
43
|
-
p_run = sub.add_parser("run", help="(Used by the platform) run one function with inputs from $
|
|
43
|
+
p_run = sub.add_parser("run", help="(Used by the platform) run one function with inputs from $CALLABLES_INPUTS")
|
|
44
44
|
p_run.add_argument("entrypoint", help="module:function")
|
|
45
45
|
p_run.add_argument("--root", default=".")
|
|
46
46
|
|
|
@@ -272,9 +272,30 @@ def _follow(root: Path, fn: dict, functions: list[dict], rows: list[dict], files
|
|
|
272
272
|
return _local(root, target["name"], inputs, as_json=False, follow=True)
|
|
273
273
|
|
|
274
274
|
|
|
275
|
+
_env_loaded = False
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _load_env(root: Path) -> None:
|
|
279
|
+
"""The project's .env (the build folder's, then the current folder's), once per process. Never on the platform:
|
|
280
|
+
`call run` doesn't come through here."""
|
|
281
|
+
global _env_loaded
|
|
282
|
+
if _env_loaded:
|
|
283
|
+
return
|
|
284
|
+
_env_loaded = True
|
|
285
|
+
from callables.envfile import load
|
|
286
|
+
|
|
287
|
+
files, added = load(root, Path.cwd())
|
|
288
|
+
if files:
|
|
289
|
+
cwd = Path.cwd().resolve()
|
|
290
|
+
shown = ", ".join(str(p.relative_to(cwd)) if p.is_relative_to(cwd) else str(p) for p in files)
|
|
291
|
+
print(f"Loaded {len(added)} variable{'s' if len(added) != 1 else ''} from {shown}", file=sys.stderr)
|
|
292
|
+
|
|
293
|
+
|
|
275
294
|
def _local(root: Path, name: str, inputs: dict, as_json: bool, follow: bool = False) -> int:
|
|
276
295
|
from pydantic import ValidationError
|
|
277
296
|
|
|
297
|
+
_load_env(root)
|
|
298
|
+
|
|
278
299
|
from callables.decorator import registry
|
|
279
300
|
from callables.files import output_dir, saved_files
|
|
280
301
|
from callables.manifest import build_manifest
|
|
@@ -70,7 +70,7 @@ class Next:
|
|
|
70
70
|
|
|
71
71
|
def resolve(self, source: "DeployedFunction") -> dict[str, Any]:
|
|
72
72
|
"""Needs the whole registry, so it runs when the manifest is built, not at decoration time."""
|
|
73
|
-
target = getattr(self.action, "
|
|
73
|
+
target = getattr(self.action, "__callables__", None)
|
|
74
74
|
if target is None:
|
|
75
75
|
names = [self.action, f"{source.group.name}.{self.action}" if source.group else None]
|
|
76
76
|
target = next((registry[n] for n in names if n in registry), None)
|
|
@@ -227,7 +227,7 @@ def deploy(
|
|
|
227
227
|
def wrapper(*args, **kwargs):
|
|
228
228
|
return f(*args, **kwargs)
|
|
229
229
|
|
|
230
|
-
wrapper.
|
|
230
|
+
wrapper.__callables__ = deployed
|
|
231
231
|
return wrapper
|
|
232
232
|
|
|
233
233
|
return wrap(func) if func is not None else wrap
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""`.env` for local runs. `call local` and `call <group> <action>` load the project's `.env` so a function finds the
|
|
2
|
+
secrets it would get on the platform. Variables already set win, and the platform (`call run`) never reads it."""
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
_ESCAPES = {"n": "\n", "t": "\t", "r": "\r", '"': '"', "\\": "\\"}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _unescape(value: str) -> str:
|
|
10
|
+
out, chars = [], iter(value)
|
|
11
|
+
for ch in chars:
|
|
12
|
+
if ch == "\\":
|
|
13
|
+
nxt = next(chars, "")
|
|
14
|
+
out.append(_ESCAPES.get(nxt, "\\" + nxt))
|
|
15
|
+
else:
|
|
16
|
+
out.append(ch)
|
|
17
|
+
return "".join(out)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def parse(text: str) -> dict[str, str]:
|
|
21
|
+
"""KEY=value lines. Blank lines and `#` comments are skipped, `export ` is allowed, values may be quoted
|
|
22
|
+
('single' kept as is, "double" with \\n-style escapes), and an unquoted value ends at ` #`. No ${VAR} expansion."""
|
|
23
|
+
values = {}
|
|
24
|
+
for raw in text.splitlines():
|
|
25
|
+
line = raw.strip()
|
|
26
|
+
if not line or line.startswith("#"):
|
|
27
|
+
continue
|
|
28
|
+
if line.startswith("export "):
|
|
29
|
+
line = line[len("export "):].lstrip()
|
|
30
|
+
key, sep, value = line.partition("=")
|
|
31
|
+
key = key.strip()
|
|
32
|
+
if not sep or not key.replace("_", "").isalnum() or key[0].isdigit():
|
|
33
|
+
continue
|
|
34
|
+
value = value.strip()
|
|
35
|
+
if len(value) >= 2 and value[0] == value[-1] and value[0] in "'\"":
|
|
36
|
+
value = _unescape(value[1:-1]) if value[0] == '"' else value[1:-1]
|
|
37
|
+
else:
|
|
38
|
+
value = value.split(" #", 1)[0].rstrip()
|
|
39
|
+
values[key] = value
|
|
40
|
+
return values
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def load(*folders: Path) -> tuple[list[Path], list[str]]:
|
|
44
|
+
"""Loads `.env` from each folder, earlier folders first, without overriding variables already set.
|
|
45
|
+
Returns the files read and the names it set."""
|
|
46
|
+
files, added = [], []
|
|
47
|
+
for folder in dict.fromkeys(Path(f).resolve() for f in folders):
|
|
48
|
+
path = folder / ".env"
|
|
49
|
+
if not path.is_file():
|
|
50
|
+
continue
|
|
51
|
+
files.append(path)
|
|
52
|
+
for key, value in parse(path.read_text(encoding="utf-8")).items():
|
|
53
|
+
if key not in os.environ:
|
|
54
|
+
os.environ[key] = value
|
|
55
|
+
added.append(key)
|
|
56
|
+
return files, added
|
|
@@ -9,9 +9,9 @@ from typing import Any
|
|
|
9
9
|
from pydantic import Field, GetCoreSchemaHandler, GetJsonSchemaHandler
|
|
10
10
|
from pydantic_core import core_schema
|
|
11
11
|
|
|
12
|
-
OUTPUT_DIR_ENV = "
|
|
12
|
+
OUTPUT_DIR_ENV = "CALLABLES_OUTPUT_DIR"
|
|
13
13
|
LOCAL_OUTPUT_DIR = "callables-output" # where `call local` puts files
|
|
14
|
-
FILE_FORMAT = "
|
|
14
|
+
FILE_FORMAT = "callables-file"
|
|
15
15
|
|
|
16
16
|
_saved: list["File"] = []
|
|
17
17
|
_returned: set[Path] = set() # saved copies of files the function returned, not ones it saved alongside
|
|
@@ -10,7 +10,6 @@ from callables.manifest import discover_modules
|
|
|
10
10
|
|
|
11
11
|
SECTION_START = "<!-- callables:start -->"
|
|
12
12
|
SECTION_END = "<!-- callables:end -->"
|
|
13
|
-
LEGACY_SECTIONS = [("<!-- shipfn:start -->", "<!-- shipfn:end -->")] # replaced with the current section
|
|
14
13
|
|
|
15
14
|
SKILL_FRONTMATTER = """---
|
|
16
15
|
name: callables
|
|
@@ -50,16 +49,14 @@ def guide() -> str:
|
|
|
50
49
|
|
|
51
50
|
|
|
52
51
|
def _upsert_section(path: Path) -> str:
|
|
53
|
-
"""Add or refresh the callables section
|
|
52
|
+
"""Add or refresh the callables section, leaving the rest of the file alone."""
|
|
54
53
|
if not path.exists():
|
|
55
54
|
path.write_text(AGENTS_SECTION, encoding="utf-8")
|
|
56
55
|
return "created"
|
|
57
56
|
text = path.read_text(encoding="utf-8")
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
updated = text[:start] + AGENTS_SECTION.rstrip("\n") + text[end + len(end_marker):]
|
|
62
|
-
break
|
|
57
|
+
start, end = text.find(SECTION_START), text.find(SECTION_END)
|
|
58
|
+
if start != -1 and end > start:
|
|
59
|
+
updated = text[:start] + AGENTS_SECTION.rstrip("\n") + text[end + len(SECTION_END):]
|
|
63
60
|
else:
|
|
64
61
|
updated = text.rstrip("\n") + ("\n\n" if text.strip() else "") + AGENTS_SECTION
|
|
65
62
|
if updated == text:
|
|
@@ -100,12 +97,6 @@ def init_project(root: Path, example: bool = True, agents: bool = True) -> list[
|
|
|
100
97
|
|
|
101
98
|
if agents:
|
|
102
99
|
skill = root / ".claude" / "skills" / "callables" / "SKILL.md"
|
|
103
|
-
old_skill = root / ".claude" / "skills" / "shipfn" / "SKILL.md"
|
|
104
|
-
if old_skill.exists(): # written by an older version under the old name; the new one replaces it
|
|
105
|
-
old_skill.unlink()
|
|
106
|
-
if not any(old_skill.parent.iterdir()):
|
|
107
|
-
old_skill.parent.rmdir()
|
|
108
|
-
done.append((str(old_skill.relative_to(root)), "removed (renamed to callables)"))
|
|
109
100
|
content = SKILL_FRONTMATTER + guide()
|
|
110
101
|
existed = skill.exists()
|
|
111
102
|
if existed and skill.read_text(encoding="utf-8") == content:
|
|
@@ -6,12 +6,12 @@ from typing import Any
|
|
|
6
6
|
|
|
7
7
|
from callables.decorator import registry
|
|
8
8
|
|
|
9
|
-
SKIP_DIRS = {".git", ".venv", "venv", "env", "node_modules", "__pycache__", "tests", "test", ".
|
|
9
|
+
SKIP_DIRS = {".git", ".venv", "venv", "env", "node_modules", "__pycache__", "tests", "test", ".callables_sdk", "build", "dist"}
|
|
10
10
|
MANIFEST_VERSION = 1
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def discover_modules(root: Path) -> list[str]:
|
|
14
|
-
"""Dotted names of every module under root that mentions callables
|
|
14
|
+
"""Dotted names of every module under root that mentions callables, so they can be imported."""
|
|
15
15
|
modules = []
|
|
16
16
|
for dirpath, dirnames, filenames in os.walk(root):
|
|
17
17
|
dirnames[:] = sorted(d for d in dirnames if d not in SKIP_DIRS and not d.startswith("."))
|
|
@@ -23,7 +23,7 @@ def discover_modules(root: Path) -> list[str]:
|
|
|
23
23
|
text = path.read_text(encoding="utf-8", errors="ignore")
|
|
24
24
|
except OSError:
|
|
25
25
|
continue
|
|
26
|
-
if
|
|
26
|
+
if "callables" not in text or ("deploy" not in text and "command" not in text):
|
|
27
27
|
continue
|
|
28
28
|
rel = path.relative_to(root).with_suffix("")
|
|
29
29
|
parts = list(rel.parts)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"""Which folder of a repo the platform builds. By default the whole repo; a repo can point it at a subfolder,
|
|
2
|
-
and then only that folder is built: its requirements.txt / pyproject.toml, apt.txt and .python-version.
|
|
2
|
+
and then only that folder is built: its requirements.txt / pyproject.toml, apt.txt and .python-version.
|
|
3
|
+
A project's own folder setting wins over the repo's config, so one repo can back several projects."""
|
|
3
4
|
import tomllib
|
|
4
5
|
from pathlib import Path, PurePosixPath
|
|
5
6
|
|
|
6
|
-
CONFIG_FILES = ("callables.toml",
|
|
7
|
-
TOOL_KEYS = ("callables",
|
|
7
|
+
CONFIG_FILES = ("callables.toml",)
|
|
8
|
+
TOOL_KEYS = ("callables",)
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
class ConfigError(ValueError):
|
|
@@ -34,10 +35,11 @@ def _configured_root(repo: Path) -> tuple[object, str] | None:
|
|
|
34
35
|
return None
|
|
35
36
|
|
|
36
37
|
|
|
37
|
-
def build_root(repo: Path) -> tuple[Path, str | None]:
|
|
38
|
-
"""The folder to build, and where that setting came from (None when it's the whole repo).
|
|
38
|
+
def build_root(repo: Path, project_root: str | None = None) -> tuple[Path, str | None]:
|
|
39
|
+
"""The folder to build, and where that setting came from (None when it's the whole repo). `project_root` is the
|
|
40
|
+
project's folder setting, relative to the repo."""
|
|
39
41
|
repo = repo.resolve()
|
|
40
|
-
configured = _configured_root(repo)
|
|
42
|
+
configured = (project_root, "the project's settings") if project_root else _configured_root(repo)
|
|
41
43
|
if configured is None:
|
|
42
44
|
return repo, None
|
|
43
45
|
value, source = configured
|
|
@@ -11,9 +11,9 @@ from pydantic import BaseModel, TypeAdapter
|
|
|
11
11
|
|
|
12
12
|
from callables.files import File, keep_returned, saved_files
|
|
13
13
|
|
|
14
|
-
RESULT_MARKER = "
|
|
14
|
+
RESULT_MARKER = "__CALLABLES_RESULT__"
|
|
15
15
|
# Lines the platform shows only to the function's builders (end users never see stack traces)
|
|
16
|
-
BUILDER_MARKER = "
|
|
16
|
+
BUILDER_MARKER = "__CALLABLES_BUILDER__"
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def to_jsonable(value: Any) -> Any:
|
|
@@ -36,7 +36,7 @@ def resolve(entrypoint: str):
|
|
|
36
36
|
obj: Any = importlib.import_module(module_name)
|
|
37
37
|
for attr in qualname.split("."):
|
|
38
38
|
obj = getattr(obj, attr)
|
|
39
|
-
deployed = getattr(obj, "
|
|
39
|
+
deployed = getattr(obj, "__callables__", None)
|
|
40
40
|
if deployed is None:
|
|
41
41
|
raise RuntimeError(f"{entrypoint} is not decorated with @deploy")
|
|
42
42
|
return deployed
|
|
@@ -51,13 +51,13 @@ def emit(payload: dict[str, Any]) -> None:
|
|
|
51
51
|
def run(entrypoint: str, root: Path) -> int:
|
|
52
52
|
if str(root) not in sys.path:
|
|
53
53
|
sys.path.insert(0, str(root))
|
|
54
|
-
inputs = json.loads(os.environ.pop("
|
|
54
|
+
inputs = json.loads(os.environ.pop("CALLABLES_INPUTS", "{}") or "{}")
|
|
55
55
|
try:
|
|
56
56
|
result = finish(resolve(entrypoint).call(inputs))
|
|
57
57
|
except Exception as exc:
|
|
58
58
|
sys.stdout.flush()
|
|
59
59
|
# On the platform, tag the traceback so only builders see it; locally, print it as-is
|
|
60
|
-
prefix = BUILDER_MARKER if os.environ.get("
|
|
60
|
+
prefix = BUILDER_MARKER if os.environ.get("CALLABLES_RUN_ID") else ""
|
|
61
61
|
for line in traceback.format_exc().rstrip().splitlines():
|
|
62
62
|
print(prefix + line, file=sys.stderr, flush=True)
|
|
63
63
|
emit({"ok": False, "error": f"{type(exc).__name__}: {exc}", "files": saved_files()})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: callables
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Decorate Python functions and push them to Callables: forms, schedules and run history for your team.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Homepage, https://callables.app
|
|
@@ -26,7 +26,7 @@ pip install callables
|
|
|
26
26
|
|
|
27
27
|
Docs: [callables.app/docs](https://callables.app/docs).
|
|
28
28
|
|
|
29
|
-
This installs the `call` command.
|
|
29
|
+
This installs the `call` command.
|
|
30
30
|
|
|
31
31
|
```python
|
|
32
32
|
from typing import Literal
|
|
@@ -42,7 +42,7 @@ def weekly_report(region: Literal["NA", "EMEA", "APAC"] = "NA", days: int = 7) -
|
|
|
42
42
|
- **Results** are shown by return type: `str` as Markdown, `list[dict]` (or a DataFrame) as a table with CSV download, `dict`/Pydantic model as a key-value list, `None` as "done".
|
|
43
43
|
- **Files in**: a `File` parameter becomes an upload field. Your function gets a `File` with `.path`, `.name`, `.read_text()`, `.read_bytes()` and `.open()`. Limit the picker with `Annotated[File, accept(".csv", ".xlsx")]`.
|
|
44
44
|
- **Files out**: return a `File` (or a `list[File]`) and people get download buttons. To hand back files alongside another result, call `save_file(path_or_bytes, name=...)`. Files are kept for 24 hours by default.
|
|
45
|
-
- **Secrets** you list are injected as environment variables at run time (`os.environ["SALES_API_TOKEN"]`); set their values in the Callables console.
|
|
45
|
+
- **Secrets** you list are injected as environment variables at run time (`os.environ["SALES_API_TOKEN"]`); set their values in the Callables console. Locally, `call local` and `call <group> <action>` load the project's `.env` instead (variables already set in your shell win).
|
|
46
46
|
- **Schedules** are cron expressions, in UTC.
|
|
47
47
|
|
|
48
48
|
```python
|
|
@@ -88,7 +88,7 @@ python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
|
88
88
|
.venv/bin/pytest
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
The platform (
|
|
91
|
+
The platform (callables-api) depends on this package and copies the installed version into every build, so a release only reaches deployed functions once the API is updated to it. See [RELEASING.md](RELEASING.md).
|
|
92
92
|
|
|
93
93
|
## License
|
|
94
94
|
|
|
@@ -8,6 +8,7 @@ callables/checks.py
|
|
|
8
8
|
callables/cli.py
|
|
9
9
|
callables/commands.py
|
|
10
10
|
callables/decorator.py
|
|
11
|
+
callables/envfile.py
|
|
11
12
|
callables/files.py
|
|
12
13
|
callables/init.py
|
|
13
14
|
callables/manifest.py
|
|
@@ -21,10 +22,9 @@ callables.egg-info/dependency_links.txt
|
|
|
21
22
|
callables.egg-info/entry_points.txt
|
|
22
23
|
callables.egg-info/requires.txt
|
|
23
24
|
callables.egg-info/top_level.txt
|
|
24
|
-
shipfn/__init__.py
|
|
25
|
-
shipfn/__main__.py
|
|
26
25
|
tests/test_agent_tools.py
|
|
27
26
|
tests/test_command.py
|
|
27
|
+
tests/test_envfile.py
|
|
28
28
|
tests/test_files.py
|
|
29
29
|
tests/test_groups.py
|
|
30
30
|
tests/test_next.py
|
|
@@ -27,10 +27,9 @@ Source = "https://github.com/callables-app/callables-python"
|
|
|
27
27
|
[project.scripts]
|
|
28
28
|
call = "callables.cli:main"
|
|
29
29
|
callables = "callables.cli:main"
|
|
30
|
-
shipfn = "callables.cli:main" # the old name, kept for existing scripts
|
|
31
30
|
|
|
32
31
|
[tool.setuptools.packages.find]
|
|
33
|
-
include = ["callables*"
|
|
32
|
+
include = ["callables*"]
|
|
34
33
|
|
|
35
34
|
[tool.setuptools.package-data]
|
|
36
35
|
callables = ["py.typed", "GUIDE.md"]
|
|
@@ -14,7 +14,7 @@ from callables.schema import input_model
|
|
|
14
14
|
def isolated(tmp_path, monkeypatch):
|
|
15
15
|
registry.clear()
|
|
16
16
|
files_mod._saved.clear()
|
|
17
|
-
monkeypatch.setenv("
|
|
17
|
+
monkeypatch.setenv("CALLABLES_OUTPUT_DIR", str(tmp_path / "out"))
|
|
18
18
|
yield
|
|
19
19
|
registry.clear()
|
|
20
20
|
files_mod._saved.clear()
|
|
@@ -143,17 +143,3 @@ def test_init_sets_up_a_repo_and_is_safe_to_rerun(tmp_path):
|
|
|
143
143
|
# An outdated section is refreshed in place
|
|
144
144
|
(tmp_path / "AGENTS.md").write_text(f"top\n{SECTION_START}\nold\n{SECTION_END}\nbottom\n")
|
|
145
145
|
assert dict(init_project(tmp_path, example=False))["AGENTS.md"] == "updated"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
def test_init_replaces_what_the_shipfn_version_wrote(tmp_path):
|
|
149
|
-
(tmp_path / "AGENTS.md").write_text("top\n<!-- shipfn:start -->\nold\n<!-- shipfn:end -->\nbottom\n")
|
|
150
|
-
old_skill = tmp_path / ".claude/skills/shipfn/SKILL.md"
|
|
151
|
-
old_skill.parent.mkdir(parents=True)
|
|
152
|
-
old_skill.write_text("old guide")
|
|
153
|
-
done = dict(init_project(tmp_path, example=False))
|
|
154
|
-
assert done[".claude/skills/shipfn/SKILL.md"].startswith("removed") and not old_skill.parent.exists()
|
|
155
|
-
agents = (tmp_path / "AGENTS.md").read_text()
|
|
156
|
-
assert "shipfn:start" not in agents and agents.count(SECTION_START) == 1
|
|
157
|
-
assert agents.startswith("top\n" + SECTION_START) and agents.endswith(SECTION_END + "\nbottom\n")
|
|
158
|
-
refreshed = (tmp_path / "AGENTS.md").read_text()
|
|
159
|
-
assert refreshed.startswith("top\n") and refreshed.endswith("bottom\n") and "old" not in refreshed
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import textwrap
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from callables import cli, registry
|
|
8
|
+
from callables.cli import main
|
|
9
|
+
from callables.envfile import load, parse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture(autouse=True)
|
|
13
|
+
def isolated(monkeypatch):
|
|
14
|
+
registry.clear()
|
|
15
|
+
monkeypatch.setattr(cli, "_env_loaded", False)
|
|
16
|
+
for key in ("CALLABLES_T_TOKEN", "CALLABLES_T_SHELL"):
|
|
17
|
+
monkeypatch.delenv(key, raising=False)
|
|
18
|
+
yield
|
|
19
|
+
registry.clear()
|
|
20
|
+
for key in ("CALLABLES_T_TOKEN", "CALLABLES_T_SHELL"): # load() sets os.environ directly
|
|
21
|
+
os.environ.pop(key, None)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_parse_reads_the_usual_dotenv_forms():
|
|
25
|
+
text = textwrap.dedent('''
|
|
26
|
+
# a comment
|
|
27
|
+
PLAIN=abc
|
|
28
|
+
export EXPORTED=1
|
|
29
|
+
SPACED = padded value
|
|
30
|
+
SINGLE='keep $this \\n raw'
|
|
31
|
+
DOUBLE="line\\nbreak \\"quoted\\""
|
|
32
|
+
INLINE=value # trailing comment
|
|
33
|
+
HASH=pass#word
|
|
34
|
+
URL=postgresql://u:p@host:5432/db?sslmode=require
|
|
35
|
+
EMPTY=
|
|
36
|
+
not a line
|
|
37
|
+
1BAD=x
|
|
38
|
+
''')
|
|
39
|
+
assert parse(text) == {
|
|
40
|
+
"PLAIN": "abc",
|
|
41
|
+
"EXPORTED": "1",
|
|
42
|
+
"SPACED": "padded value",
|
|
43
|
+
"SINGLE": "keep $this \\n raw",
|
|
44
|
+
"DOUBLE": 'line\nbreak "quoted"',
|
|
45
|
+
"INLINE": "value",
|
|
46
|
+
"HASH": "pass#word",
|
|
47
|
+
"URL": "postgresql://u:p@host:5432/db?sslmode=require",
|
|
48
|
+
"EMPTY": "",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_load_never_overrides_what_is_already_set(tmp_path, monkeypatch):
|
|
53
|
+
(tmp_path / ".env").write_text("CALLABLES_T_TOKEN=from-file\nCALLABLES_T_SHELL=from-file\n")
|
|
54
|
+
monkeypatch.setenv("CALLABLES_T_SHELL", "from-shell")
|
|
55
|
+
files, added = load(tmp_path)
|
|
56
|
+
assert files == [(tmp_path / ".env").resolve()]
|
|
57
|
+
assert added == ["CALLABLES_T_TOKEN"]
|
|
58
|
+
assert os.environ["CALLABLES_T_TOKEN"] == "from-file"
|
|
59
|
+
assert os.environ["CALLABLES_T_SHELL"] == "from-shell"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_the_build_folder_env_wins_over_the_current_folder(tmp_path):
|
|
63
|
+
sub = tmp_path / "automations"
|
|
64
|
+
sub.mkdir()
|
|
65
|
+
(sub / ".env").write_text("CALLABLES_T_TOKEN=folder\n")
|
|
66
|
+
(tmp_path / ".env").write_text("CALLABLES_T_TOKEN=repo\nCALLABLES_T_SHELL=repo\n")
|
|
67
|
+
load(sub, tmp_path)
|
|
68
|
+
assert os.environ["CALLABLES_T_TOKEN"] == "folder"
|
|
69
|
+
assert os.environ["CALLABLES_T_SHELL"] == "repo"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
PROJECT = '''
|
|
73
|
+
import os
|
|
74
|
+
from callables import deploy
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@deploy(secrets=["CALLABLES_T_TOKEN"])
|
|
78
|
+
def token() -> str:
|
|
79
|
+
return os.environ.get("CALLABLES_T_TOKEN", "missing")
|
|
80
|
+
'''
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@pytest.fixture
|
|
84
|
+
def project(tmp_path, monkeypatch, request):
|
|
85
|
+
(tmp_path / f"env_{request.node.name}.py").write_text(textwrap.dedent(PROJECT))
|
|
86
|
+
(tmp_path / ".env").write_text("CALLABLES_T_TOKEN=secret-from-env-file\n")
|
|
87
|
+
monkeypatch.chdir(tmp_path)
|
|
88
|
+
return tmp_path
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_local_runs_see_the_env_file(project, capsys):
|
|
92
|
+
assert main(["local", "token", "--json"]) == 0
|
|
93
|
+
out = capsys.readouterr()
|
|
94
|
+
assert json.loads(out.out)["value"] == "secret-from-env-file"
|
|
95
|
+
assert "Loaded 1 variable from .env" in out.err
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_commands_see_the_env_file(project, capsys):
|
|
99
|
+
assert main(["token"]) == 0
|
|
100
|
+
assert capsys.readouterr().out.strip() == "secret-from-env-file"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_the_shell_wins_over_the_env_file(project, capsys, monkeypatch):
|
|
104
|
+
monkeypatch.setenv("CALLABLES_T_TOKEN", "from-shell")
|
|
105
|
+
assert main(["token"]) == 0
|
|
106
|
+
assert capsys.readouterr().out.strip() == "from-shell"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_the_platform_runner_ignores_the_env_file(project, monkeypatch, capsys, request):
|
|
110
|
+
monkeypatch.setenv("CALLABLES_INPUTS", "{}")
|
|
111
|
+
main(["run", f"env_{request.node.name}:token", "--root", str(project)])
|
|
112
|
+
assert "missing" in capsys.readouterr().out
|
|
113
|
+
assert "CALLABLES_T_TOKEN" not in os.environ
|
|
@@ -14,7 +14,7 @@ from callables.schema import input_schema, output_kind
|
|
|
14
14
|
def isolated(tmp_path, monkeypatch):
|
|
15
15
|
registry.clear()
|
|
16
16
|
files_mod._saved.clear()
|
|
17
|
-
monkeypatch.setenv("
|
|
17
|
+
monkeypatch.setenv("CALLABLES_OUTPUT_DIR", str(tmp_path / "out"))
|
|
18
18
|
yield
|
|
19
19
|
registry.clear()
|
|
20
20
|
files_mod._saved.clear()
|
|
@@ -26,8 +26,8 @@ def test_file_parameters_become_upload_fields():
|
|
|
26
26
|
...
|
|
27
27
|
|
|
28
28
|
props = input_schema(clean)["properties"]
|
|
29
|
-
assert props["sheet"] == {"type": "string", "format": "
|
|
30
|
-
assert {"type": "string", "format": "
|
|
29
|
+
assert props["sheet"] == {"type": "string", "format": "callables-file", "title": "Sheet", "x-accept": ".csv,.xlsx"}
|
|
30
|
+
assert {"type": "string", "format": "callables-file"} in props["notes"]["anyOf"]
|
|
31
31
|
assert input_schema(clean)["required"] == ["sheet"]
|
|
32
32
|
assert output_kind(clean) == "file"
|
|
33
33
|
|
|
@@ -50,7 +50,7 @@ def test_runtime_hands_uploads_in_and_files_out(tmp_path, capsys, monkeypatch):
|
|
|
50
50
|
" out.write_text(sheet.read_text() * 2)\n"
|
|
51
51
|
" return File(out, name=f'doubled-{sheet.name}')\n"
|
|
52
52
|
)
|
|
53
|
-
monkeypatch.setenv("
|
|
53
|
+
monkeypatch.setenv("CALLABLES_INPUTS", json.dumps({"sheet": {"path": str(upload), "name": "Sales Q3.csv"}}))
|
|
54
54
|
assert run("fx_double:double", tmp_path) == 0
|
|
55
55
|
payload = json.loads(capsys.readouterr().out.splitlines()[-1].removeprefix(RESULT_MARKER))
|
|
56
56
|
assert payload["ok"] and payload["value"] is None
|
|
@@ -63,7 +63,7 @@ def test_runtime_hands_uploads_in_and_files_out(tmp_path, capsys, monkeypatch):
|
|
|
63
63
|
|
|
64
64
|
def test_missing_upload_is_a_validation_error(tmp_path, capsys, monkeypatch):
|
|
65
65
|
(tmp_path / "fx_missing.py").write_text("from callables import deploy, File\n@deploy\ndef f(sheet: File) -> str:\n return 'x'\n")
|
|
66
|
-
monkeypatch.setenv("
|
|
66
|
+
monkeypatch.setenv("CALLABLES_INPUTS", json.dumps({"sheet": {"path": str(tmp_path / "nope.csv")}}))
|
|
67
67
|
assert run("fx_missing:f", tmp_path) == 1
|
|
68
68
|
payload = json.loads(capsys.readouterr().out.splitlines()[-1].removeprefix(RESULT_MARKER))
|
|
69
69
|
assert "File not found" in payload["error"]
|
|
@@ -14,14 +14,24 @@ def isolated():
|
|
|
14
14
|
registry.clear()
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
def test_the_projects_folder_wins_over_the_repo_config(tmp_path):
|
|
18
|
+
(tmp_path / "automations" / "email").mkdir(parents=True)
|
|
19
|
+
(tmp_path / "callables.toml").write_text('root = "automations"\n')
|
|
20
|
+
assert build_root(tmp_path, "automations/email") == (
|
|
21
|
+
(tmp_path / "automations" / "email").resolve(), "the project's settings")
|
|
22
|
+
assert build_root(tmp_path, "") == ((tmp_path / "automations").resolve(), "callables.toml")
|
|
23
|
+
with pytest.raises(ConfigError, match="no folder"):
|
|
24
|
+
build_root(tmp_path, "salesforce")
|
|
25
|
+
with pytest.raises(ConfigError, match="inside the repo"):
|
|
26
|
+
build_root(tmp_path, "../other")
|
|
27
|
+
|
|
28
|
+
|
|
17
29
|
def test_whole_repo_unless_a_root_is_set(tmp_path):
|
|
18
30
|
assert build_root(tmp_path) == (tmp_path.resolve(), None)
|
|
19
31
|
(tmp_path / "automations").mkdir()
|
|
20
|
-
(tmp_path / "pyproject.toml").write_text('[tool.
|
|
21
|
-
assert build_root(tmp_path) == ((tmp_path / "automations").resolve(), "pyproject.toml [tool.
|
|
22
|
-
(tmp_path / "
|
|
23
|
-
assert build_root(tmp_path) == ((tmp_path / "automations").resolve(), "shipfn.toml")
|
|
24
|
-
(tmp_path / "callables.toml").write_text('root = "automations"\n') # and the current name over the old one
|
|
32
|
+
(tmp_path / "pyproject.toml").write_text('[tool.callables]\nroot = "automations/"\n')
|
|
33
|
+
assert build_root(tmp_path) == ((tmp_path / "automations").resolve(), "pyproject.toml [tool.callables]")
|
|
34
|
+
(tmp_path / "callables.toml").write_text('root = "./automations"\n') # a config file wins over pyproject.toml
|
|
25
35
|
assert build_root(tmp_path) == ((tmp_path / "automations").resolve(), "callables.toml")
|
|
26
36
|
|
|
27
37
|
|
|
@@ -42,13 +52,13 @@ def test_root_must_be_a_folder_in_the_repo(tmp_path, value, message):
|
|
|
42
52
|
repo = tmp_path / "repo"
|
|
43
53
|
repo.mkdir()
|
|
44
54
|
(repo / "escape").symlink_to(tmp_path)
|
|
45
|
-
(repo / "
|
|
55
|
+
(repo / "callables.toml").write_text(f"root = {value}\n")
|
|
46
56
|
with pytest.raises(ConfigError, match=message):
|
|
47
57
|
build_root(repo)
|
|
48
58
|
|
|
49
59
|
|
|
50
60
|
def test_commands_use_the_same_folder_the_platform_builds(tmp_path, monkeypatch, capsys):
|
|
51
|
-
(tmp_path / "
|
|
61
|
+
(tmp_path / "callables.toml").write_text('root = "autos"\n')
|
|
52
62
|
(tmp_path / "autos").mkdir()
|
|
53
63
|
(tmp_path / "autos" / "proj_root_jobs.py").write_text(
|
|
54
64
|
"from callables import deploy\n\n@deploy()\ndef proj_root_fn() -> str:\n return 'hi'\n")
|
|
@@ -95,16 +95,16 @@ def test_runtime_emits_result_and_errors(tmp_path, capsys, monkeypatch):
|
|
|
95
95
|
pkg.mkdir()
|
|
96
96
|
(pkg / "__init__.py").write_text("")
|
|
97
97
|
(pkg / "m.py").write_text(
|
|
98
|
-
"from datetime import date\nfrom
|
|
98
|
+
"from datetime import date\nfrom callables import deploy\n"
|
|
99
99
|
"@deploy\ndef rt_ok(n: int = 2) -> list[dict]:\n print('working')\n return [{'n': n, 'd': date(2026, 1, 1)}]\n"
|
|
100
100
|
"@deploy\ndef rt_bad() -> None:\n raise ValueError('nope')\n"
|
|
101
101
|
)
|
|
102
|
-
monkeypatch.setenv("
|
|
102
|
+
monkeypatch.setenv("CALLABLES_INPUTS", json.dumps({"n": 5}))
|
|
103
103
|
assert run("autos.m:rt_ok", tmp_path) == 0
|
|
104
104
|
out = capsys.readouterr().out.strip().splitlines()
|
|
105
105
|
assert out[0] == "working"
|
|
106
106
|
assert json.loads(out[-1].removeprefix(RESULT_MARKER)) == {"ok": True, "value": [{"n": 5, "d": "2026-01-01"}], "files": []}
|
|
107
|
-
assert "
|
|
107
|
+
assert "CALLABLES_INPUTS" not in os.environ # inputs are consumed, not left for user code
|
|
108
108
|
|
|
109
109
|
assert run("autos.m:rt_bad", tmp_path) == 1
|
|
110
110
|
last = capsys.readouterr().out.strip().splitlines()[-1]
|
|
@@ -130,13 +130,3 @@ def test_manifest_reports_import_errors(tmp_path):
|
|
|
130
130
|
manifest = build_manifest(tmp_path)
|
|
131
131
|
assert manifest["errors"][0]["module"] == "broken"
|
|
132
132
|
assert "not_a_real_module_xyz" in manifest["errors"][0]["error"]
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def test_shipfn_is_the_old_name_for_callables():
|
|
136
|
-
import shipfn
|
|
137
|
-
import shipfn.files
|
|
138
|
-
|
|
139
|
-
import callables
|
|
140
|
-
import callables.files
|
|
141
|
-
|
|
142
|
-
assert shipfn.deploy is callables.deploy and shipfn.files is callables.files and shipfn.__version__ == callables.__version__
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"""The old name of the callables package. `from shipfn import deploy` and `import shipfn.files` keep working, so
|
|
2
|
-
repos written before the rename still deploy. New code imports callables."""
|
|
3
|
-
import importlib
|
|
4
|
-
import sys
|
|
5
|
-
|
|
6
|
-
from callables import * # noqa: F401,F403
|
|
7
|
-
from callables import __all__, __version__ # noqa: F401
|
|
8
|
-
|
|
9
|
-
for _name in ("checks", "cli", "commands", "decorator", "files", "init", "manifest", "project", "runtime", "schema"):
|
|
10
|
-
sys.modules[f"{__name__}.{_name}"] = globals()[_name] = importlib.import_module(f"callables.{_name}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|