Skip to content

Commit b4f2549

Browse files
author
David Andersson
committed
unify variable names and types
1 parent 84e778c commit b4f2549

2 files changed

Lines changed: 35 additions & 24 deletions

File tree

open_alchemy/build/__init__.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ def calculate_spec_info(*, schemas: types.Schemas, spec: typing.Any) -> TSpecInf
197197
)
198198

199199

200-
def generate_setup(*, name: str, version: str) -> str:
200+
TName = str
201+
202+
203+
def generate_setup(*, name: TName, version: TVersion) -> str:
201204
"""
202205
Generate the content of the setup.py file.
203206
@@ -217,7 +220,7 @@ def generate_setup(*, name: str, version: str) -> str:
217220
)
218221

219222

220-
def generate_manifest(*, name: str) -> str:
223+
def generate_manifest(*, name: TName) -> str:
221224
"""
222225
Generate the content of the MANIFEST.in file.
223226
@@ -286,8 +289,17 @@ def generate_init(open_alchemy: str, models_file: str) -> str:
286289
)
287290

288291

292+
TPath = str
293+
294+
289295
def dump(
290-
*, path: str, name: str, setup: str, manifest: str, spec: str, init: str
296+
*,
297+
path: TPath,
298+
name: TName,
299+
setup: str,
300+
manifest: str,
301+
spec_str: TSpecStr,
302+
init: str,
291303
) -> None:
292304
"""
293305
Dump the files needed for the package at a path.
@@ -311,13 +323,13 @@ def dump(
311323
# Write files in the package directory.
312324
package = directory / name
313325
package.mkdir(parents=True, exist_ok=True)
314-
(package / "spec.json").write_text(spec)
326+
(package / "spec.json").write_text(spec_str)
315327
(package / "__init__.py").write_text(init)
316328
except OSError as exc:
317329
raise exceptions.BuildError(str(exc)) from exc
318330

319331

320-
def build_dist(name: str, path: str, format_: PackageFormat) -> None:
332+
def build_dist(name: TName, path: TPath, format_: PackageFormat) -> None:
321333
"""
322334
Build a distribution package.
323335
@@ -338,7 +350,7 @@ def build_dist(name: str, path: str, format_: PackageFormat) -> None:
338350
build_wheel(name, path)
339351

340352

341-
def build_sdist(name: str, path: str) -> None:
353+
def build_sdist(name: TName, path: TPath) -> None:
342354
"""
343355
Build a .tar.gz source distribution and place it in a "dist" folder.
344356
@@ -351,7 +363,7 @@ def build_sdist(name: str, path: str) -> None:
351363
helpers.command.run([sys.executable, "setup.py", "sdist"], str(pkg_dir))
352364

353365

354-
def build_wheel(name: str, path: str) -> None:
366+
def build_wheel(name: TName, path: TPath) -> None:
355367
"""
356368
Build a .whl package and place it in a "dist" folder.
357369
@@ -373,8 +385,8 @@ def build_wheel(name: str, path: str) -> None:
373385
def execute(
374386
*,
375387
spec: typing.Any,
376-
name: str,
377-
path: str,
388+
name: TName,
389+
path: TPath,
378390
format_: PackageFormat,
379391
) -> None:
380392
"""
@@ -402,7 +414,7 @@ def execute(
402414
name=name,
403415
setup=setup,
404416
manifest=manifest,
405-
spec=spec_info.spec_str,
417+
spec_str=spec_info.spec_str,
406418
init=init,
407419
)
408420

tests/open_alchemy/test_build.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,12 @@ def test_calculate_spec_info_version():
125125
WHEN calculate_spec_info is called with the spec
126126
THEN the version is returned.
127127
"""
128-
version = "version 1"
129-
spec = {"info": {"version": version}}
128+
spec = {}
130129
schemas = {}
131130

132131
spec_info = build.calculate_spec_info(spec=spec, schemas=schemas)
133132

134-
assert spec_info.version == version
133+
assert spec_info.version == "63581fa2bdc5cef14183"
135134

136135

137136
@pytest.mark.parametrize(
@@ -394,15 +393,15 @@ def test_dump(tmp_path):
394393
name = "name 1"
395394
setup = "setup file"
396395
manifest = "manifest file"
397-
spec = "spec file"
396+
spec_str = "spec file"
398397
init = "init file"
399398

400399
build.dump(
401400
path=str(dist_path),
402401
name=name,
403402
setup=setup,
404403
manifest=manifest,
405-
spec=spec,
404+
spec_str=spec_str,
406405
init=init,
407406
)
408407

@@ -426,7 +425,7 @@ def test_dump(tmp_path):
426425
expected_spec_path = package_path / "spec.json"
427426
assert expected_spec_path.is_file()
428427
with open(expected_spec_path) as in_file:
429-
assert in_file.read() == spec
428+
assert in_file.read() == spec_str
430429

431430
# Check init file
432431
expected_init_path = package_path / "__init__.py"
@@ -447,15 +446,15 @@ def test_dump_path_not_exists(tmp_path):
447446
name = "name 1"
448447
setup = "setup file"
449448
manifest = "manifest file"
450-
spec = "spec file"
449+
spec_str = "spec file"
451450
init = "init file"
452451

453452
build.dump(
454453
path=str(dist_path),
455454
name=name,
456455
setup=setup,
457456
manifest=manifest,
458-
spec=spec,
457+
spec_str=spec_str,
459458
init=init,
460459
)
461460

@@ -474,7 +473,7 @@ def test_dump_path_is_file(tmp_path):
474473
name = "name 1"
475474
setup = "setup file"
476475
manifest = "manifest file"
477-
spec = "spec file"
476+
spec_str = "spec file"
478477
init = "init file"
479478

480479
with pytest.raises(exceptions.BuildError):
@@ -483,7 +482,7 @@ def test_dump_path_is_file(tmp_path):
483482
name=name,
484483
setup=setup,
485484
manifest=manifest,
486-
spec=spec,
485+
spec_str=spec_str,
487486
init=init,
488487
)
489488

@@ -501,7 +500,7 @@ def test_dump_path_name_exists(tmp_path):
501500
name = "name 1"
502501
setup = "setup file"
503502
manifest = "manifest file"
504-
spec = "spec file"
503+
spec_str = "spec file"
505504
init = "init file"
506505

507506
(dist_path / name).mkdir()
@@ -511,7 +510,7 @@ def test_dump_path_name_exists(tmp_path):
511510
name=name,
512511
setup=setup,
513512
manifest=manifest,
514-
spec=spec,
513+
spec_str=spec_str,
515514
init=init,
516515
)
517516

@@ -529,7 +528,7 @@ def test_dump_path_name_is_file(tmp_path):
529528
name = "name 1"
530529
setup = "setup file"
531530
manifest = "manifest file"
532-
spec = "spec file"
531+
spec_str = "spec file"
533532
init = "init file"
534533

535534
with open(dist_path / name, "w") as out_file:
@@ -541,7 +540,7 @@ def test_dump_path_name_is_file(tmp_path):
541540
name=name,
542541
setup=setup,
543542
manifest=manifest,
544-
spec=spec,
543+
spec_str=spec_str,
545544
init=init,
546545
)
547546

0 commit comments

Comments
 (0)