Update radicli and add static CLI

This commit is contained in:
Ines Montani 2023-02-23 13:45:30 +01:00
parent cb54af10a3
commit 2b469a8449
No known key found for this signature in database
9 changed files with 47 additions and 10 deletions

View File

@ -6,3 +6,4 @@ include spacy/py.typed
recursive-include spacy/cli *.yml
recursive-include licenses *
recursive-exclude spacy *.cpp
include spacy/cli.json

8
generate_static_cli.py Normal file
View File

@ -0,0 +1,8 @@
from wasabi import msg
from spacy.__main__ import FILE
from spacy.cli import setup_cli
if __name__ == "__main__":
cli = setup_cli()
cli.to_static(FILE)
msg.good("Successfully generated static CLI", str(FILE))

View File

@ -11,7 +11,7 @@ srsly>=2.4.3,<3.0.0
catalogue>=2.0.6,<2.1.0
pathy>=0.10.0
smart-open>=5.2.1,<7.0.0
radicli>=0.0.9,<1.0.0
radicli>=0.0.10,<1.0.0
# Third party dependencies
numpy>=1.15.0
requests>=2.13.0,<3.0.0

View File

@ -41,7 +41,7 @@ install_requires =
wasabi>=0.9.1,<1.2.0
srsly>=2.4.3,<3.0.0
catalogue>=2.0.6,<2.1.0
radicli>=0.0.9,<1.0.0
radicli>=0.0.10,<1.0.0
# Third-party dependencies
pathy>=0.10.0
smart-open>=5.2.1,<7.0.0
@ -57,7 +57,7 @@ install_requires =
[options.entry_points]
console_scripts =
spacy = spacy.cli:setup_cli
spacy = spacy.__main__:main
[options.extras_require]
lookups =

View File

@ -1,4 +1,21 @@
if __name__ == "__main__":
from pathlib import Path
FILE = Path(__file__).parent / "cli.json"
def main():
from radicli import StaticRadicli
# TODO: ideally we want to set disable=True for local development, but
# not sure yet how to best determine that?
static = StaticRadicli.load(FILE)
static.run()
from spacy.cli import setup_cli
setup_cli()
cli = setup_cli()
cli.run()
if __name__ == "__main__":
main()

1
spacy/cli.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -56,10 +56,10 @@ cli.placeholder("benchmark", description=BENCHMARK_HELP)
cli.placeholder("init", description=INIT_HELP)
def setup_cli() -> None:
def setup_cli() -> radicli.Radicli:
# Make sure the entry-point for CLI runs, so that they get imported.
registry.cli.get_all()
cli.run()
return cli
def parse_config_overrides(

View File

@ -1157,10 +1157,9 @@ def test_cli_find_threshold(capsys):
)
def test_project_check_requirements(reqs, output):
# excessive guard against unlikely package name
try:
with pytest.raises(pkg_resources.DistributionNotFound):
pkg_resources.require("spacyunknowndoesnotexist12345")
except pkg_resources.DistributionNotFound:
assert output == _check_requirements([req.strip() for req in reqs.split("\n")])
assert output == _check_requirements([req.strip() for req in reqs.split("\n")])
def test_upload_download_local_file():

View File

@ -3,6 +3,8 @@ import os
from pathlib import Path
from spacy.tokens import DocBin, Doc
from spacy.cli._util import cli
from spacy.__main__ import FILE
import json
from .util import make_tempdir, normalize_whitespace
@ -15,6 +17,15 @@ def all_commands():
return result
def test_static_up_to_date():
"""Test that the static JSON matches the current live CLI."""
err = "static CLI doesn't match live CLI, re-run generate_static_cli.py"
with FILE.open("r", encoding="utf8") as f:
existing = f.read()
current = json.dumps(cli.to_static_json())
assert existing == current, err
def test_help_texts(all_commands):
"""Test that all commands provide docstrings and argument help texts."""
for command in all_commands: