Skip to content

Commit

Permalink
replace deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMohrmann committed Jul 17, 2023
1 parent 46d1b49 commit 58dee78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
12 changes: 5 additions & 7 deletions glidertools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import warnings as _warnings

from pkg_resources import DistributionNotFound, get_distribution

from . import ( # NOQA
calibration,
cleaning,
Expand All @@ -14,16 +12,16 @@
physics,
utils,
)
from .helpers import package_version
from .mapping import grid_data, interp_obj
from .plot import logo as make_logo
from .plot import plot_functions as plot
from .processing import *


try:
__version__ = get_distribution("glidertools").version
except DistributionNotFound:
__version__ = "version_undefined"
del get_distribution, DistributionNotFound
# from importlib.metadata import version, PackageNotFoundError
# from pkg_resources import DistributionNotFound, get_distribution


__version__ = package_version()
_warnings.filterwarnings("ignore", category=RuntimeWarning)
17 changes: 11 additions & 6 deletions glidertools/helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import inspect

from pkg_resources import DistributionNotFound, get_distribution

def package_version():
# package version will only be returned if package is installed through e.g. pip or conda,
# development code is unaware of its own version (and there is not such a thing in dev anyway).
# Advantage: We don't have to keep track of versioning manually
from importlib.metadata import PackageNotFoundError, version

try:
version = get_distribution("glidertools").version
except DistributionNotFound:
version = "version_undefined"
try:
version = version("glidertools")
except PackageNotFoundError:
version = "version_undefined"
return version


class GliderToolsWarning(UserWarning):
Expand Down Expand Up @@ -79,7 +84,7 @@ def transfer_nc_attrs(frame, input_xds, output_arr, output_name, **attrs):
attributes = input_xds.attrs.copy()
history = "" if "history" not in attributes else attributes["history"]
history += "[{}] (v{}) {};\n".format(
time_now(), version, rebuild_func_call(frame)
time_now(), package_version(), rebuild_func_call(frame)
)
attributes.update({"history": history})
attributes.update(attrs)
Expand Down

0 comments on commit 58dee78

Please sign in to comment.