Skip to content

Commit

Permalink
ENH: Auto warning stacklevel (#1099)
Browse files Browse the repository at this point in the history
* ENH: Auto warning stacklevel

* FIX: Sty

* FIX: Protect
  • Loading branch information
larsoner committed Nov 15, 2022
1 parent f34fa2a commit 1b04da8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
4 changes: 2 additions & 2 deletions mne_bids/copyfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import mne
from mne.io import (read_raw_brainvision, read_raw_edf, read_raw_bdf,
anonymize_info)
from mne.utils import logger, verbose, warn
from mne.utils import logger, verbose

from mne_bids.path import BIDSPath, _parse_ext, _mkdir_p
from mne_bids.utils import _get_mrk_meas_date, _check_anonymize
from mne_bids.utils import _get_mrk_meas_date, _check_anonymize, warn
import numpy as np


Expand Down
4 changes: 2 additions & 2 deletions mne_bids/dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import mne
import numpy as np
from mne.io.constants import FIFF
from mne.utils import (logger, warn, _validate_type, _check_option,
from mne.utils import (logger, _validate_type, _check_option,
has_nibabel, get_subjects_dir)
from mne.io.pick import _picks_to_idx

Expand All @@ -25,7 +25,7 @@
BIDS_STANDARD_TEMPLATE_COORDINATE_SYSTEMS)
from mne_bids.tsv_handler import _from_tsv
from mne_bids.utils import (_scale_coord_to_meters, _write_json, _write_tsv,
verbose)
verbose, warn)
from mne_bids.path import BIDSPath

data_dir = Path(__file__).parent / 'data'
Expand Down
4 changes: 2 additions & 2 deletions mne_bids/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import Optional

import numpy as np
from mne.utils import warn, logger, _validate_type, verbose, _check_fname
from mne.utils import logger, _validate_type, verbose, _check_fname

from mne_bids.config import (
ALLOWED_PATH_ENTITIES, ALLOWED_FILENAME_EXTENSIONS,
Expand All @@ -26,7 +26,7 @@
ALLOWED_SPACES,
reader, ENTITY_VALUE_TYPE)
from mne_bids.utils import (_check_key_val, _check_empty_room_basename,
param_regex, _ensure_tuple)
param_regex, _ensure_tuple, warn)


def _find_empty_room_candidates(bids_path):
Expand Down
6 changes: 2 additions & 4 deletions mne_bids/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import mne
from mne import io, read_events, events_from_annotations
from mne.io.pick import pick_channels_regexp
from mne.utils import (
has_nibabel, logger, warn, get_subjects_dir
)
from mne.utils import has_nibabel, logger, get_subjects_dir
from mne.coreg import fit_matched_points
from mne.transforms import apply_trans

Expand All @@ -29,7 +27,7 @@
from mne_bids.config import (ALLOWED_DATATYPE_EXTENSIONS,
ANNOTATIONS_TO_KEEP,
reader, _map_options)
from mne_bids.utils import _get_ch_type_mapping, verbose
from mne_bids.utils import _get_ch_type_mapping, verbose, warn
from mne_bids.path import (BIDSPath, _parse_ext, _find_matching_sidecar,
_infer_datatype, get_bids_path_from_fname)

Expand Down
3 changes: 2 additions & 1 deletion mne_bids/report/_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

import numpy as np
import jinja2
from mne.utils import warn, logger, verbose
from mne.utils import logger, verbose

from mne_bids.config import DOI, ALLOWED_DATATYPES
from mne_bids.tsv_handler import _from_tsv
from mne_bids.path import (get_bids_path_from_fname, get_datatypes,
get_entity_vals, BIDSPath,
_parse_ext, _find_matching_sidecar)
from mne_bids.utils import warn


jinja_env = jinja2.Environment(
Expand Down
2 changes: 1 addition & 1 deletion mne_bids/tsv_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from collections import OrderedDict
from copy import deepcopy

from mne.utils import warn
import numpy as np


Expand Down Expand Up @@ -140,6 +139,7 @@ def _from_tsv(fname, dtypes=None):
Keys are the column names, and values are the column data.
"""
from .utils import warn # avoid circular import
data = np.loadtxt(fname, dtype=str, delimiter='\t', ndmin=2,
comments=None, encoding='utf-8-sig')
column_names = data[0, :]
Expand Down
16 changes: 15 additions & 1 deletion mne_bids/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from mne.channels import make_standard_montage
from mne.io.kit.kit import get_kit_info
from mne.io.pick import pick_types
from mne.utils import warn, logger, verbose
from mne.utils import warn as _warn, logger, verbose

from mne_bids.tsv_handler import _to_tsv

Expand Down Expand Up @@ -456,3 +456,17 @@ def _check_datatype(raw, datatype):
'`bids_path.update(datatype="<datatype>")` or use '
'raw.set_channel_types to set the correct channel types in '
'the raw object.')


def warn(message, category=RuntimeWarning, module='mne_bids',
ignore_namespaces=('mne', 'mne_bids')): # noqa: D103
_warn(
message,
category=category,
module=module,
ignore_namespaces=ignore_namespaces,
)


# Some of the defaults here will be wrong but it should be close enough
warn.__doc__ = getattr(_warn, '__doc__', None)
4 changes: 2 additions & 2 deletions mne_bids/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from mne.io import BaseRaw, read_fiducials
from mne.channels.channels import (_unit2human, _get_meg_system)
from mne.chpi import get_chpi_info
from mne.utils import (check_version, has_nibabel, logger, warn, Bunch,
from mne.utils import (check_version, has_nibabel, logger, Bunch,
_validate_type, get_subjects_dir, verbose,
ProgressBar)
import mne.preprocessing
Expand All @@ -40,7 +40,7 @@
from mne_bids.utils import (_write_json, _write_tsv, _write_text,
_age_on_date, _infer_eeg_placement_scheme,
_get_ch_type_mapping, _check_anonymize,
_stamp_to_dt, _handle_datatype)
_stamp_to_dt, _handle_datatype, warn)
from mne_bids import (BIDSPath, read_raw_bids, get_anonymization_daysback,
get_bids_path_from_fname)
from mne_bids.path import _parse_ext, _mkdir_p, _path_to_str
Expand Down

0 comments on commit 1b04da8

Please sign in to comment.