From 0c8a057053fc668161e843da0c1cda8b2ab7df3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20M=C3=ADchal?= Date: Sat, 7 Oct 2023 00:17:42 +0300 Subject: [PATCH 1/2] Remove demandimport module The demandimport module relies on the imp module which has been deprecated in Python 3.4[0] and then removed in Python 3.12[1]. Remove it as it is no longer maintained (last commit in 2019), the performance benefit is marginal and optional imports can be managed in alternative ways (such as using try/expect or by utilising a build system). [0] https://bugs.python.org/issue17177 [1] https://docs.python.org/dev/whatsnew/3.12.html#imp [2] https://github.com/bwesterb/py-demandimport/commit/ca9c11635407b4b012c4b70f6fe03729b924eacd --- perun/collect/trace/configuration.py | 4 +--- perun/fuzz/interpret.py | 4 +--- perun/logic/store.py | 4 +--- perun/profile/convert.py | 6 ++---- perun/utils/view_helpers.py | 10 ++++------ perun/view/bars/factory.py | 5 +---- perun/view/flow/factory.py | 5 +---- perun/view/scatter/factory.py | 11 ++++------- pyproject.toml | 6 +----- 9 files changed, 16 insertions(+), 39 deletions(-) diff --git a/perun/collect/trace/configuration.py b/perun/collect/trace/configuration.py index 28d39a1a7..b9f7912e7 100644 --- a/perun/collect/trace/configuration.py +++ b/perun/collect/trace/configuration.py @@ -3,7 +3,6 @@ import os import time -import demandimport from perun.collect.trace.collect_engine import CollectEngine from perun.collect.trace.systemtap.engine import SystemTapEngine @@ -15,8 +14,7 @@ import perun.logic.temp as temp # Import on demand since eBPF support is optional -with demandimport.enabled(): - import perun.collect.trace.ebpf.engine as bpf +import perun.collect.trace.ebpf.engine as bpf class Configuration: diff --git a/perun/fuzz/interpret.py b/perun/fuzz/interpret.py index c64f64e40..ec4f5fa9d 100644 --- a/perun/fuzz/interpret.py +++ b/perun/fuzz/interpret.py @@ -1,12 +1,10 @@ """ Module contains a set of functions for fuzzing results interpretation.""" from __future__ import annotations -import demandimport import os.path as path import difflib import scipy.stats.mstats as stats -with demandimport.enabled(): - import matplotlib.pyplot as plt +import matplotlib.pyplot as plt from typing import TextIO, Optional diff --git a/perun/logic/store.py b/perun/logic/store.py index c43ba1017..5fcc089d3 100644 --- a/perun/logic/store.py +++ b/perun/logic/store.py @@ -11,7 +11,6 @@ import string import struct import zlib -import demandimport from typing import BinaryIO, Optional @@ -22,8 +21,7 @@ from perun.utils.exceptions import IncorrectProfileFormatException from perun.profile.factory import Profile -with demandimport.enabled(): - import hashlib +import hashlib INDEX_TAG_REGEX = re.compile(r"^(\d+)@i$") diff --git a/perun/profile/convert.py b/perun/profile/convert.py index 1137490ae..8563a9ad4 100644 --- a/perun/profile/convert.py +++ b/perun/profile/convert.py @@ -25,10 +25,8 @@ import perun.profile.query as query import perun.postprocess.regression_analysis.transform as transform -import demandimport -with demandimport.enabled(): - import numpy - import pandas +import numpy +import pandas diff --git a/perun/utils/view_helpers.py b/perun/utils/view_helpers.py index 67c7de44c..619984629 100644 --- a/perun/utils/view_helpers.py +++ b/perun/utils/view_helpers.py @@ -6,13 +6,11 @@ from collections.abc import MutableMapping, Iterable from enum import Enum -import demandimport -with demandimport.enabled(): - from bokeh.plotting import show, output_file - import bokeh.palettes as bk_palettes - import bokeh.themes.theme as bk_theme - import holoviews as hv +from bokeh.plotting import show, output_file +import bokeh.palettes as bk_palettes +import bokeh.themes.theme as bk_theme +import holoviews as hv import perun.profile.helpers as profiles from perun.utils import log diff --git a/perun/view/bars/factory.py b/perun/view/bars/factory.py index 56a5664d5..265167ff9 100644 --- a/perun/view/bars/factory.py +++ b/perun/view/bars/factory.py @@ -3,10 +3,7 @@ from typing import TYPE_CHECKING -import demandimport - -with demandimport.enabled(): - import holoviews as hv +import holoviews as hv from perun.profile import convert from perun.utils import view_helpers diff --git a/perun/view/flow/factory.py b/perun/view/flow/factory.py index a82c99ac9..c0dfdee05 100644 --- a/perun/view/flow/factory.py +++ b/perun/view/flow/factory.py @@ -3,10 +3,7 @@ from typing import TYPE_CHECKING, Hashable, cast, Protocol -import demandimport - -with demandimport.enabled(): - import holoviews as hv +import holoviews as hv from perun.profile import convert from perun.utils import view_helpers diff --git a/perun/view/scatter/factory.py b/perun/view/scatter/factory.py index fa74579c2..de1836333 100644 --- a/perun/view/scatter/factory.py +++ b/perun/view/scatter/factory.py @@ -6,13 +6,10 @@ from operator import itemgetter -import demandimport - -with demandimport.enabled(): - import numpy as np - import numpy.typing as npt - import holoviews as hv - from bokeh import palettes +import numpy as np +import numpy.typing as npt +import holoviews as hv +from bokeh import palettes from perun.utils import view_helpers from perun.profile import query, convert diff --git a/pyproject.toml b/pyproject.toml index 4cfdf9cb0..8cbe30d7d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,9 +28,6 @@ dependencies = [ "GitPython>=3.1.30", "gitdb>=4.0.10", - # Lazy imports - "demandimport>=0.3.4", - # String / text utilities "Faker>=19.3", "ruamel.yaml>=0.17", @@ -140,7 +137,6 @@ module = [ "scipy.*", "sklearn.*", "statsmodels.*", - "demandimport.*", "holoviews.*", "bcc.*", "binaryornot.*", @@ -212,4 +208,4 @@ exclude_also = [ # Not implemented asserst are omitted "assert NotImplementedError(.*)", -] \ No newline at end of file +] From 6d5ec6b9c370da485e2aecd53395cf49a30d321f Mon Sep 17 00:00:00 2001 From: JiriPavela Date: Thu, 26 Oct 2023 11:50:21 +0200 Subject: [PATCH 2/2] Make bcc import optional After the removal of demandimport, the BPF engine of Tracer was being eagerly imported. However, the underlying bcc package is only an optional requirement and its absence should not crash Perun. --- perun/collect/trace/configuration.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/perun/collect/trace/configuration.py b/perun/collect/trace/configuration.py index b9f7912e7..9f00df6c6 100644 --- a/perun/collect/trace/configuration.py +++ b/perun/collect/trace/configuration.py @@ -11,10 +11,7 @@ from perun.utils.exceptions import InvalidBinaryException from perun.utils import find_executable -import perun.logic.temp as temp - -# Import on demand since eBPF support is optional -import perun.collect.trace.ebpf.engine as bpf +from perun.logic import temp class Configuration: @@ -113,6 +110,8 @@ def engine_factory(self): if self.engine == 'stap': self.engine = SystemTapEngine(self) else: + # Import on demand since eBPF support is optional + import perun.collect.trace.ebpf.engine as bpf self.engine = bpf.BpfEngine(self) def get_functions(self):