Skip to content

Commit

Permalink
Switch from sinfo to session_info (scverse#2089)
Browse files Browse the repository at this point in the history
* Switch from sinfo to session_info

* Utilize rich display

* Fix use

* oops

* Import conditionally

* Grammar

* Remove update from old news file

* Simplify, deprecate file argument

* Added release note

* Clean up unused imports

Co-authored-by: Isaac Virshup <[email protected]>
  • Loading branch information
flying-sheep and ivirshup authored Mar 15, 2022
1 parent fdd602e commit 495c905
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/1.9.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

- :func:`~scanpy.tl.filter_rank_genes_groups` now allows to filter with absolute values of log fold change :pr:`1649` :smaller:`S Rybakov`
- :func:`~scanpy.pl.embedding_density` now allows more than 10 groups :pr:`1936` :smaller:`A Wolf`
- :func:`~scanpy.logging.print_versions` now uses `session_info` :pr:`2089` :smaller:`P Angerer` :smaller:`I Virshup`
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dependencies = [
"numba>=0.41.0",
"umap-learn>=0.3.10",
"packaging",
"sinfo",
"session-info",
# for getting the stable version
"importlib_metadata>=0.7; python_version < '3.8'",
]
Expand Down
42 changes: 25 additions & 17 deletions scanpy/logging.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"""Logging and Profiling
"""
import io
import logging
import sys
from functools import update_wrapper, partial
from logging import CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET
from logging import CRITICAL, ERROR, WARNING, INFO, DEBUG
from datetime import datetime, timedelta, timezone
from typing import Optional
from typing import Optional, IO
import warnings

import anndata.logging
from sinfo import sinfo


HINT = (INFO + DEBUG) // 2
Expand Down Expand Up @@ -159,28 +158,37 @@ def print_header(*, file=None):
)


def print_versions(*, file=None):
"""Print print versions of imported packages"""
if file is None: # Inform people about the behavior change
warning('If you miss a compact list, please try `print_header`!')
stdout = sys.stdout
try:
buf = sys.stdout = io.StringIO()
sinfo(
def print_versions(*, file: Optional[IO[str]] = None):
"""\
Print versions of imported packages, OS, and jupyter environment.
For more options (including rich output) use `session_info.show` directly.
"""
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/sinfo/-/issues/10
# https://gitlab.com/joelostblom/session_info/-/issues/10
"$coverage",
],
)
finally:
sys.stdout = stdout
output = buf.getvalue()
print(output, file=file)


def print_version_and_date(*, file=None):
Expand Down

0 comments on commit 495c905

Please sign in to comment.