Skip to content

Commit ed65869

Browse files
committed
Format with black
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ggg4AutCcRdK8c57NMxSqp
1 parent cdd2e76 commit ed65869

5 files changed

Lines changed: 51 additions & 18 deletions

File tree

‎dataherb/catalog/add.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ def add_repos(
164164
)
165165
continue
166166
did = str(existing["id"]) if existing else default_id(repo, strip_prefix)
167-
target = (
168-
cfg.path(existing["_file"]) if existing else out_dir / f"{did}.{fmt}"
169-
)
167+
target = cfg.path(existing["_file"]) if existing else out_dir / f"{did}.{fmt}"
170168
if not existing and (did in known_ids or target.exists()) and not force:
171169
results.append(
172170
Added(repo, did, target, "skipped", f"id '{did}' is already taken")
@@ -200,15 +198,20 @@ def add_repos(
200198
)
201199
)
202200
continue
203-
found = next((c for c in METADATA_CANDIDATES if (dest / c).exists()), None)
201+
found = next(
202+
(c for c in METADATA_CANDIDATES if (dest / c).exists()), None
203+
)
204204
if found is None:
205205
inferred = scaffold(dest, dataset_id=did)
206206

207207
if inferred is not None:
208208
entry["inline"] = True
209209
for k in ("name", "description", "datapackage"):
210210
entry[k] = inferred[k]
211-
kind, note = "inline", f"no metadata in the repo; inferred {len(inferred['datapackage']['resources'])} resource(s)"
211+
kind, note = (
212+
"inline",
213+
f"no metadata in the repo; inferred {len(inferred['datapackage']['resources'])} resource(s)",
214+
)
212215
else:
213216
kind, note = "pointer", f"reads {found}"
214217
if tags:

‎dataherb/catalog/util.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def load_structured(text: str | bytes, name: str = "") -> Any:
2828
return yaml.safe_load(text)
2929

3030

31-
_FRONT_MATTER = re.compile(r"\A---[ \t]*\r?\n(.*?)^(?:---|\.\.\.)[ \t]*(?:\r?\n|\Z)", re.S | re.M)
31+
_FRONT_MATTER = re.compile(
32+
r"\A---[ \t]*\r?\n(.*?)^(?:---|\.\.\.)[ \t]*(?:\r?\n|\Z)", re.S | re.M
33+
)
3234

3335

3436
def split_front_matter(text: str) -> tuple[Any, str]:

‎dataherb/cmd/catalog.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,18 @@ def lint(config_path, min_score):
135135
)
136136
@click.option("--store", "store_name", help="Git store from the config.")
137137
@click.option("--ref", help="Branch, tag or sha to pin.")
138-
@click.option("--tag", "tags", multiple=True, help="Tag for the new entries. Repeatable.")
138+
@click.option(
139+
"--tag", "tags", multiple=True, help="Tag for the new entries. Repeatable."
140+
)
139141
@click.option(
140142
"--api-url",
141143
default="https://api.github.com",
142144
show_default=True,
143145
help="GitHub API, for --org (GitHub Enterprise: https://HOST/api/v3).",
144146
)
145-
@click.option("--include-archived", is_flag=True, help="With --org: keep archived repos.")
147+
@click.option(
148+
"--include-archived", is_flag=True, help="With --org: keep archived repos."
149+
)
146150
@click.option(
147151
"--format",
148152
"fmt",
@@ -209,12 +213,16 @@ def add_to_catalog(
209213
)
210214
colors = {"pointer": "green", "inline": "green", "skipped": "yellow"}
211215
for r in results:
212-
where = r.path.relative_to(cfg.root) if r.path and r.path.is_relative_to(cfg.root) else (r.path or "-")
213-
click.secho(
214-
f"{r.kind:<8} {r.repo} -> {where} ({r.note})", fg=colors[r.kind]
216+
where = (
217+
r.path.relative_to(cfg.root)
218+
if r.path and r.path.is_relative_to(cfg.root)
219+
else (r.path or "-")
215220
)
221+
click.secho(f"{r.kind:<8} {r.repo} -> {where} ({r.note})", fg=colors[r.kind])
216222
added = sum(r.kind != "skipped" for r in results)
217-
click.echo(f"{'would add' if dry_run else 'added'} {added} of {len(results)} repo(s)")
223+
click.echo(
224+
f"{'would add' if dry_run else 'added'} {added} of {len(results)} repo(s)"
225+
)
218226

219227

220228
@catalog.command("serve")

‎tests/catalog/test_add.py‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def _git_repo(path, files):
1616
for name, text in files.items():
1717
(path / name).parent.mkdir(parents=True, exist_ok=True)
1818
(path / name).write_text(text)
19-
run = lambda *a: subprocess.run(["git", *a], cwd=path, check=True, capture_output=True) # noqa: E731
19+
run = lambda *a: subprocess.run(
20+
["git", *a], cwd=path, check=True, capture_output=True
21+
) # noqa: E731
2022
run("init", "-q")
2123
run("add", ".")
2224
run("-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "init")
@@ -60,7 +62,10 @@ def test_add_pointer_inline_and_skip(project, tmp_path):
6062
assert r0["path"] == "data/x.csv" and r0["rows"] == 2
6163
assert not (project / "catalog" / "gone.md").exists()
6264

63-
ds = {d["id"]: d for d in build_catalog(load_config(project / "dataherb.config.yml")).datasets}
65+
ds = {
66+
d["id"]: d
67+
for d in build_catalog(load_config(project / "dataherb.config.yml")).datasets
68+
}
6469
assert ds["meta"]["name"] == "Meta"
6570
assert ds["raw"]["resources"][0]["url"].endswith("/git/acme/raw/HEAD/data/x.csv")
6671

@@ -82,7 +87,10 @@ def fake_get(url, headers=None, timeout=20.0):
8287

8388
monkeypatch.setattr(add_mod, "http_get", fake_get)
8489
assert list_org_repos("o", "dataset") == ["o/dataset-a"]
85-
assert list_org_repos("o", "dataset", include_archived=True) == ["o/Dataset-b", "o/dataset-a"]
90+
assert list_org_repos("o", "dataset", include_archived=True) == [
91+
"o/Dataset-b",
92+
"o/dataset-a",
93+
]
8694
assert seen[0].startswith("https://api.github.com/orgs/o/repos?")
8795

8896

@@ -92,7 +100,14 @@ def test_cli_dry_run(project):
92100
(meta_dir / "dataherb.json").write_text("{}")
93101
res = CliRunner().invoke(
94102
dataherb,
95-
["catalog", "add", "-c", str(project / "dataherb.config.yml"), "--dry-run", "acme/meta"],
103+
[
104+
"catalog",
105+
"add",
106+
"-c",
107+
str(project / "dataherb.config.yml"),
108+
"--dry-run",
109+
"acme/meta",
110+
],
96111
)
97112
assert res.exit_code == 0, res.output
98113
assert "pointer" in res.output and "would add 1 of 1" in res.output
@@ -117,4 +132,7 @@ def test_yml_format(project):
117132
meta_dir.mkdir(parents=True)
118133
(meta_dir / "dataherb.json").write_text("{}")
119134
add_repos(load_config(project / "dataherb.config.yml"), ["acme/meta"], fmt="yml")
120-
assert yaml.safe_load((project / "catalog" / "meta.yml").read_text())["repo"] == "acme/meta"
135+
assert (
136+
yaml.safe_load((project / "catalog" / "meta.yml").read_text())["repo"]
137+
== "acme/meta"
138+
)

‎tests/catalog/test_catalog.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def test_markdown_entries(project):
5151
"---\nid: orders\nrepo: acme/orders\nref: main\ntags: [sales]\n---\n\n"
5252
"## Caveats\n\nRefunds arrive a day late.\n"
5353
)
54-
(cat / "README.md").write_text("# About this folder\n") # no front matter: not an entry
54+
(cat / "README.md").write_text(
55+
"# About this folder\n"
56+
) # no front matter: not an entry
5557
(cat / "notes.md").write_text("---\nid: notes-ds\ninline: true\nname: Notes\n---\n")
5658
res = build_catalog(load_config(project / "dataherb.config.yml"))
5759
ds = by_id(res)

0 commit comments

Comments
 (0)