Skip to content

Commit

Permalink
Replace imports of distutils.
Browse files Browse the repository at this point in the history
As reported in [Debian bug #1083070], the Python module distutils is
going to be removed entirely from the upcoming Debian release,
following the deprecation on Python side of the distutils module.
Removal of distutils is causing test failures in bmtk though:

	Traceback:
	/usr/lib/python3.12/importlib/__init__.py:90: in import_module
	    return _bootstrap._gcd_import(name[level:], package, level)
	tests/simulator/filternet/test_filternet_movies.py:5: in <module>
	    from bmtk.utils.sim_setup import build_env_filternet
	/usr/lib/python3/dist-packages/bmtk/utils/sim_setup.py:32: in <module>
	    from distutils.dir_util import copy_tree
	E   ModuleNotFoundError: No module named 'distutils'

These changes replace copy_tree invocations by shutil.copytree, with
the option to clobber existing directories by default, as otherwise
the refusal of erasing the target directory will cause other test
regressions.  The version sort invocation perusing LooseVersion is
replaced by invocations of the bare packaging.version.Version.

[Debian bug #1083070]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1083070

Signed-off-by: Étienne Mollier <emollier@debian.org>
  • Loading branch information
emollier committed Oct 16, 2024
1 parent b1ebdf1 commit 91617e0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bmtk/analyzer/spikes_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import numpy as np

try:
from distutils.version import LooseVersion
use_sort_values = LooseVersion(pd.__version__) >= LooseVersion('0.19.0')
from packaging.version import Version
use_sort_values = Version(pd.__version__) >= Version('0.19.0')

except:
use_sort_values = False
Expand Down
4 changes: 2 additions & 2 deletions bmtk/utils/compile_mechanisms/compile_mechanisms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import logging
from subprocess import call
from distutils.dir_util import copy_tree
from shutil import copytree


logger = logging.getLogger(__name__)
Expand All @@ -28,4 +28,4 @@ def copy_modfiles(mechanisms_dir, cached_dir=None):
cached_dir = os.path.join(local_path, '..', 'scripts/bionet/mechanisms')

logger.info('Copying mod files from {} to {}'.format(cached_dir, mechanisms_dir))
copy_tree(cached_dir, mechanisms_dir)
copytree(cached_dir, mechanisms_dir, dirs_exist_ok=True)
4 changes: 2 additions & 2 deletions bmtk/utils/create_environment/env_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from subprocess import call
from collections import OrderedDict
import logging
from distutils.dir_util import copy_tree
from shutil import copytree

from bmtk.utils.compile_mechanisms import copy_modfiles, compile_mechanisms

Expand Down Expand Up @@ -270,7 +270,7 @@ def _create_components_dir(self, components_dir, with_examples=True):

if with_examples:
logger.info(' Copying files from {}.'.format(src_dir))
copy_tree(src_dir, trg_dir)
copytree(src_dir, trg_dir, dirs_exist_ok=True)

# return components_config
self._circuit_config['components'] = components_config
Expand Down
6 changes: 3 additions & 3 deletions bmtk/utils/sim_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from optparse import OptionParser
from collections import OrderedDict
import logging
from distutils.dir_util import copy_tree
from shutil import copytree


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -248,7 +248,7 @@ def _create_components_dir(self, components_dir, with_examples=True):

if with_examples:
logger.info(' Copying files from {}.'.format(src_dir))
copy_tree(src_dir, trg_dir)
copytree(src_dir, trg_dir, dirs_exist_ok=True)

# return components_config
self._circuit_config['components'] = components_config
Expand Down Expand Up @@ -852,4 +852,4 @@ def membrane_report_parser(option, opt, value, parser):
elif target_sim == 'filternet':
build_env_filternet(base_dir=base_dir, network_dir=options.network_dir, tstop=options.tstop,
include_examples=options.include_examples,
config_file=options.config_file)
config_file=options.config_file)

0 comments on commit 91617e0

Please sign in to comment.