Fix package cli auto-completions (#596)

This commit is contained in:
Matthew Tancik authored and GitHub committed 2022-10-01 10:55:49 -07:00
1 parent 31d26e2436
commit 1b9f42384e
2 files changed
+17 -20

No files matched your search

+10 -18
View File
@@ -22,6 +22,15 @@ ShellType = Literal["zsh", "bash"]
CONSOLE = Console(width=120)
ENTRYPOINTS = [
"ns-install-cli",
"ns-process-data",
"ns-download-data",
"ns-train",
"ns-eval",
"ns-dev-test",
]
def _check_dcargs_cli(script_path: pathlib.Path) -> bool:
"""Check if a path points to a script containing a dcargs.cli() call. Also checks
@@ -211,23 +220,6 @@ def main(
# Find dcargs CLIs.
script_paths = list(filter(_check_dcargs_cli, scripts_dir.glob("**/*.py"))) if include_scripts else []
entry_points = (
# Read pyproject.toml.
(scripts_dir.parent / "pyproject.toml")
.read_text()
# Get entrypoint lines.
.partition("[project.scripts]")[2]
.partition("[")[0]
# Split into list of strings, which should each be of the format:
# `entrypoint = "scripts.something:entrypoint"`
.strip()
.split("\n")
)
entry_points = list(
# ns-train = "..." ==> ns-train
e.partition("=")[0].strip()
for e in entry_points
)
script_names = tuple(p.name for p in script_paths)
assert len(set(script_names)) == len(script_names)
@@ -246,7 +238,7 @@ def main(
lambda path_or_entrypoint_and_shell: _generate_completion(
path_or_entrypoint_and_shell[0], path_or_entrypoint_and_shell[1], completions_dir
),
itertools.product(script_paths + entry_points, shells_found),
itertools.product(script_paths + ENTRYPOINTS, shells_found),
)
)