Skip to content

Commit 22634db

Browse files
shixishclaude
andcommitted
Merge origin/main (3.1.1) into feat/sdk-s2
3.1.1 is on PyPI but feat/sdk-s2 forked from 3.1.0, so releasing 3.4.0 without this would undo it: db -o now creates missing parent folders, the verify-release targets refresh uv's index cache, and the macOS release binary builds on macos-15. Conflicts were only the version line in pyproject.toml and uv.lock; 3.4.0 is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 parents 7d0241b + 4cd21ee commit 22634db

5 files changed

Lines changed: 49 additions & 10 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
# macOS is Apple Silicon only: GitHub's Intel (macos-13) runners are
4141
# being deprecated and their queue is unreliable. Intel-Mac users can
4242
# still `pip install diffbot`.
43-
- runner: macos-14 # Apple Silicon
43+
- runner: macos-15 # Apple Silicon
4444
target_os: darwin
4545
arch: aarch64
4646
steps:

‎Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ verify-release-test:
9090
@VERSION=$$(grep '^version' $(PYPROJECT) | head -1 | cut -d'"' -f2) && \
9191
TMP=$$(mktemp -d) && \
9292
uv venv --python 3.12 $$TMP/.venv >/dev/null 2>&1 && \
93-
uv pip install --quiet --python $$TMP/.venv/bin/python \
93+
uv pip install --quiet --refresh-package $(PKG) --python $$TMP/.venv/bin/python \
9494
--index-url https://test.pypi.org/simple/ \
9595
--extra-index-url https://pypi.org/simple/ --index-strategy unsafe-best-match \
9696
"$(PKG)==$$VERSION" && \
@@ -101,6 +101,6 @@ verify-release:
101101
@VERSION=$$(grep '^version' $(PYPROJECT) | head -1 | cut -d'"' -f2) && \
102102
TMP=$$(mktemp -d) && \
103103
uv venv --python 3.12 $$TMP/.venv >/dev/null 2>&1 && \
104-
uv pip install --quiet --python $$TMP/.venv/bin/python "$(PKG)==$$VERSION" && \
104+
uv pip install --quiet --refresh-package $(PKG) --python $$TMP/.venv/bin/python "$(PKG)==$$VERSION" && \
105105
(cd $$TMP && $$TMP/.venv/bin/python -c "import diffbot; print('PyPI install OK:', diffbot.__version__)") && \
106106
rm -rf $$TMP

‎src/diffbot/cli/__init__.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
json_schema_format,
2424
)
2525

26-
from ._common import get_client
26+
from ._common import get_client, write_output
2727

2828
console = Console()
2929
is_interactive = sys.stdout.isatty()
@@ -76,8 +76,7 @@ def extract(url, output, fmt, api):
7676
output_str = f"Title: {title}\n\nURL: {url}\n\nContent: {content}"
7777

7878
if output:
79-
with open(output, "w") as f:
80-
f.write(output_str)
79+
write_output(output, output_str)
8180
click.echo(f"Output written to {output}")
8281
else:
8382
print_markdown(output_str)
@@ -170,8 +169,7 @@ def ask(prompt: str, output: Optional[str] = None, as_json: bool = False, schema
170169
else:
171170
for chunk in db.ask(messages):
172171
response += chunk
173-
with open(output, "w") as f:
174-
f.write(response)
172+
write_output(output, response)
175173
click.echo(f"Output written to {output}")
176174
elif as_json:
177175
sys.stdout.write(
@@ -258,8 +256,7 @@ def crawl(site, hops, job_name, max_to_crawl, max_to_process, restrict_domain,
258256
output_str = "\n".join(lines)
259257

260258
if output:
261-
with open(output, "w") as f:
262-
f.write(output_str)
259+
write_output(output, output_str)
263260
click.echo(f"Output written to {output}")
264261
else:
265262
print_markdown(output_str)

‎src/diffbot/cli/_common.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pathlib
2+
13
import click
24

35
from diffbot import Diffbot, resolve_token
@@ -19,3 +21,10 @@ def get_client() -> Diffbot:
1921
)
2022
raise click.Abort()
2123
return Diffbot(token=token)
24+
25+
26+
def write_output(path: str, text: str) -> None:
27+
"""Write text to path, creating missing parent folders."""
28+
dest = pathlib.Path(path).expanduser()
29+
dest.parent.mkdir(parents=True, exist_ok=True)
30+
dest.write_text(text)

‎tests/test_cli_output.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import json
2+
3+
from click.testing import CliRunner
4+
5+
import diffbot.cli as cli
6+
7+
8+
class StubClient:
9+
def extract(self, url, api, fmt):
10+
return {"objects": [{"title": "T"}]}
11+
12+
def crawl(self, site, **kwargs):
13+
return iter(())
14+
15+
16+
def test_extract_output_creates_missing_folders(monkeypatch, tmp_path):
17+
monkeypatch.setattr(cli, "get_client", StubClient)
18+
out = tmp_path / "a" / "b" / "extracted.json"
19+
result = CliRunner().invoke(
20+
cli.main, ["extract", "https://example.com", "-f", "json", "-o", str(out)]
21+
)
22+
assert result.exit_code == 0, result.output
23+
assert json.loads(out.read_text()) == {"objects": [{"title": "T"}]}
24+
25+
26+
def test_crawl_output_creates_missing_folders(monkeypatch, tmp_path):
27+
monkeypatch.setattr(cli, "get_client", StubClient)
28+
out = tmp_path / "a" / "b" / "crawl.json"
29+
result = CliRunner().invoke(
30+
cli.main, ["crawl", "https://example.com", "-f", "json", "-o", str(out)]
31+
)
32+
assert result.exit_code == 0, result.output
33+
assert out.exists()

0 commit comments

Comments
 (0)