Skip to content

Commit 983fa00

Browse files
committed
fix: rename ambiguous variable l to ln (ruff E741)
1 parent 3ea85eb commit 983fa00

5 files changed

Lines changed: 139 additions & 36 deletions

File tree

src/dbx_python_cli/commands/project.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def _fix_broken_editable_installs(
608608
url = data.get("url", "")
609609
if not url.startswith("file://"):
610610
continue
611-
source_path = Path(url[len("file://"):])
611+
source_path = Path(url[len("file://") :])
612612
if source_path.exists() and (
613613
(source_path / "pyproject.toml").exists()
614614
or (source_path / "setup.py").exists()
@@ -664,13 +664,28 @@ def _ensure_package_installed(
664664
repo_name = import_name.replace("_", "-")
665665

666666
if base_dir is not None:
667-
for clone_path in [Path(base_dir) / repo_name, Path(base_dir) / "django" / repo_name]:
667+
for clone_path in [
668+
Path(base_dir) / repo_name,
669+
Path(base_dir) / "django" / repo_name,
670+
]:
668671
if clone_path.exists() and (
669-
(clone_path / "pyproject.toml").exists() or (clone_path / "setup.py").exists()
672+
(clone_path / "pyproject.toml").exists()
673+
or (clone_path / "setup.py").exists()
670674
):
671-
typer.echo(f"📦 Installing {repo_name} from local clone at {clone_path}...")
675+
typer.echo(
676+
f"📦 Installing {repo_name} from local clone at {clone_path}..."
677+
)
672678
subprocess.run(
673-
["uv", "pip", "install", "--reinstall", "--python", python_path, "-e", str(clone_path)],
679+
[
680+
"uv",
681+
"pip",
682+
"install",
683+
"--reinstall",
684+
"--python",
685+
python_path,
686+
"-e",
687+
str(clone_path),
688+
],
674689
capture_output=not verbose,
675690
check=False,
676691
)
@@ -985,7 +1000,9 @@ def run_project(
9851000
_fix_broken_editable_installs(python_path, proj.project_path, verbose)
9861001

9871002
# Ensure django_mongodb_extensions is available: prefer a local clone over PyPI.
988-
_ensure_package_installed("django_mongodb_extensions", python_path, proj.base_dir, verbose)
1003+
_ensure_package_installed(
1004+
"django_mongodb_extensions", python_path, proj.base_dir, verbose
1005+
)
9891006

9901007
# Check if frontend exists
9911008
frontend_path = proj.project_path / "frontend"

src/dbx_python_cli/commands/spec.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# Helpers
3131
# ---------------------------------------------------------------------------
3232

33+
3334
def _find_specs_dir(config, base_dir) -> Path | None:
3435
"""Find the specifications repo directory via the repo config."""
3536
repo = find_repo_by_name("specifications", base_dir, config)
@@ -100,13 +101,19 @@ def _apply_patches(driver_repo, verbose: bool = False) -> bool:
100101
return True
101102

102103
cmd = [
103-
"git", "apply", "-R", "--allow-empty", "--whitespace=fix",
104+
"git",
105+
"apply",
106+
"-R",
107+
"--allow-empty",
108+
"--whitespace=fix",
104109
*[str(p) for p in patches],
105110
]
106111
if verbose:
107112
typer.echo(f"[verbose] Running: {' '.join(cmd)}")
108113

109-
result = subprocess.run(cmd, cwd=str(driver_repo["path"]), check=False, capture_output=True, text=True)
114+
result = subprocess.run(
115+
cmd, cwd=str(driver_repo["path"]), check=False, capture_output=True, text=True
116+
)
110117
if result.returncode != 0:
111118
typer.echo(f"❌ Failed to apply patches: {result.stderr.strip()}", err=True)
112119
return False
@@ -117,6 +124,7 @@ def _apply_patches(driver_repo, verbose: bool = False) -> bool:
117124
# dbx spec sync
118125
# ---------------------------------------------------------------------------
119126

127+
120128
@app.command("sync")
121129
def spec_sync(
122130
ctx: typer.Context,
@@ -186,13 +194,17 @@ def spec_sync(
186194
else:
187195
mdb_specs = _find_specs_dir(config, base_dir)
188196
if not mdb_specs:
189-
typer.echo("❌ Error: Could not find the 'specifications' repository", err=True)
197+
typer.echo(
198+
"❌ Error: Could not find the 'specifications' repository", err=True
199+
)
190200
typer.echo("\nClone it with: dbx clone specifications")
191201
typer.echo("Or specify the path with: --specs-dir <path>")
192202
raise typer.Exit(1)
193203

194204
if not mdb_specs.exists():
195-
typer.echo(f"❌ Error: Specifications directory not found: {mdb_specs}", err=True)
205+
typer.echo(
206+
f"❌ Error: Specifications directory not found: {mdb_specs}", err=True
207+
)
196208
raise typer.Exit(1)
197209

198210
script = driver_repo["path"] / ".evergreen" / "resync-specs.sh"
@@ -223,7 +235,9 @@ def spec_sync(
223235
typer.echo(f" Working directory: {cwd}")
224236
patch_count = len(_list_patches(_get_patch_dir(driver_repo)))
225237
if patch_count:
226-
typer.echo(f"\n📋 {patch_count} patch(es) would be applied with --apply-patches")
238+
typer.echo(
239+
f"\n📋 {patch_count} patch(es) would be applied with --apply-patches"
240+
)
227241
return
228242

229243
spec_label = ", ".join(specs) if specs else "all"
@@ -248,6 +262,7 @@ def spec_sync(
248262
# dbx spec list
249263
# ---------------------------------------------------------------------------
250264

265+
251266
@app.command("list")
252267
def spec_list(
253268
ctx: typer.Context,
@@ -273,13 +288,17 @@ def spec_list(
273288
else:
274289
mdb_specs = _find_specs_dir(config, base_dir)
275290
if not mdb_specs:
276-
typer.echo("❌ Error: Could not find the 'specifications' repository", err=True)
291+
typer.echo(
292+
"❌ Error: Could not find the 'specifications' repository", err=True
293+
)
277294
typer.echo("\nClone it with: dbx clone specifications")
278295
typer.echo("Or specify the path with: --specs-dir <path>")
279296
raise typer.Exit(1)
280297

281298
if not mdb_specs.exists():
282-
typer.echo(f"❌ Error: Specifications directory not found: {mdb_specs}", err=True)
299+
typer.echo(
300+
f"❌ Error: Specifications directory not found: {mdb_specs}", err=True
301+
)
283302
raise typer.Exit(1)
284303

285304
source_dir = mdb_specs / "source"
@@ -289,7 +308,9 @@ def spec_list(
289308
typer.echo(f"[verbose] Listing specs in: {search_dir}\n")
290309

291310
spec_dirs = sorted(
292-
d.name for d in search_dir.iterdir() if d.is_dir() and not d.name.startswith(".")
311+
d.name
312+
for d in search_dir.iterdir()
313+
if d.is_dir() and not d.name.startswith(".")
293314
)
294315

295316
if not spec_dirs:
@@ -307,6 +328,7 @@ def spec_list(
307328
# dbx spec patch list
308329
# ---------------------------------------------------------------------------
309330

331+
310332
@patch_app.command("list")
311333
def patch_list(
312334
ctx: typer.Context,
@@ -352,6 +374,7 @@ def patch_list(
352374
# dbx spec patch create
353375
# ---------------------------------------------------------------------------
354376

377+
355378
@patch_app.command("create")
356379
def patch_create(
357380
ctx: typer.Context,
@@ -425,7 +448,9 @@ def patch_create(
425448
diff = result.stdout
426449
if not diff.strip():
427450
typer.echo("❌ No changes to capture (git diff is empty)", err=True)
428-
typer.echo("\nMake sure you have unstaged changes in the driver repo after syncing.")
451+
typer.echo(
452+
"\nMake sure you have unstaged changes in the driver repo after syncing."
453+
)
429454
raise typer.Exit(1)
430455

431456
if dry_run:
@@ -447,6 +472,7 @@ def patch_create(
447472
# dbx spec patch remove
448473
# ---------------------------------------------------------------------------
449474

475+
450476
@patch_app.command("remove")
451477
def patch_remove(
452478
ctx: typer.Context,
@@ -488,6 +514,7 @@ def patch_remove(
488514
# dbx spec patch apply
489515
# ---------------------------------------------------------------------------
490516

517+
491518
@patch_app.command("apply")
492519
def patch_apply(
493520
ctx: typer.Context,
@@ -527,7 +554,9 @@ def patch_apply(
527554
typer.echo(f"No patch files found in {patch_dir}")
528555
return
529556

530-
typer.echo(f"🩹 {'Would apply' if dry_run else 'Applying'} {len(patches)} patch(es) to {repo_name}:")
557+
typer.echo(
558+
f"🩹 {'Would apply' if dry_run else 'Applying'} {len(patches)} patch(es) to {repo_name}:"
559+
)
531560
for p in patches:
532561
files = _parse_patch_files(p)
533562
typer.echo(f" • {p.stem} ({len(files)} file(s))")

src/dbx_python_cli/templates/project_template/project_name/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def get_context_data(self, **kwargs):
88
context = super().get_context_data(**kwargs)
99
try:
1010
from wagtail.models import Site
11+
1112
site = Site.find_for_request(self.request)
1213
if site:
1314
context["wagtail_site"] = site

tests/test_project_command.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ def test_enable_wagtail_activates_settings(tmp_path):
259259
assert "from .wagtail import * # noqa" in content
260260
assert "INSTALLED_APPS += WAGTAIL_INSTALLED_APPS # noqa: F405" in content
261261
assert "MIDDLEWARE += WAGTAIL_MIDDLEWARE # noqa: F405" in content
262-
assert "MIGRATION_MODULES.update(WAGTAIL_MIGRATION_MODULES) # noqa: F405" in content
262+
assert (
263+
"MIGRATION_MODULES.update(WAGTAIL_MIGRATION_MODULES) # noqa: F405" in content
264+
)
263265

264266

265267
def test_enable_wagtail_adds_url_patterns(tmp_path):
@@ -290,7 +292,9 @@ def test_create_pyproject_toml_includes_wagtail_dep(tmp_path):
290292
_create_pyproject_toml(tmp_path, "myproject", wagtail=True)
291293

292294
content = (tmp_path / "pyproject.toml").read_text()
293-
deps_section = content[content.index("dependencies"):content.index("[project.optional-dependencies]")]
295+
deps_section = content[
296+
content.index("dependencies") : content.index("[project.optional-dependencies]")
297+
]
294298
assert '"wagtail"' in deps_section
295299

296300

@@ -301,7 +305,9 @@ def test_create_pyproject_toml_excludes_wagtail_dep_by_default(tmp_path):
301305
_create_pyproject_toml(tmp_path, "myproject")
302306

303307
content = (tmp_path / "pyproject.toml").read_text()
304-
deps_section = content[content.index("dependencies"):content.index("[project.optional-dependencies]")]
308+
deps_section = content[
309+
content.index("dependencies") : content.index("[project.optional-dependencies]")
310+
]
305311
assert '"wagtail"' not in deps_section
306312

307313

@@ -323,7 +329,9 @@ def test_fix_broken_editable_installs_reinstalls_missing_source(tmp_path):
323329
dist_info = site_packages / "wagtail-7.4a0.dist-info"
324330
dist_info.mkdir()
325331
(dist_info / "direct_url.json").write_text(
326-
json.dumps({"dir_info": {"editable": True}, "url": "file:///nonexistent/wagtail"})
332+
json.dumps(
333+
{"dir_info": {"editable": True}, "url": "file:///nonexistent/wagtail"}
334+
)
327335
)
328336
(dist_info / "top_level.txt").write_text("wagtail\n")
329337

@@ -362,14 +370,18 @@ def test_fix_broken_editable_installs_skips_undeclared_packages(tmp_path):
362370
dist_info = site_packages / "old_project-1.0.dist-info"
363371
dist_info.mkdir()
364372
(dist_info / "direct_url.json").write_text(
365-
json.dumps({"dir_info": {"editable": True}, "url": "file:///nonexistent/old-project"})
373+
json.dumps(
374+
{"dir_info": {"editable": True}, "url": "file:///nonexistent/old-project"}
375+
)
366376
)
367377
(dist_info / "top_level.txt").write_text("old_project\n")
368378

369379
python_path = "/fake/python"
370380

371381
with patch("dbx_python_cli.commands.project.subprocess.run") as mock_run:
372-
mock_run.return_value = MagicMock(returncode=0, stdout=str(site_packages), stderr="")
382+
mock_run.return_value = MagicMock(
383+
returncode=0, stdout=str(site_packages), stderr=""
384+
)
373385
_fix_broken_editable_installs(python_path, project_path)
374386

375387
# Only the site.getsitepackages() call — no import check, no reinstall
@@ -404,7 +416,9 @@ def test_fix_broken_editable_installs_skips_valid_source(tmp_path):
404416
python_path = "/fake/python"
405417

406418
with patch("dbx_python_cli.commands.project.subprocess.run") as mock_run:
407-
mock_run.return_value = MagicMock(returncode=0, stdout=str(site_packages), stderr="")
419+
mock_run.return_value = MagicMock(
420+
returncode=0, stdout=str(site_packages), stderr=""
421+
)
408422
_fix_broken_editable_installs(python_path, project_path)
409423

410424
# Only the site.getsitepackages() call — source is valid, no reinstall

0 commit comments

Comments
 (0)