Add additional note for interactive sessions

This commit is contained in:
shadeMe 2023-10-24 10:46:18 +02:00
parent 92ebb931bf
commit be4a7aab86
No known key found for this signature in database
GPG Key ID: 6FCA9FC635B2A402
2 changed files with 17 additions and 1 deletions

View File

@ -9,6 +9,7 @@ from .. import about
from ..errors import OLD_MODEL_SHORTCUTS
from ..util import (
get_minor_version,
is_in_interactive,
is_in_jupyter,
is_package,
is_prerelease_version,
@ -95,6 +96,11 @@ def download(
"You can do this clicking on the 'Restart Kernel' button (or "
"'Restart Runtime' button in the case of Google Colab)"
)
elif is_in_interactive():
reload_deps_msg = (
f"{reload_deps_msg}This includes the current interactive Python session: "
"You can do this by pressing 'Ctrl+D' (or 'Ctrl+Z' and 'Enter' on Windows)."
)
msg.info(
"Reloading dependencies",
reload_deps_msg,

View File

@ -43,11 +43,12 @@ import catalogue
import langcodes
import numpy
import srsly
import thinc
from catalogue import Registry, RegistryError
from packaging.requirements import Requirement
from packaging.specifiers import InvalidSpecifier, SpecifierSet
from packaging.version import InvalidVersion, Version
import thinc
from thinc.api import (
Adam,
Config,
@ -1111,6 +1112,15 @@ def is_in_jupyter() -> bool:
return False
def is_in_interactive() -> bool:
"""Check if user is running spaCy from an interactive Python
shell. Will return True in Jupyter notebooks too.
RETURNS (bool): True if in interactive mode, False if not.
"""
# https://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode
return hasattr(sys, "ps1") or hasattr(sys, "ps2")
def get_object_name(obj: Any) -> str:
"""Get a human-readable name of a Python object, e.g. a pipeline component.