mirror of
https://github.com/explosion/spaCy.git
synced 2025-06-22 14:03:05 +03:00
Add cli for finding locations of registered func
This commit is contained in:
parent
e1664217f5
commit
a96e4eb307
|
@ -14,6 +14,7 @@ from .debug_diff import debug_diff # noqa: F401
|
||||||
from .debug_model import debug_model # noqa: F401
|
from .debug_model import debug_model # noqa: F401
|
||||||
from .download import download # noqa: F401
|
from .download import download # noqa: F401
|
||||||
from .evaluate import evaluate # noqa: F401
|
from .evaluate import evaluate # noqa: F401
|
||||||
|
from .find_loc import find_loc # noqa: F401
|
||||||
from .find_threshold import find_threshold # noqa: F401
|
from .find_threshold import find_threshold # noqa: F401
|
||||||
from .info import info # noqa: F401
|
from .info import info # noqa: F401
|
||||||
from .init_config import fill_config, init_config # noqa: F401
|
from .init_config import fill_config, init_config # noqa: F401
|
||||||
|
|
51
spacy/cli/find_loc.py
Normal file
51
spacy/cli/find_loc.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
from wasabi import msg
|
||||||
|
|
||||||
|
from ._util import Arg, Opt, app
|
||||||
|
|
||||||
|
from ..util import registry
|
||||||
|
from catalogue import RegistryError
|
||||||
|
|
||||||
|
|
||||||
|
@app.command("find-loc")
|
||||||
|
def find_loc(
|
||||||
|
# fmt: off
|
||||||
|
func_name: str = Arg(..., help="Name of the registered function."),
|
||||||
|
registry_name: str = Opt(None, help="Name of the catalogue registry."),
|
||||||
|
# fmt: on
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Find the module, path and line number to the file the registered
|
||||||
|
function is defined in, if available.
|
||||||
|
|
||||||
|
func_name (str): Name of the registered function.
|
||||||
|
registry_name (str): Name of the catalogue registry.
|
||||||
|
"""
|
||||||
|
registry_names = registry.get_registry_names()
|
||||||
|
for name in registry_names:
|
||||||
|
if registry.has(name, func_name):
|
||||||
|
registry_name = name
|
||||||
|
break
|
||||||
|
|
||||||
|
find_loc(func_name, registry_name)
|
||||||
|
|
||||||
|
|
||||||
|
def find_loc(registry_func, registry_name):
|
||||||
|
try:
|
||||||
|
registry_desc = registry.find(registry_name, registry_func)
|
||||||
|
|
||||||
|
except RegistryError as e:
|
||||||
|
msg.fail(
|
||||||
|
f"Couldn't find registered function: {registry_func}\n\n{e}",
|
||||||
|
exits=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
if registry_desc["file"]:
|
||||||
|
registry_path = registry_desc["file"]
|
||||||
|
line_no = registry_desc["line_no"]
|
||||||
|
else:
|
||||||
|
msg.fail(
|
||||||
|
f"Couldn't find path to registered function: {registry_func}",
|
||||||
|
exits=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
msg.good(f"Found registered function at file://{registry_path}:{line_no}")
|
Loading…
Reference in New Issue
Block a user