Fix and simplify info

This commit is contained in:
Ines Montani 2020-06-22 01:07:48 +02:00
parent fca3907d4e
commit 189ed56777
2 changed files with 8 additions and 10 deletions

View File

@ -8,7 +8,7 @@ warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
from thinc.api import prefer_gpu, require_gpu
from . import pipeline
from .cli.info import info as cli_info
from .cli.info import info
from .glossary import explain
from .about import __version__
from .errors import Errors, Warnings
@ -34,7 +34,3 @@ def load(name, **overrides):
def blank(name, **kwargs):
LangClass = util.get_lang_class(name)
return LangClass(**kwargs)
def info(model=None, markdown=False, silent=False):
return cli_info(model, markdown, silent)

View File

@ -5,7 +5,6 @@ from wasabi import Printer
import srsly
from ._app import app, Arg, Opt
from .validate import get_model_pkgs
from .. import util
from .. import about
@ -27,7 +26,7 @@ def info_cli(
def info(
model: Optional[str], *, markdown: bool = False, silent: bool = True
model: Optional[str] = None, *, markdown: bool = False, silent: bool = True
) -> Union[str, dict]:
msg = Printer(no_print=silent, pretty=not silent)
if model:
@ -43,7 +42,7 @@ def info(
return markdown_data
if not silent:
msg.table(data, title=title)
return data
return {k.lower().replace(" ", "_"): v for k, v in data.items()}
def info_spacy(*, silent: bool = True) -> Dict[str, any]:
@ -52,8 +51,11 @@ def info_spacy(*, silent: bool = True) -> Dict[str, any]:
silent (bool): Don't print anything, just return.
RETURNS (dict): The spaCy info.
"""
all_models, _ = get_model_pkgs(silent=silent)
models = ", ".join(f"{m['name']} ({m['version']})" for m in all_models.values())
all_models = {}
for pkg_name in util.get_installed_models():
package = pkg_name.replace("-", "_")
all_models[package] = util.get_package_version(pkg_name)
models = ", ".join(f"{name} ({version})" for name, version in all_models.items())
return {
"spaCy version": about.__version__,
"Location": str(Path(__file__).parent.parent),