Skip to content

Commit 6ae5682

Browse files
committed
Switch to session-info2
1 parent 7131500 commit 6ae5682

File tree

2 files changed

+26
-68
lines changed

2 files changed

+26
-68
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dependencies = [
6464
"umap-learn>=0.5,!=0.5.0",
6565
"pynndescent>=0.5",
6666
"packaging>=21.3",
67-
"session-info",
67+
"session-info2",
6868
"legacy-api-wrap>=1.4", # for positional API deprecations
6969
"typing-extensions; python_version < '3.13'",
7070
]

src/scanpy/logging.py

Lines changed: 25 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44

55
import logging
66
import sys
7-
import warnings
87
from datetime import datetime, timedelta, timezone
98
from functools import partial, update_wrapper
109
from logging import CRITICAL, DEBUG, ERROR, INFO, WARNING
11-
from typing import TYPE_CHECKING
10+
from typing import TYPE_CHECKING, overload
1211

1312
import anndata.logging
1413

14+
from ._compat import deprecated
15+
1516
if TYPE_CHECKING:
1617
from typing import IO
1718

19+
from session_info2 import SessionInfo
20+
1821
from ._settings import ScanpyConfig
1922

2023

@@ -127,33 +130,11 @@ def format(self, record: logging.LogRecord):
127130
get_memory_usage = anndata.logging.get_memory_usage
128131

129132

130-
_DEPENDENCIES_NUMERICS = [
131-
"anndata", # anndata actually shouldn't, but as long as it's in development
132-
"umap",
133-
"numpy",
134-
"scipy",
135-
"pandas",
136-
("sklearn", "scikit-learn"),
137-
"statsmodels",
138-
"igraph",
139-
"louvain",
140-
"leidenalg",
141-
"pynndescent",
142-
]
143-
144-
145-
def _versions_dependencies(dependencies):
146-
# this is not the same as the requirements!
147-
for mod in dependencies:
148-
mod_name, dist_name = mod if isinstance(mod, tuple) else (mod, mod)
149-
try:
150-
imp = __import__(mod_name)
151-
yield dist_name, imp.__version__
152-
except (ImportError, AttributeError):
153-
pass
154-
155-
156-
def print_header(*, file=None):
133+
@overload
134+
def print_header(*, file: None = None) -> SessionInfo: ...
135+
@overload
136+
def print_header(*, file: IO[str]) -> None: ...
137+
def print_header(*, file: IO[str] | None = None):
157138
"""\
158139
Versions that might influence the numerical results.
159140
Matplotlib and Seaborn are excluded from this.
@@ -163,50 +144,27 @@ def print_header(*, file=None):
163144
file
164145
Optional path for dependency output.
165146
"""
147+
from session_info2 import session_info
166148

167-
modules = ["scanpy"] + _DEPENDENCIES_NUMERICS
168-
print(
169-
" ".join(f"{mod}=={ver}" for mod, ver in _versions_dependencies(modules)),
170-
file=file or sys.stdout,
171-
)
149+
sinfo = session_info(os=True, cpu=True, gpu=True, dependencies=True)
150+
151+
if file is not None:
152+
print(sinfo, file=file)
153+
return
154+
155+
return sinfo
172156

173157

174-
def print_versions(*, file: IO[str] | None = None):
158+
@deprecated("Use `print_header` instead")
159+
def print_versions() -> SessionInfo:
175160
"""\
176-
Print versions of imported packages, OS, and jupyter environment.
161+
Alias for `print_header`.
177162
178-
For more options (including rich output) use `session_info.show` directly.
163+
.. deprecated:: 1.11.0
179164
180-
Parameters
181-
----------
182-
file
183-
Optional path for output.
165+
Use :func:`print_header` instead.
184166
"""
185-
import session_info
186-
187-
if file is not None:
188-
from contextlib import redirect_stdout
189-
190-
warnings.warn(
191-
"Passing argument 'file' to print_versions is deprecated, and will be "
192-
"removed in a future version.",
193-
FutureWarning,
194-
)
195-
with redirect_stdout(file):
196-
print_versions()
197-
else:
198-
session_info.show(
199-
dependencies=True,
200-
html=False,
201-
excludes=[
202-
"builtins",
203-
"stdlib_list",
204-
"importlib_metadata",
205-
# Special module present if test coverage being calculated
206-
# https://gitlab.com/joelostblom/session_info/-/issues/10
207-
"$coverage",
208-
],
209-
)
167+
return print_header()
210168

211169

212170
def print_version_and_date(*, file=None):
@@ -235,7 +193,7 @@ def _copy_docs_and_signature(fn):
235193
def error(
236194
msg: str,
237195
*,
238-
time: datetime = None,
196+
time: datetime | None = None,
239197
deep: str | None = None,
240198
extra: dict | None = None,
241199
) -> datetime:

0 commit comments

Comments
 (0)