Repository: skorch-dev/skorch (language: python)

Issue:
Remove deprecated pkg_resources import
`pkg_resources` is deprecated as an API. I think the alternative is to use `packaging.version`.

The import occurs here: 

https://github.com/skorch-dev/skorch/blob/5b222a5897071c35a3ab0e0663796be366fdc954/skorch/__init__.py#L6-L7

And it makes CIs fail if they raise on deprecation warnings. Eg: https://github.com/fairlearn/fairlearn/actions/runs/5242050040/jobs/9464954323?pr=1241

In `scikit-learn` we vendor `packaging` instead of having it as a dependency, but it's a very lightweight dependency.


Discussion / hints:

Fix patch:
diff --git a/skorch/__init__.py b/skorch/__init__.py
index 64f0f64c5..18708e383 100644
--- a/skorch/__init__.py
+++ b/skorch/__init__.py
@@ -3,8 +3,7 @@
 import sys
 import warnings
 
-import pkg_resources
-from pkg_resources import parse_version
+import importlib.metadata
 
 from .history import History
 from .net import NeuralNet
@@ -12,6 +11,7 @@
 from .classifier import NeuralNetBinaryClassifier
 from .regressor import NeuralNetRegressor
 from . import callbacks
+from ._version import Version
 
 
 MIN_TORCH_VERSION = '1.1.0'
@@ -26,8 +26,8 @@
         "(aka 'torch'). "
         "Visit https://pytorch.org/ for installation instructions.")
 
-torch_version = pkg_resources.get_distribution('torch').version
-if parse_version(torch_version) < parse_version(MIN_TORCH_VERSION):
+torch_version = torch.__version__
+if Version(torch_version) < Version(MIN_TORCH_VERSION):
     msg = ('skorch depends on a newer version of PyTorch (at least {req}, not '
            '{installed}). Visit https://pytorch.org for installation details')
     raise ImportWarning(msg.format(req=MIN_TORCH_VERSION, installed=torch_version))
@@ -42,8 +42,7 @@
     'callbacks',
 ]
 
-
 try:
-    __version__ = pkg_resources.get_distribution('skorch').version
+    __version__ = importlib.metadata.version("skorch")
 except:  # pylint: disable=bare-except
     __version__ = 'n/a'


Test patch:
diff --git a/skorch/tests/net_cuda.pkl b/skorch/tests/net_cuda.pkl
index 33af7483f..cf13d08de 100644
Binary files a/skorch/tests/net_cuda.pkl and b/skorch/tests/net_cuda.pkl differ