conan-io/conan

View on GitHub
conans/client/tools/win.py

Summary

Maintainability
F
1 wk
Test Coverage

Function vcvars_command has a Cognitive Complexity of 56 (exceeds 20 allowed). Consider refactoring.
Open

def vcvars_command(conanfile=None, arch=None, compiler_version=None, force=False, vcvars_ver=None,
                   winsdk_version=None, output=None, settings=None):
    # Handle input arguments (backwards compatibility with 'settings' as first argument)
    # TODO: This can be promoted to a decorator pattern for any function
    if conanfile and settings:
Severity: Minor
Found in conans/client/tools/win.py - About 6 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

Function vs_installation_path has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring.
Open

def vs_installation_path(version, preference=None):

    if not preference:
        preference = get_env("CONAN_VS_INSTALLATION_PREFERENCE", list())
        if not preference:  # default values
Severity: Minor
Found in conans/client/tools/win.py - About 3 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

Function run_in_windows_bash has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
Open

def run_in_windows_bash(conanfile, bashcmd, cwd=None, subsystem=None, msys_mingw=True, env=None,
                        with_login=True):
    """ Will run a unix command inside a bash terminal
        It requires to have MSYS2, CYGWIN, or WSL
    """
Severity: Minor
Found in conans/client/tools/win.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

Avoid deeply nested control flow statements.
Open

                    if product_type in product["productId"]:
                        vs_paths.append(product["installationPath"])

        # Append products without "productId" (Legacy installations)
        for product in seen_products:
Severity: Major
Found in conans/client/tools/win.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        if os.path.isfile(windows_h):
                            return sdk_version
        return None
    Severity: Major
    Found in conans/client/tools/win.py - About 45 mins to fix

      Function build_sln_command has 12 arguments (exceeds 10 allowed). Consider refactoring.
      Open

      def build_sln_command(settings, sln_path, targets=None, upgrade_project=True, build_type=None,
      Severity: Major
      Found in conans/client/tools/win.py - About 45 mins to fix

        Function msvc_build_command has 11 arguments (exceeds 10 allowed). Consider refactoring.
        Open

        def msvc_build_command(settings, sln_path, targets=None, upgrade_project=True, build_type=None,
        Severity: Major
        Found in conans/client/tools/win.py - About 35 mins to fix

          Avoid too many return statements within this function.
          Open

              return None
          Severity: Major
          Found in conans/client/tools/win.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return None
            Severity: Major
            Found in conans/client/tools/win.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return '/mnt' + path[0:2].lower() + path[2:]
              Severity: Major
              Found in conans/client/tools/win.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return path if path_flavor == WSL else path.lower()
                Severity: Major
                Found in conans/client/tools/win.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return '/dev/fs' + path[0] + path[1:].capitalize()
                  Severity: Major
                  Found in conans/client/tools/win.py - About 30 mins to fix

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

                    def get_cased_path(name):
                        if platform.system() != "Windows":
                            return name
                        if not os.path.isabs(name):
                            name = os.path.abspath(name)
                    Severity: Major
                    Found in conans/client/tools/win.py and 1 other location - About 1 day to fix
                    conans/client/subsystems.py on lines 195..219

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

                    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

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

                                if only_diff:
                                    old_value = os.environ.get(name_var)
                                    if name_var.lower() == "path":
                                        old_values_lower = [v.lower() for v in old_value.split(os.pathsep)]
                                        # Clean all repeated entries, not append if the element was already there
                    Severity: Major
                    Found in conans/client/tools/win.py and 1 other location - About 1 day to fix
                    conans/client/tools/env.py on lines 142..157

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

                    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

                        if append_prefix:
                            if path_flavor in (MSYS, MSYS2):
                                return path.lower()
                            elif path_flavor == CYGWIN:
                                return '/cygdrive' + path.lower()
                    Severity: Major
                    Found in conans/client/tools/win.py and 1 other location - About 1 day to fix
                    conans/client/subsystems.py on lines 180..191

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

                    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 escape_windows_cmd(command):
                        """ To use in a regular windows cmd.exe
                            1. Adds escapes so the argument can be unpacked by CommandLineToArgvW()
                            2. Adds escapes for cmd.exe so the argument survives cmd.exe's substitutions.
                    
                    
                    Severity: Major
                    Found in conans/client/tools/win.py and 1 other location - About 2 hrs to fix
                    conans/client/subsystems.py on lines 108..116

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

                    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

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

                            if compiler == "intel":
                                compiler_version = compiler_version if "." in compiler_version else \
                                    "%s.0" % compiler_version
                                toolset = "Intel C++ Compiler " + compiler_version
                    Severity: Minor
                    Found in conans/client/tools/win.py and 1 other location - About 45 mins to fix
                    conan/tools/cmake/toolchain/blocks.py on lines 746..749

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

                    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

                                    _path_key = next((name for name in container.keys() if "path" == name.lower()), None)
                    Severity: Minor
                    Found in conans/client/tools/win.py and 1 other location - About 40 mins to fix
                    conans/client/tools/win.py on lines 548..548

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

                    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

                            path_key = next((name for name in new_env.keys() if "path" == name.lower()), None)
                    Severity: Minor
                    Found in conans/client/tools/win.py and 1 other location - About 40 mins to fix
                    conans/client/tools/win.py on lines 677..677

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

                    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

                        if len(property_) != 0:
                            arguments.append("-property")
                            arguments.append(property_)
                    Severity: Minor
                    Found in conans/client/tools/win.py and 1 other location - About 30 mins to fix
                    conans/client/tools/win.py on lines 310..312

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

                    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

                        if len(version) != 0:
                            arguments.append("-version")
                            arguments.append(version)
                    Severity: Minor
                    Found in conans/client/tools/win.py and 1 other location - About 30 mins to fix
                    conans/client/tools/win.py on lines 320..322

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

                    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

                    Line too long (101 > 100 characters)
                    Open

                            path = get_cased_path(path)  # if the path doesn't exist (and abs) we cannot guess the casing
                    Severity: Minor
                    Found in conans/client/tools/win.py by pep8

                    Limit all lines to a maximum of 79 characters.

                    There are still many devices around that are limited to 80 character
                    lines; plus, limiting windows to 80 characters makes it possible to
                    have several windows side-by-side.  The default wrapping on such
                    devices looks ugly.  Therefore, please limit all lines to a maximum
                    of 79 characters. For flowing long blocks of text (docstrings or
                    comments), limiting the length to 72 characters is recommended.
                    
                    Reports error E501.

                    Line too long (101 > 100 characters)
                    Open

                                    _path_key = next((name for name in container.keys() if "path" == name.lower()), None)
                    Severity: Minor
                    Found in conans/client/tools/win.py by pep8

                    Limit all lines to a maximum of 79 characters.

                    There are still many devices around that are limited to 80 character
                    lines; plus, limiting windows to 80 characters makes it possible to
                    have several windows side-by-side.  The default wrapping on such
                    devices looks ugly.  Therefore, please limit all lines to a maximum
                    of 79 characters. For flowing long blocks of text (docstrings or
                    comments), limiting the length to 72 characters is recommended.
                    
                    Reports error E501.

                    There are no issues that match your filters.

                    Category
                    Status