Skip to content

Commit 4bf7b40

Browse files
💥 Render code into src directory; reserve extras sub-package for authored code. Change openapi document location to lapidary/openapi
1 parent b5561a9 commit 4bf7b40

File tree

101 files changed

+35
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+35
-41
lines changed

‎docs/index.md

Lines changed: 5 additions & 4 deletions

‎src/lapidary/render/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
class Config(pydantic.BaseModel):
1111
document_path: str | None = None
1212
"""URL or path relative to ./openapi/"""
13-
extra_sources: Sequence[str] = ()
1413
origin: pydantic.AnyHttpUrl | None = None
1514
"""Origin URL in case"""
1615
package: str

‎src/lapidary/render/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def init_project(
3131
document_handler = document_handler_for(anyio.Path(), document_path)
3232

3333
if save_document:
34-
document_root = anyio.Path('src/openapi')
34+
document_root = anyio.Path('lapidary/openapi')
3535
target_dir = project_root / document_root
3636
await target_dir.mkdir(parents=True)
3737
file_name = await document_handler.save_to(target_dir)
@@ -87,8 +87,7 @@ def progress(module: python.AbstractModule) -> None:
8787

8888
await update_project(
8989
model.modules,
90-
project_root / config.extra_sources[0] if config.extra_sources else None,
91-
project_root / 'gen',
90+
project_root / 'src',
9291
config.package,
9392
progress,
9493
)

‎src/lapidary/render/writer.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
2-
import shutil
3-
from collections.abc import Callable, Iterable, Sequence
2+
from collections.abc import Callable, Iterable
3+
from pathlib import PurePath
44

55
import anyio
66
import asyncclick
@@ -32,13 +32,13 @@ def mk_module(module: python.AbstractModule) -> cst.Module | None:
3232

3333
async def update_project(
3434
modules: Iterable[python.AbstractModule],
35-
src_root: anyio.Path | None,
3635
target_root: anyio.Path,
3736
root_package: str,
3837
update_progress: Callable[[python.AbstractModule], None],
3938
):
4039
await target_root.mkdir(parents=True, exist_ok=True)
4140
written: list[anyio.Path] = []
41+
package_extras = PurePath(root_package) / 'extras'
4242
for module in modules:
4343
update_progress(module)
4444
cst_module = mk_module(module)
@@ -57,25 +57,18 @@ async def update_project(
5757
await (target_root / root_package / 'py.typed').write_text('', newline='')
5858
written.append(anyio.Path(root_package, 'py.typed'))
5959

60-
if src_root:
61-
62-
def cp(src: str, names: list[str]) -> Sequence[str]:
63-
local_src = anyio.Path(src)
64-
written.extend((local_src / name).relative_to(src_root) for name in names)
65-
return ()
66-
67-
shutil.copytree(src_root, target_root, ignore=cp, dirs_exist_ok=True)
68-
6960
with asyncclick.progressbar(length=0, label='Removing stale files') as bar:
7061
async for parent, dirs, files in target_root.walk(False):
62+
package = parent.relative_to(target_root)
7163
files_ = set(files)
72-
for existing in files:
73-
path = (parent / existing).relative_to(target_root)
74-
75-
if path not in written:
76-
bar.update(1, str(path))
77-
files_.remove(existing)
78-
await (parent / existing).unlink()
64+
if package != package_extras:
65+
for existing in files:
66+
path = (parent / existing).relative_to(target_root)
67+
68+
if path not in written:
69+
bar.update(1, str(path))
70+
files_.remove(existing)
71+
await (parent / existing).unlink()
7972
if not files_ and not dirs:
8073
bar.update(1, str(parent))
8174
await parent.rmdir()

‎tests/e2e/expected/dummy/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ version = "0.1.0"
99
authors = []
1010
license = ""
1111
packages = [
12-
{ include = 'test_dummy', from = "gen" },
12+
{ include = 'test_dummy', from = "src" },
1313
]
1414

1515
[tool.poetry.dependencies]
1616
python = "^3.9"
1717
lapidary = {path="../../../../../lapidary"}
1818

1919
[tool.lapidary]
20-
document_path = "dummy.yaml"
20+
document_path = "lapidary/openapi/dummy.yaml"
2121
package = "test_dummy"

0 commit comments

Comments
 (0)