LiberTEM/LiberTEM

View on GitHub
src/libertem/udf/base.py

Summary

Maintainability
F
6 days
Test Coverage

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert self._tiling_scheme is not None
Severity: Info
Found in src/libertem/udf/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert self._slice is not None
Severity: Info
Found in src/libertem/udf/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert not cupy_udfs
Severity: Info
Found in src/libertem/udf/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

                    assert frame.shape == tuple(partition.shape.sig)
Severity: Info
Found in src/libertem/udf/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert self._partition_slice is not None
Severity: Info
Found in src/libertem/udf/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert backend in self.get_backends()
Severity: Info
Found in src/libertem/udf/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

                assert partition.slice.adjust_for_roi(roi) == tile.tile_slice
Severity: Info
Found in src/libertem/udf/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert isinstance(buffer, BufferWrapper)
Severity: Info
Found in src/libertem/udf/base.py by bandit

File base.py has 1793 lines of code (exceeds 400 allowed). Consider refactoring.
Open

from collections import defaultdict
from contextlib import contextmanager
from typing import (
    Any, AsyncGenerator, Dict, Generator, Iterator, Mapping, Optional, List,
    Tuple, Type, Iterable, TypeVar, Union, Set, TYPE_CHECKING
Severity: Major
Found in src/libertem/udf/base.py - About 4 days to fix

    UDFData has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class UDFData:
        '''
        Container for result buffers, return value from running UDFs
        '''
    
    
    Severity: Minor
    Found in src/libertem/udf/base.py - About 3 hrs to fix

      UDFBase has 25 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class UDFBase(UDFProtocol):
          '''
          Base class for UDFs with helper functions.
          '''
          def __init__(self, *args, **kwargs) -> None:
      Severity: Minor
      Found in src/libertem/udf/base.py - About 2 hrs to fix

        Cyclomatic complexity is too high in method results_for_dataset_sync. (12)
        Open

            def results_for_dataset_sync(
                self,
                dataset: DataSet,
                executor: JobExecutor,
                roi: Optional[np.ndarray] = None,
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Cyclomatic complexity is too high in method _init_udfs. (11)
        Open

            def _init_udfs(
                self,
                numpy_udfs: List[UDF],
                cupy_udfs: List[UDF],
                partition: Partition,
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Cyclomatic complexity is too high in function get_resources_for_backends. (10)
        Open

        def get_resources_for_backends(
            udf_backends: List[BackendSpec],
            user_backends: Optional[BackendSpec]
        ) -> ResourceDef:
            """
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Cyclomatic complexity is too high in method _udf_lists. (9)
        Open

            def _udf_lists(self, device_class: DeviceClass) -> Tuple[List[UDF], List[UDF]]:
                numpy_udfs = []
                cupy_udfs = []
                if device_class == 'cuda':
                    for udf in self._udfs:
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Cyclomatic complexity is too high in method _run_tile. (8)
        Open

            def _run_tile(
                self,
                udfs: List[UDF],
                partition: Partition,
                tile: DataTile,
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Function _udf_lists has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def _udf_lists(self, device_class: DeviceClass) -> Tuple[List[UDF], List[UDF]]:
                numpy_udfs = []
                cupy_udfs = []
                if device_class == 'cuda':
                    for udf in self._udfs:
        Severity: Minor
        Found in src/libertem/udf/base.py - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Cyclomatic complexity is too high in method _wrapup_udfs. (7)
        Open

            def _wrapup_udfs(
                self,
                numpy_udfs: List[UDF],
                cupy_udfs: List[UDF],
                partition: Partition
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Function _init_udfs has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def _init_udfs(
                self,
                numpy_udfs: List[UDF],
                cupy_udfs: List[UDF],
                partition: Partition,
        Severity: Minor
        Found in src/libertem/udf/base.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Cyclomatic complexity is too high in method run_for_partition. (6)
        Open

            def run_for_partition(
                self,
                partition: Partition,
                params: UDFParams,
                env: Environment,
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Cyclomatic complexity is too high in method run_for_dataset_sync. (6)
        Open

            def run_for_dataset_sync(
                self,
                dataset: DataSet,
                executor: JobExecutor,
                roi: Optional[np.ndarray] = None,
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Cyclomatic complexity is too high in class UDFPartRunner. (6)
        Open

        class UDFPartRunner:
            def __init__(self, udfs: List[UDF], debug: bool = False, progress: bool = False):
                self._udfs = udfs
                self._debug = debug
                self._progress = progress
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Cyclomatic complexity is too high in method _do_get_results. (6)
        Open

            def _do_get_results(self) -> Mapping[str, BufferWrapper]:
                results_tmp = self.get_results()
                decl = self.get_result_buffers()
        
                # include any results that were not explicitly included, but have non-private `use`:
        Severity: Minor
        Found in src/libertem/udf/base.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Function results_for_dataset_sync has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def results_for_dataset_sync(
                self,
                dataset: DataSet,
                executor: JobExecutor,
                roi: Optional[np.ndarray] = None,
        Severity: Minor
        Found in src/libertem/udf/base.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function __init__ has 10 arguments (exceeds 8 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Major
        Found in src/libertem/udf/base.py - About 45 mins to fix

          Function _wrapup_udfs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def _wrapup_udfs(
                  self,
                  numpy_udfs: List[UDF],
                  cupy_udfs: List[UDF],
                  partition: Partition
          Severity: Minor
          Found in src/libertem/udf/base.py - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function _run_tile has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def _run_tile(
                  self,
                  udfs: List[UDF],
                  partition: Partition,
                  tile: DataTile,
          Severity: Minor
          Found in src/libertem/udf/base.py - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function _init_udfs has 9 arguments (exceeds 8 allowed). Consider refactoring.
          Open

              def _init_udfs(
          Severity: Major
          Found in src/libertem/udf/base.py - About 35 mins to fix

            Function __init__ has 9 arguments (exceeds 8 allowed). Consider refactoring.
            Open

                def __init__(
            Severity: Major
            Found in src/libertem/udf/base.py - About 35 mins to fix

              Function run_for_dataset_sync has 9 arguments (exceeds 8 allowed). Consider refactoring.
              Open

                  def run_for_dataset_sync(
              Severity: Major
              Found in src/libertem/udf/base.py - About 35 mins to fix

                Function _get_buffers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _get_buffers(
                        self, filter_allocated: bool = False
                    ) -> Generator[Tuple[str, AuxBufferWrapper], None, None]:
                        for k, buf in self._data.items():
                            if isinstance(buf, AuxBufferWrapper):
                Severity: Minor
                Found in src/libertem/udf/base.py - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function _run_udfs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _run_udfs(
                        self,
                        numpy_udfs: List[UDF],
                        cupy_udfs: List[UDF],
                        partition: Partition,
                Severity: Minor
                Found in src/libertem/udf/base.py - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                There are no issues that match your filters.

                Category
                Status