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 ..errors import OLD_MODEL_SHORTCUTS
from ..util import ( from ..util import (
get_minor_version, get_minor_version,
is_in_interactive,
is_in_jupyter, is_in_jupyter,
is_package, is_package,
is_prerelease_version, is_prerelease_version,
@ -95,6 +96,11 @@ def download(
"You can do this clicking on the 'Restart Kernel' button (or " "You can do this clicking on the 'Restart Kernel' button (or "
"'Restart Runtime' button in the case of Google Colab)" "'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( msg.info(
"Reloading dependencies", "Reloading dependencies",
reload_deps_msg, reload_deps_msg,

View File

@ -43,11 +43,12 @@ import catalogue
import langcodes import langcodes
import numpy import numpy
import srsly import srsly
import thinc
from catalogue import Registry, RegistryError from catalogue import Registry, RegistryError
from packaging.requirements import Requirement from packaging.requirements import Requirement
from packaging.specifiers import InvalidSpecifier, SpecifierSet from packaging.specifiers import InvalidSpecifier, SpecifierSet
from packaging.version import InvalidVersion, Version from packaging.version import InvalidVersion, Version
import thinc
from thinc.api import ( from thinc.api import (
Adam, Adam,
Config, Config,
@ -1111,6 +1112,15 @@ def is_in_jupyter() -> bool:
return False 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: def get_object_name(obj: Any) -> str:
"""Get a human-readable name of a Python object, e.g. a pipeline component. """Get a human-readable name of a Python object, e.g. a pipeline component.