Skip to content

Commit

Permalink
Merge pull request #187 from MartinMohrmann/update-init-file
Browse files Browse the repository at this point in the history
Replace deprecated pkg_resources functions
  • Loading branch information
MartinMohrmann authored Jul 17, 2023
2 parents 46d1b49 + 3edee63 commit fa38b77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
10 changes: 2 additions & 8 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,12 @@
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

__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 fa38b77

Please sign in to comment.