Skip to content

Commit

Permalink
Remove demandimport module (#121)
Browse files Browse the repository at this point in the history
* 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] bwesterb/py-demandimport@ca9c116

* 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.

---------

Co-authored-by: JiriPavela <xpavel32@stud.fit.vutbr.cz>
  • Loading branch information
HarryMichal and JiriPavela authored Oct 26, 2023
1 parent 7668ca9 commit 607666e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 42 deletions.
9 changes: 3 additions & 6 deletions perun/collect/trace/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,11 +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
with demandimport.enabled():
import perun.collect.trace.ebpf.engine as bpf
from perun.logic import temp


class Configuration:
Expand Down Expand Up @@ -115,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):
Expand Down
4 changes: 1 addition & 3 deletions perun/fuzz/interpret.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 1 addition & 3 deletions perun/logic/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import string
import struct
import zlib
import demandimport

from typing import BinaryIO, Optional

Expand All @@ -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$")
Expand Down
6 changes: 2 additions & 4 deletions perun/profile/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
10 changes: 4 additions & 6 deletions perun/utils/view_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions perun/view/bars/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions perun/view/flow/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions perun/view/scatter/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -140,7 +137,6 @@ module = [
"scipy.*",
"sklearn.*",
"statsmodels.*",
"demandimport.*",
"holoviews.*",
"bcc.*",
"binaryornot.*",
Expand Down Expand Up @@ -212,4 +208,4 @@ exclude_also = [

# Not implemented asserst are omitted
"assert NotImplementedError(.*)",
]
]

0 comments on commit 607666e

Please sign in to comment.