Skip to content

Commit

Permalink
[cocopp] Remove pkg_resouces dependency
Browse files Browse the repository at this point in the history
Instead of using pkg_resources to get the version number and package
path, import cocopp._version for the version and use importlib.resources
for the package path.
  • Loading branch information
olafmersmann committed Nov 29, 2023
1 parent f12c8a8 commit 32a64e6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions code-postprocessing/cocopp/bestalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import warnings
import numpy as np
import tarfile
import pkg_resources
from six import advance_iterator

from . import readalign, pproc
Expand Down Expand Up @@ -548,6 +547,7 @@ def custom_generate(args=algs2009, algId='bestCustomAlg', suite=None):


def create_data_files(output_dir, result, suite):
from ._version import __version__ as coco_version

if not suite:
suite = result[list(result.keys())[0]].suite_name
Expand Down Expand Up @@ -626,7 +626,7 @@ def create_data_files(output_dir, result, suite):
comment = 'Combination of ' + ', '.join(algorithms_used)
else:
comment = value.comment
comment += '; coco_version: ' + pkg_resources.require('cocopp')[0].version
comment += '; coco_version: ' + coco_version

info_lines.insert(1, "%% %s; instance_numbers: %s" % (comment, instances_list))

Expand Down
12 changes: 6 additions & 6 deletions code-postprocessing/cocopp/toolsdivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
"""Various tools.
"""
from __future__ import absolute_import, print_function

import os, time, warnings
import tempfile, shutil
from collections import OrderedDict as _OrderedDict
import re as _re
import numpy as np
from matplotlib import pyplot as plt
from subprocess import CalledProcessError, STDOUT
import pkg_resources

from . import genericsettings, testbedsettings

Expand Down Expand Up @@ -586,7 +583,7 @@ def get_version_label(algorithmID=None):
the string. If more than one reference value is present in the data,
the string displays also a warning.
"""
coco_version = pkg_resources.require('cocopp')[0].version
from ._version import __version__ as coco_version
reference_values = testbedsettings.get_reference_values(algorithmID)

if reference_values and type(reference_values) is set:
Expand All @@ -600,7 +597,10 @@ def get_version_label(algorithmID=None):


def path_in_package(sub_path=""):
from importlib import resources as res
"""return the absolute path prepended to `subpath` in this module.
"""
egg_info = pkg_resources.require('cocopp')[0]
return os.path.join(egg_info.location, egg_info.project_name, sub_path)

package_root_directory = res.files("cocopp")
path = package_root_directory / sub_path
return str(path)
1 change: 0 additions & 1 deletion code-postprocessing/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ classifiers = [
dependencies = [
"matplotlib >=3.5.0",
"numpy >=1.21.0",
"setuptools >=61.0", # For pkg_resources
"platformdirs >=3.8.1",
]
dynamic = ["version"]
Expand Down

0 comments on commit 32a64e6

Please sign in to comment.