Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to session-info2 #3384

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies = [
"umap-learn>=0.5,!=0.5.0",
"pynndescent>=0.5",
"packaging>=21.3",
"session-info",
"session-info2",
"legacy-api-wrap>=1.4", # for positional API deprecations
"typing-extensions; python_version < '3.13'",
]
Expand Down
92 changes: 25 additions & 67 deletions src/scanpy/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

import logging
import sys
import warnings
from datetime import datetime, timedelta, timezone
from functools import partial, update_wrapper
from logging import CRITICAL, DEBUG, ERROR, INFO, WARNING
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, overload

import anndata.logging

from ._compat import deprecated

if TYPE_CHECKING:
from typing import IO

from session_info2 import SessionInfo

from ._settings import ScanpyConfig


Expand Down Expand Up @@ -127,33 +130,11 @@
get_memory_usage = anndata.logging.get_memory_usage


_DEPENDENCIES_NUMERICS = [
"anndata", # anndata actually shouldn't, but as long as it's in development
"umap",
"numpy",
"scipy",
"pandas",
("sklearn", "scikit-learn"),
"statsmodels",
"igraph",
"louvain",
"leidenalg",
"pynndescent",
]


def _versions_dependencies(dependencies):
# this is not the same as the requirements!
for mod in dependencies:
mod_name, dist_name = mod if isinstance(mod, tuple) else (mod, mod)
try:
imp = __import__(mod_name)
yield dist_name, imp.__version__
except (ImportError, AttributeError):
pass


def print_header(*, file=None):
@overload
def print_header(*, file: None = None) -> SessionInfo: ...
@overload
def print_header(*, file: IO[str]) -> None: ...
def print_header(*, file: IO[str] | None = None):
"""\
Versions that might influence the numerical results.
Matplotlib and Seaborn are excluded from this.
Expand All @@ -163,50 +144,27 @@
file
Optional path for dependency output.
"""
from session_info2 import session_info

modules = ["scanpy"] + _DEPENDENCIES_NUMERICS
print(
" ".join(f"{mod}=={ver}" for mod, ver in _versions_dependencies(modules)),
file=file or sys.stdout,
)
sinfo = session_info(os=True, cpu=True, gpu=True, dependencies=True)

if file is not None:
print(sinfo, file=file)
return

Check warning on line 153 in src/scanpy/logging.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/logging.py#L152-L153

Added lines #L152 - L153 were not covered by tests

return sinfo


def print_versions(*, file: IO[str] | None = None):
@deprecated("Use `print_header` instead")
def print_versions() -> SessionInfo:
"""\
Print versions of imported packages, OS, and jupyter environment.
Alias for `print_header`.

For more options (including rich output) use `session_info.show` directly.
.. deprecated:: 1.11.0

Parameters
----------
file
Optional path for output.
Use :func:`print_header` instead.
"""
import session_info

if file is not None:
from contextlib import redirect_stdout

warnings.warn(
"Passing argument 'file' to print_versions is deprecated, and will be "
"removed in a future version.",
FutureWarning,
)
with redirect_stdout(file):
print_versions()
else:
session_info.show(
dependencies=True,
html=False,
excludes=[
"builtins",
"stdlib_list",
"importlib_metadata",
# Special module present if test coverage being calculated
# https://gitlab.com/joelostblom/session_info/-/issues/10
"$coverage",
],
)
return print_header()


def print_version_and_date(*, file=None):
Expand Down Expand Up @@ -235,7 +193,7 @@
def error(
msg: str,
*,
time: datetime = None,
time: datetime | None = None,
deep: str | None = None,
extra: dict | None = None,
) -> datetime:
Expand Down
Loading