biosustain/optlang

View on GitHub

Showing 288 of 288 total issues

File versioneer.py has 1650 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Version: 0.29

"""The Versioneer - like a rocketeer, but for versions.

The Versioneer
Severity: Major
Found in versioneer.py - About 4 days to fix

    File interface.py has 1374 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    # Copyright 2013 Novo Nordisk Foundation Center for Biosustainability,
    # Technical University of Denmark.
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    Severity: Major
    Found in src/optlang/interface.py - About 3 days to fix

      Similar blocks of code found in 2 locations. 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: Major
      Found in src/optlang/glpk_interface.py and 1 other location - About 2 days to fix
      src/optlang/glpk_interface.py on lines 816..841

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 257.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. 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: Major
      Found in src/optlang/glpk_interface.py and 1 other location - About 2 days to fix
      src/optlang/glpk_interface.py on lines 782..807

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 257.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      File matrix_interface.py has 868 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      # Licensed under the Apache License, Version 2.0 (the "License");
      # you may not use this file except in compliance with the License.
      # You may obtain a copy of the License at
      #
      # http://www.apache.org/licenses/LICENSE-2.0
      Severity: Major
      Found in src/optlang/matrix_interface.py - About 2 days to fix

        File cplex_interface.py has 799 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        # Copyright 2013 Novo Nordisk Foundation Center for Biosustainability,
        # Technical University of Denmark.
        #
        # Licensed under the Apache License, Version 2.0 (the "License");
        # you may not use this file except in compliance with the License.
        Severity: Major
        Found in src/optlang/cplex_interface.py - About 1 day to fix

          File glpk_interface.py has 733 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          # Copyright 2013 Novo Nordisk Foundation Center for Biosustainability,
          # Technical University of Denmark.
          #
          # Licensed under the Apache License, Version 2.0 (the "License");
          # you may not use this file except in compliance with the License.
          Severity: Major
          Found in src/optlang/glpk_interface.py - About 1 day to fix

            Function convert_linear_problem_to_dual has a Cognitive Complexity of 82 (exceeds 5 allowed). Consider refactoring.
            Open

            def convert_linear_problem_to_dual(model, sloppy=False, infinity=None, maintain_standard_form=True, prefix="dual_", dual_model=None):  # NOQA
                """
                A mathematical optimization problem can be viewed as a primal and a dual problem. If the primal problem is
                a minimization problem the dual is a maximization problem, and the optimal value of the dual is a lower bound of
                the optimal value of the primal.
            Severity: Minor
            Found in src/optlang/duality.py - About 1 day 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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            def _constraint_lb_and_ub_to_cplex_sense_rhs_and_range_value(lb, ub):
                """Helper function used by Constraint and Model"""
                if lb is None and ub is None:
                    raise Exception("Free constraint ...")
                elif lb is None:
            Severity: Major
            Found in src/optlang/cplex_interface.py and 1 other location - About 1 day to fix
            src/optlang/gurobi_interface.py on lines 72..94

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 183.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            def _constraint_lb_and_ub_to_gurobi_sense_rhs_and_range_value(lb, ub):
                """Helper function used by Constraint and Model"""
                if lb is None and ub is None:
                    raise Exception("Free constraint ...")
                elif lb is None:
            Severity: Major
            Found in src/optlang/gurobi_interface.py and 1 other location - About 1 day to fix
            src/optlang/cplex_interface.py on lines 140..162

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 183.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            File gurobi_interface.py has 691 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            # Copyright 2013 Novo Nordisk Foundation Center for Biosustainability,
            # Technical University of Denmark.
            #
            # Licensed under the Apache License, Version 2.0 (the "License");
            # you may not use this file except in compliance with the License.
            Severity: Major
            Found in src/optlang/gurobi_interface.py - About 1 day to fix

              File coinor_cbc_interface.py has 590 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              # Copyright 2013 Novo Nordisk Foundation Center for Biosustainability,
              # Technical University of Denmark.
              #
              # Licensed under the Apache License, Version 2.0 (the "License");
              # you may not use this file except in compliance with the License.
              Severity: Major
              Found in src/optlang/coinor_cbc_interface.py - About 1 day to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    @staticmethod
                    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:
                Severity: Major
                Found in src/optlang/interface.py and 1 other location - About 1 day to fix
                src/optlang/interface.py on lines 130..141

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 145.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    @staticmethod
                    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:
                Severity: Major
                Found in src/optlang/interface.py and 1 other location - About 1 day to fix
                src/optlang/interface.py on lines 117..128

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 145.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                File scipy_interface.py has 499 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                # Copyright 2015 Novo Nordisk Foundation Center for Biosustainability,
                # Technical University of Denmark.
                #
                # Licensed under the Apache License, Version 2.0 (the "License");
                # you may not use this file except in compliance with the License.
                Severity: Minor
                Found in src/optlang/scipy_interface.py - About 1 day to fix

                  File _version.py has 495 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  # This file helps to compute a version number in source trees obtained from
                  # git-archive tarball (such as those provided by githubs download-from-tag
                  # feature). Distribution tarballs (built by setup.py sdist) and build
                  # directories (produced by setup.py build) will contain a much shorter file
                  # that just contains the computed version number.
                  Severity: Minor
                  Found in src/optlang/_version.py - About 7 hrs to fix

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                        def _run_glp_mip(self):
                            return_value = glp_intopt(self.problem, self.configuration._iocp)
                            glpk_status = glp_mip_status(self.problem)
                            if return_value == 0:
                                status = _GLPK_STATUS_TO_STATUS[glpk_status]
                    Severity: Major
                    Found in src/optlang/glpk_interface.py and 2 other locations - About 7 hrs to fix
                    src/optlang/glpk_exact_interface.py on lines 71..82
                    src/optlang/glpk_interface.py on lines 679..690

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 114.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                        def _run_glp_exact(self):
                            return_value = glp_exact(self.problem, self.configuration._smcp)
                            glpk_status = glp_get_status(self.problem)
                            if return_value == 0:
                                status = _GLPK_STATUS_TO_STATUS[glpk_status]
                    Severity: Major
                    Found in src/optlang/glpk_exact_interface.py and 2 other locations - About 7 hrs to fix
                    src/optlang/glpk_interface.py on lines 679..690
                    src/optlang/glpk_interface.py on lines 692..703

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 114.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                        def _run_glp_simplex(self):
                            return_value = glp_simplex(self.problem, self.configuration._smcp)
                            glpk_status = glp_get_status(self.problem)
                            if return_value == 0:
                                status = _GLPK_STATUS_TO_STATUS[glpk_status]
                    Severity: Major
                    Found in src/optlang/glpk_interface.py and 2 other locations - About 7 hrs to fix
                    src/optlang/glpk_exact_interface.py on lines 71..82
                    src/optlang/glpk_interface.py on lines 692..703

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 114.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Function is_Quadratic has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def is_Quadratic(self):
                            """Returns True if the expression is a polynomial with degree exactly 2 (read-only)."""
                            if self.expression.is_Atom:
                                return False
                            if all((len(key.free_symbols) < 2 and (key.is_Add or key.is_Mul or key.is_Atom)
                    Severity: Minor
                    Found in src/optlang/interface.py - About 5 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

                    Severity
                    Category
                    Status
                    Source
                    Language