Skip to content

Commit 8a6b14a

Browse files
committed
Additional cleanups/fixes
1 parent c7d2fe9 commit 8a6b14a

7 files changed

Lines changed: 34 additions & 26 deletions

File tree

docs/reference/api/cli.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
::: griffecli.main
66

7-
::: griffe.check
7+
::: griffecli.check
88

9-
::: griffe.dump
9+
::: griffecli.dump
1010

1111
## **Advanced API**
1212

13-
::: griffe.get_parser
13+
::: griffecli.get_parser

duties.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from duty.context import Context
2525

2626

27-
PY_SRC_PATHS = (Path(_) for _ in ("src", "tests", "duties.py", "scripts"))
27+
PY_SRC_PATHS = (Path(_) for _ in ("packages/griffecli/src", "packages/griffelib/src", "tests", "duties.py", "scripts"))
2828
PY_SRC_LIST = tuple(str(_) for _ in PY_SRC_PATHS)
2929
PY_SRC = " ".join(PY_SRC_LIST)
3030
CI = os.environ.get("CI", "0") in {"1", "true", "yes", ""}
@@ -287,7 +287,20 @@ def check_api(ctx: Context, *cli_args: str) -> None:
287287
ctx.run(
288288
tools.griffe.check(
289289
"griffe",
290-
search=["src"],
290+
search=["packages/griffelib/src"],
291+
color=True,
292+
extensions=[
293+
"griffe_inherited_docstrings",
294+
"unpack_typeddict",
295+
],
296+
).add_args(*cli_args),
297+
title="Checking for API breaking changes",
298+
nofail=True,
299+
)
300+
ctx.run(
301+
tools.griffe.check(
302+
"griffecli",
303+
search=["packages/griffecli/src"],
291304
color=True,
292305
extensions=[
293306
"griffe_inherited_docstrings",

packages/griffelib/src/griffe/__init__.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,14 +601,9 @@
601601
"main",
602602
]
603603

604-
try:
605-
from griffecli._internal.cli import DEFAULT_LOG_LEVEL, check, dump, get_parser, main
606-
except ImportError:
607-
def __getattr__(attr: str) -> object:
608-
if attr in __cli_all__:
609-
import griffecli._internal.cli as griffecli_mod
610-
return getattr(griffecli_mod, attr)
611-
raise AttributeError(attr)
612-
613-
else:
614-
__all__.extend(__cli_all__)
604+
__all__ += __cli_all__
605+
606+
def __getattr__(attr: str) -> object:
607+
if attr in __cli_all__:
608+
raise ImportError(f'Install `griffecli` to use {"griffe." + attr!r}')
609+
raise AttributeError(attr)

packages/griffelib/src/griffe/__main__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
try:
1212
from griffecli import main
13-
except ModuleNotFoundError:
14-
raise ImportError(
15-
"`griffecli` is not installed. Install `griffecli` "
16-
"to use `python -m griffe`."
17-
)
13+
except ModuleNotFoundError as exc:
14+
raise ModuleNotFoundError(
15+
"`griffecli` or its dependencies are not installed. "
16+
"Install `griffecli` to use `python -m griffe`.",
17+
) from exc
1818

1919
if __name__ == "__main__":
2020
sys.exit(main(sys.argv[1:]))

packages/griffelib/src/griffe/_internal/finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def _handle_editable_module(path: Path) -> list[_SP]:
508508
and node.value.func.id == "install"
509509
and isinstance(node.value.args[1], ast.Constant)
510510
):
511-
build_path = Path(node.value.args[1].value, "src") # type: ignore[arg-type]
511+
build_path = Path(node.value.args[1].value, "packages/griffelib/src") # type: ignore[arg-type]
512512
# NOTE: What if there are multiple packages?
513513
pkg_name = next(build_path.iterdir()).name
514514
return [_SP(build_path, always_scan_for=pkg_name)]

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _public_path(obj: griffe.Object | griffe.Alias) -> bool:
140140
return obj.is_public and (obj.parent is None or _public_path(obj.parent))
141141

142142
multiple_locations = {}
143-
for obj_name in griffe.__all__:
143+
for obj_name in set(griffe.__all__) - set(griffe.__cli_all__):
144144
obj = public_api[obj_name]
145145
if obj.aliases and (
146146
public_aliases := [path for path, alias in obj.aliases.items() if path != obj.path and _public_path(alias)]

tests/test_finder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ def test_editables_file_handling(tmp_path: Path, editable_file_name: str) -> Non
125125
tmp_path: Pytest fixture.
126126
"""
127127
pth_file = tmp_path / editable_file_name
128-
pth_file.write_text("hello\nF.map_module('griffe', 'src/griffe/__init__.py')", encoding="utf8")
128+
pth_file.write_text("hello\nF.map_module('griffe', 'packages/griffelib/src/griffe/__init__.py')", encoding="utf8")
129129
paths = [sp.path for sp in _handle_editable_module(pth_file)]
130-
assert paths == [Path("src")]
130+
assert paths == [Path("packages/griffelib/src")]
131131

132132

133133
@pytest.mark.parametrize("annotation", ["", ": dict[str, str]"])
@@ -197,7 +197,7 @@ def test_meson_python_file_handling(tmp_path: Path) -> None:
197197
search_paths = _handle_editable_module(pth_file)
198198
assert all(sp.always_scan_for == "griffe" for sp in search_paths)
199199
paths = [sp.path for sp in search_paths]
200-
assert paths == [Path("src")]
200+
assert paths == [Path("packages/griffelib/src")]
201201

202202

203203
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)