Skip to content

Commit

Permalink
Add shim for deprecated API with warning. Old API will be removed in …
Browse files Browse the repository at this point in the history
…exspy 1.0
  • Loading branch information
ericpre committed Aug 16, 2024
1 parent 4093c98 commit b62f3b0
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 0 deletions.
1 change: 1 addition & 0 deletions exspy/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Deprecated and to be removed in exspy 1.0
1 change: 1 addition & 0 deletions exspy/misc/eds/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Deprecated and to be removed in exspy 1.0
32 changes: 32 additions & 0 deletions exspy/misc/eds/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import warnings

from hyperspy.exceptions import VisibleDeprecationWarning

from exspy._misc.eds.utils import (
cross_section_to_zeta,
electron_range,
get_xray_lines_near_energy,
take_off_angle,
xray_range,
zeta_to_cross_section,
)


warnings.warn(
"This module is deprecated, use `exspy.utils.eds` instead. "
"It will be removed in exspy 1.0.",
VisibleDeprecationWarning,
)

__all__ = [
"cross_section_to_zeta",
"electron_range",
"get_xray_lines_near_energy",
"take_off_angle",
"xray_range",
"zeta_to_cross_section",
]


def __dir__():
return sorted(__all__)

Check warning on line 32 in exspy/misc/eds/utils.py

View check run for this annotation

Codecov / codecov/patch

exspy/misc/eds/utils.py#L32

Added line #L32 was not covered by tests
Empty file added exspy/misc/eels/_init__.py
Empty file.
24 changes: 24 additions & 0 deletions exspy/misc/eels/electron_inelastic_mean_free_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Deprecated and to be removed in exspy 1.0

import warnings

from hyperspy.exceptions import VisibleDeprecationWarning

from exspy.utils.eels import (
iMFP_angular_correction,
iMFP_Iakoubovskii,
iMFP_TPP2M,
)

__all__ = [
"iMFP_angular_correction",
"iMFP_Iakoubovskii",
"iMFP_TPP2M",
]


warnings.warn(
"This module is deprecated, use `exspy.utils.eels` instead. "
"It will be removed in exspy 1.0.",
VisibleDeprecationWarning,
)
29 changes: 29 additions & 0 deletions exspy/misc/eels/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Deprecated and to be removed in exspy 1.0

import warnings

from hyperspy.exceptions import VisibleDeprecationWarning

from exspy.utils.eels import (
effective_angle,
get_edges_near_energy,
get_info_from_edges,
)


__all__ = [
"effective_angle",
"get_edges_near_energy",
"get_info_from_edges",
]


def __dir__():
return sorted(__all__)

Check warning on line 22 in exspy/misc/eels/tools.py

View check run for this annotation

Codecov / codecov/patch

exspy/misc/eels/tools.py#L22

Added line #L22 was not covered by tests


warnings.warn(
"This module is deprecated, use `exspy.utils.eels` instead. "
"It will be removed in exspy 1.0.",
VisibleDeprecationWarning,
)
23 changes: 23 additions & 0 deletions exspy/misc/elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Deprecated and to be removed in exspy 1.0

import warnings

from hyperspy.exceptions import VisibleDeprecationWarning

from exspy._misc.elements import elements_db


__all__ = [
"elements_db",
]


def __dir__():
return sorted(__all__)


warnings.warn(
"This module is deprecated, use `exspy.material` instead. "
"It will be removed in exspy 1.0.",
VisibleDeprecationWarning,
)
33 changes: 33 additions & 0 deletions exspy/misc/material.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Deprecated and to be removed in exspy 1.0

import warnings

from hyperspy.exceptions import VisibleDeprecationWarning

from exspy.material import (
atomic_to_weight,
density_of_mixture,
mass_absorption_coefficient,
mass_absorption_mixture,
weight_to_atomic,
)


__all__ = [
"atomic_to_weight",
"density_of_mixture",
"mass_absorption_coefficient",
"mass_absorption_mixture",
"weight_to_atomic",
]


def __dir__():
return sorted(__all__)


warnings.warn(
"This module is deprecated, use `exspy.material` instead. "
"It will be removed in exspy 1.0.",
VisibleDeprecationWarning,
)
62 changes: 62 additions & 0 deletions exspy/tests/test_deprecated_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ruff: noqa
# Remove in exspy 1.0

import pytest

from hyperspy.exceptions import VisibleDeprecationWarning


def test_import_element():
with pytest.warns(VisibleDeprecationWarning) as record:
from exspy.misc.elements import elements_db

assert "use `exspy.material` instead" in record[0].message.args[0]


def test_import_material():
with pytest.warns(VisibleDeprecationWarning) as record:
from exspy.misc.material import (
atomic_to_weight,
density_of_mixture,
mass_absorption_coefficient,
mass_absorption_mixture,
weight_to_atomic,
)

assert "use `exspy.material` instead" in record[0].message.args[0]


def test_import_eds_utils():
with pytest.warns(VisibleDeprecationWarning) as record:
from exspy.misc.eds.utils import (
cross_section_to_zeta,
electron_range,
get_xray_lines_near_energy,
take_off_angle,
xray_range,
zeta_to_cross_section,
)

assert "use `exspy.utils.eds` instead" in record[0].message.args[0]


def test_import_eels_tools():
with pytest.warns(VisibleDeprecationWarning) as record:
from exspy.misc.eels.tools import (
effective_angle,
get_edges_near_energy,
get_info_from_edges,
)

assert "use `exspy.utils.eels` instead" in record[0].message.args[0]


def test_import_eels_electron_inelastic_mean_free_path():
with pytest.warns(VisibleDeprecationWarning) as record:
from exspy.misc.eels.electron_inelastic_mean_free_path import (
iMFP_angular_correction,
iMFP_Iakoubovskii,
iMFP_TPP2M,
)

assert "use `exspy.utils.eels` instead" in record[0].message.args[0]

0 comments on commit b62f3b0

Please sign in to comment.