biosustain/optlang

View on GitHub

Showing 157 of 209 total issues

Function render has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]:
    """Render the given version pieces into the requested style."""
    if pieces["error"]:
        return {"version": "unknown",
                "full-revisionid": pieces.get("long"),
Severity: Minor
Found in src/optlang/_version.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 expr_to_json has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def expr_to_json(expr):
    """
    Converts a Sympy expression to a json-compatible tree-structure.
    """
    if isinstance(expr, symbolics.Mul):
Severity: Minor
Found in src/optlang/util.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 _add_constraints has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def _add_constraints(self, constraints, sloppy=False):
        if sloppy is False:
            for c in constraints:
                if not c.is_Linear:
                    raise ValueError("Scipy solver only works with linear constraints. Please use another interface.")
Severity: Minor
Found in src/optlang/scipy_interface.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 _add_constraints has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def _add_constraints(self, constraints, sloppy=False):
        super()._add_constraints(constraints, sloppy=sloppy)
        self.problem.reset()
        for constraint in constraints:
            # This needs to be done in order to not trigger constraint._get_expression()
Severity: Minor
Found in src/optlang/matrix_interface.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 a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def __init__(self, name=None, objective=None, variables=None, constraints=None, problem=None, *args, **kwargs):
        super(Model, self).__init__(*args, **kwargs)

        self._objective = self.interface.Objective(0)
        self._objective.problem = self
Severity: Minor
Found in src/optlang/interface.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 solve_osqp has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def solve_osqp(self):
        """Solve a QP with OSQP."""
        settings = self.osqp_settings()
        d = float(self.direction)
        sp = self.build(add_variable_constraints=True)
Severity: Minor
Found in src/optlang/hybrid_interface.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 _remove_constraints has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def _remove_constraints(self, constraints):
        not_removed = True
        if len(constraints) > 350:  # Need to figure out a good threshold here
            keys = map(lambda c: c.name, constraints)
            self._constraints = self._constraints.fromkeys(set(self._constraints.keys()).difference(set(keys)))
Severity: Minor
Found in src/optlang/coinor_cbc_interface.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 render has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]:
    """Render the given version pieces into the requested style."""
    if pieces["error"]:
        return {"version": "unknown",
                "full-revisionid": pieces.get("long"),
Severity: Minor
Found in versioneer.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 do_setup has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def do_setup() -> int:
    """Do main VCS-independent setup function for installing Versioneer."""
    root = get_root()
    try:
        cfg = get_config_from_root(root)
Severity: Minor
Found in versioneer.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 git_pieces_from_vcs has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def git_pieces_from_vcs(
    tag_prefix: str,
    root: str,
    verbose: bool,
    runner: Callable = run_command
Severity: Minor
Found in src/optlang/_version.py - About 1 hr to fix

    Function git_pieces_from_vcs has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def git_pieces_from_vcs(
        tag_prefix: str,
        root: str,
        verbose: bool,
        runner: Callable = run_command
    Severity: Minor
    Found in versioneer.py - About 1 hr to fix

      Function to_lp has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def to_lp(self):
              self.update()
      
              lp_form = ('Maximize' if self.problem.sense == mip.MAXIMIZE else 'Minimize') + '\n'
              for i, (var, coef) in enumerate(self.problem.objective.expr.items()):
      Severity: Minor
      Found in src/optlang/coinor_cbc_interface.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 render_pep440 has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def render_pep440(pieces: Dict[str, Any]) -> str:
          """Build up version string, with post-release "local version identifier".
      
          Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
          get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
      Severity: Minor
      Found in src/optlang/_version.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 render_pep440_post has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def render_pep440_post(pieces: Dict[str, Any]) -> str:
          """TAG[.postDISTANCE[.dev0]+gHEX] .
      
          The ".dev0" means dirty. Note that .dev0 sorts backwards
          (a dirty tree will appear "older" than the corresponding clean one),
      Severity: Minor
      Found in src/optlang/_version.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 render_pep440 has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def render_pep440(pieces: Dict[str, Any]) -> str:
          """Build up version string, with post-release "local version identifier".
      
          Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
          get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
      Severity: Minor
      Found in versioneer.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 type has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def type(self, value):
              if self.problem is not None:
                  if value not in _TYPES:
                      raise ValueError(
                          "This interface cannot handle variables of type '%s'. " % value
      Severity: Minor
      Found in src/optlang/matrix_interface.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 _add_constraints has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _add_constraints(self, constraints, sloppy=False):
              super(Model, self)._add_constraints(constraints, sloppy=sloppy)
              for constraint in constraints:
                  if constraint.lb is None and constraint.ub is None:
                      raise ValueError("optlang does not support free constraints in the gurobi interface.")
      Severity: Minor
      Found in src/optlang/gurobi_interface.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 render_pep440_post has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def render_pep440_post(pieces: Dict[str, Any]) -> str:
          """TAG[.postDISTANCE[.dev0]+gHEX] .
      
          The ".dev0" means dirty. Note that .dev0 sorts backwards
          (a dirty tree will appear "older" than the corresponding clean one),
      Severity: Minor
      Found in versioneer.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 objective has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def objective(self, value):
              value.problem = None
              if self._objective is not None:  # Reset previous objective
                  variables = self.objective.variables
                  if len(variables) > 0:
      Severity: Minor
      Found in src/optlang/cplex_interface.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

      Consider simplifying this complex logical expression.
      Open

              if value == "EvolutionaryComputation":
                  self._algorithm = inspyred.ec.EvolutionaryComputation
              elif value == "GeneticAlgorithm" or value == "GA":
                  self._algorithm = inspyred.ec.GA(random)
              elif value == "ParticleSwarmOptimization" or value == "PSO":
      Severity: Major
      Found in src/optlang/inspyred_interface.py - About 1 hr to fix
        Severity
        Category
        Status
        Source
        Language