biosustain/optlang

View on GitHub

Showing 157 of 209 total issues

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

    def _remove_constraints(self, constraints):
        keys = [constraint.name for constraint in constraints]
        if len(constraints) > 350:  # Need to figure out a good threshold here
            self._constraints = self._constraints.fromkeys(set(self._constraints.keys()).difference(set(keys)))
        else:
Severity: Minor
Found in src/optlang/interface.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_command has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

def run_command(
Severity: Minor
Found in src/optlang/_version.py - About 45 mins to fix

    Function __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Minor
    Found in src/optlang/matrix_interface.py - About 45 mins to fix

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

          def _canonicalize(self, expression):
              expression = super(Constraint, self)._canonicalize(expression)
              if expression.is_Atom or expression.is_Mul:
                  return expression
              lonely_coeffs = [arg for arg in expression.args if arg.is_Number]
      Severity: Minor
      Found in src/optlang/interface.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 _glpk_set_col_bounds has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def _glpk_set_col_bounds(self, variable):
              if variable.lb is None and variable.ub is None:
                  # 0.'s are ignored
                  glp_set_col_bnds(self.problem, variable._index, GLP_FR, 0., 0.)
              elif variable.lb is None:
      Severity: Minor
      Found in src/optlang/glpk_interface.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 __test_valid_lower_bound has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def __test_valid_lower_bound(type, value, name):
              if not (value is None or is_numeric(value)):
                  raise TypeError("Variable bounds must be numeric or None.")
              if value is not None:
                  if type == 'integer' and value % 1 != 0.:
      Severity: Minor
      Found in src/optlang/interface.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__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, name, lb=None, ub=None, type="continuous", *args, **kwargs):
      Severity: Minor
      Found in src/optlang/scipy_interface.py - About 45 mins to fix

        Function __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, expression, name=None, problem=None, sloppy=False, *args, **kwargs):
        Severity: Minor
        Found in src/optlang/interface.py - About 45 mins to fix

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

              def __test_valid_upper_bound(type, value, name):
                  if not (value is None or is_numeric(value)):
                      raise TypeError("Variable bounds must be numeric or None.")
                  if value is not None:
                      if type == 'integer' and value % 1 != 0.:
          Severity: Minor
          Found in src/optlang/interface.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 type has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def type(self, value):
                  if not value in _VTYPE_TO_MIP_VTYPE:
                      raise ValueError(
                          'COIN-OR CBC cannot handle variables of type %s. ' % value +
                          'The following variable types are available:\n' +
          Severity: Minor
          Found in src/optlang/coinor_cbc_interface.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__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self, presolve="auto", verbosity=0, timeout=None, *args, **kwargs):
          Severity: Minor
          Found in src/optlang/glpk_interface.py - About 35 mins to fix

            Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def __init__(self, expression, value=None, direction='max', *args, **kwargs):
            Severity: Minor
            Found in src/optlang/interface.py - About 35 mins to fix

              Function parse_optimization_expression has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              def parse_optimization_expression(obj, linear=True, quadratic=False, expression=None, **kwargs):
              Severity: Minor
              Found in src/optlang/expression_parsing.py - About 35 mins to fix

                Function _get_expression has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _get_expression(self):
                        if self.problem is not None:
                            cplex_problem = self.problem.problem
                            try:
                                cplex_row = cplex_problem.linear_constraints.get_rows(self.name)
                Severity: Minor
                Found in src/optlang/cplex_interface.py - About 35 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 get_config_from_root has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                def get_config_from_root(root: str) -> VersioneerConfig:
                    """Read the project setup.cfg file to determine Versioneer config."""
                    # This might raise OSError (if setup.cfg is missing), or
                    # configparser.NoSectionError (if it lacks a [versioneer] section), or
                    # configparser.NoOptionError (if it lacks "VCS="). See the docstring at
                Severity: Minor
                Found in versioneer.py - About 35 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 verbosity has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def verbosity(self, value):
                
                        class StreamHandler(StringIO):
                
                            def __init__(self, logger, *args, **kwargs):
                Severity: Minor
                Found in src/optlang/cplex_interface.py - About 35 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 _glpk_set_row_bounds has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _glpk_set_row_bounds(self, constraint):
                        if constraint.lb is None and constraint.ub is None:
                            # 0.'s are ignored
                            glp_set_row_bnds(self.problem, constraint._index, GLP_FR, 0., 0.)
                        elif constraint.lb is None:
                Severity: Minor
                Found in src/optlang/glpk_interface.py - About 35 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 _add_variables has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _add_variables(self, variables):
                        super(Model, self)._add_variables(variables)
                        for variable in variables:
                            if variable.lb is None:
                                lb = -gurobipy.GRB.INFINITY
                Severity: Minor
                Found in src/optlang/gurobi_interface.py - About 35 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 solve_with_glpsol has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                def solve_with_glpsol(glp_prob):
                    """Solve glpk problem with glpsol commandline solver. Mainly for testing purposes.
                
                    # Examples
                    # --------
                Severity: Minor
                Found in src/optlang/util.py - About 35 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 _add_variables has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _add_variables(self, variables):
                        super()._add_variables(variables)
                        self.problem.reset()
                        for variable in variables:
                            lb = -Infinity if variable.lb is None else float(variable.lb)
                Severity: Minor
                Found in src/optlang/matrix_interface.py - About 35 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

                Severity
                Category
                Status
                Source
                Language