4
4
5
5
import logging
6
6
import sys
7
- import warnings
8
7
from datetime import datetime , timedelta , timezone
9
8
from functools import partial , update_wrapper
10
9
from logging import CRITICAL , DEBUG , ERROR , INFO , WARNING
11
- from typing import TYPE_CHECKING
10
+ from typing import TYPE_CHECKING , overload
12
11
13
12
import anndata .logging
14
13
14
+ from ._compat import deprecated
15
+
15
16
if TYPE_CHECKING :
16
17
from typing import IO
17
18
19
+ from session_info2 import SessionInfo
20
+
18
21
from ._settings import ScanpyConfig
19
22
20
23
@@ -127,33 +130,11 @@ def format(self, record: logging.LogRecord):
127
130
get_memory_usage = anndata .logging .get_memory_usage
128
131
129
132
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 ):
157
138
"""\
158
139
Versions that might influence the numerical results.
159
140
Matplotlib and Seaborn are excluded from this.
@@ -163,50 +144,27 @@ def print_header(*, file=None):
163
144
file
164
145
Optional path for dependency output.
165
146
"""
147
+ from session_info2 import session_info
166
148
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
172
156
173
157
174
- def print_versions (* , file : IO [str ] | None = None ):
158
+ @deprecated ("Use `print_header` instead" )
159
+ def print_versions () -> SessionInfo :
175
160
"""\
176
- Print versions of imported packages, OS, and jupyter environment .
161
+ Alias for `print_header` .
177
162
178
- For more options (including rich output) use `session_info.show` directly.
163
+ .. deprecated:: 1.11.0
179
164
180
- Parameters
181
- ----------
182
- file
183
- Optional path for output.
165
+ Use :func:`print_header` instead.
184
166
"""
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 ()
210
168
211
169
212
170
def print_version_and_date (* , file = None ):
@@ -235,7 +193,7 @@ def _copy_docs_and_signature(fn):
235
193
def error (
236
194
msg : str ,
237
195
* ,
238
- time : datetime = None ,
196
+ time : datetime | None = None ,
239
197
deep : str | None = None ,
240
198
extra : dict | None = None ,
241
199
) -> datetime :
0 commit comments