Skip to content

Commit b379404

Browse files
authored
style: unify import messages (#3979)
1 parent 4a90f6f commit b379404

20 files changed

Lines changed: 52 additions & 55 deletions

src/scanpy/external/exporting.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,8 @@ def cellbrowser( # noqa: PLR0913
577577
"""
578578
try:
579579
import cellbrowser.cellbrowser as cb
580-
except ImportError:
581-
logg.error(
582-
"The package cellbrowser is not installed. "
583-
"Install with 'pip install cellbrowser' and retry."
584-
)
580+
except ImportError as e:
581+
e.add_note("Please install `cellbrowser` and try again.")
585582
raise
586583

587584
data_dir = str(data_dir)

src/scanpy/external/pp/_bbknn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def bbknn( # noqa: PLR0913
133133
try:
134134
from bbknn import bbknn
135135
except ImportError as e:
136-
msg = "Please install bbknn: `pip install bbknn`."
137-
raise ImportError(msg) from e
136+
e.add_note("Please install `bbknn` and try again.")
137+
raise
138138
return bbknn(
139139
adata=adata,
140140
batch_key=batch_key,

src/scanpy/external/pp/_dca.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ def dca( # noqa: PLR0913
180180
try:
181181
from dca.api import dca
182182
except ImportError as e:
183-
msg = "Please install dca package (>= 0.2.1) via `pip install dca`"
184-
raise ImportError(msg) from e
183+
e.add_note("Please install `dca` (≥ 0.2.1) and try again.")
184+
raise e
185185

186186
return dca(
187187
adata,

src/scanpy/external/pp/_harmony_integrate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def harmony_integrate(
9090
try:
9191
import harmonypy
9292
except ImportError as e:
93-
msg = "\nplease install harmonypy:\n\n\tpip install harmonypy"
94-
raise ImportError(msg) from e
93+
e.add_note("Please install `harmonypy` and try again.")
94+
raise
9595

9696
x = adata.obsm[basis].astype(np.float64)
9797

src/scanpy/external/pp/_magic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def magic( # noqa: PLR0913
140140
try:
141141
from magic import MAGIC
142142
except ImportError as e:
143-
msg = "Please install magic package via `pip install magic-impute`"
144-
raise ImportError(msg) from e
143+
e.add_note("Please install `magic-impute` and try again.")
144+
raise
145145
else:
146146
if pkg_version("magic-impute") < Version(MIN_VERSION):
147147
msg = (

src/scanpy/external/pp/_mnn_correct.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def mnn_correct( # noqa: PLR0913
133133
import mnnpy
134134
from mnnpy import mnn_correct
135135
except ImportError as e:
136-
msg = "Please install the package mnnpy (https://github.com/chriscainx/mnnpy). "
137-
raise ImportError(msg) from e
136+
e.add_note("Please install `mnnpy` and try again.")
137+
raise
138138

139139
n_jobs = settings.n_jobs if n_jobs is None else n_jobs
140140

src/scanpy/external/pp/_scanorama_integrate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def scanorama_integrate(
109109
try:
110110
import scanorama
111111
except ImportError as e:
112-
msg = "\nplease install Scanorama:\n\n\tpip install scanorama"
113-
raise ImportError(msg) from e
112+
e.add_note("Please install `scanorama` and try again.")
113+
raise
114114

115115
# Get batch indices in linear time.
116116
curr_batch = None

src/scanpy/external/tl/_harmony_timeseries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def harmony_timeseries(
135135
try:
136136
import harmony
137137
except ImportError as e:
138-
msg = "\nplease install harmony:\n\n\tpip install harmonyTS"
139-
raise ImportError(msg) from e
138+
e.add_note("Please install `harmonyTS` and try again.")
139+
raise
140140

141141
adata = adata.copy() if copy else adata
142142
logg.info("Harmony augmented affinity matrix")

src/scanpy/external/tl/_palantir.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ def palantir_results(
333333
return pr_res
334334

335335

336-
def _check_import():
336+
def _check_import() -> None:
337337
try:
338338
import palantir # noqa: F401
339339
except ImportError as e:
340-
msg = "\nplease install palantir:\n\tpip install palantir"
341-
raise ImportError(msg) from e
340+
e.add_note("Please install `palantir` and try again.")
341+
raise

src/scanpy/external/tl/_phate.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,8 @@ def phate( # noqa: PLR0913
152152
try:
153153
import phate
154154
except ImportError as e:
155-
msg = (
156-
"You need to install the package `phate`: please run `pip install "
157-
"--user phate` in a terminal."
158-
)
159-
raise ImportError(msg) from e
155+
e.add_note("Please install `phate` and try again.")
156+
raise
160157
x_phate = phate.PHATE(
161158
n_components=n_components,
162159
k=k,

0 commit comments

Comments
 (0)