ariofrio/oration

View on GitHub
templates/azure/py/WorkerRole/virtualenv.py

Summary

Maintainability
F
4 mos
Test Coverage

File virtualenv.py has 1566 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
"""Create a "virtual" Python installation
"""

# If you change the version here, change it in setup.py 
Severity: Major
Found in templates/azure/py/WorkerRole/virtualenv.py - About 4 days to fix

    Function install_python has a Cognitive Complexity of 89 (exceeds 5 allowed). Consider refactoring.
    Open

    def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear):
        """Install just the base environment, no distutils patches etc"""
        if sys.executable.startswith(bin_dir):
            print('Please use the *system* python to run this script')
            return
    Severity: Minor
    Found in templates/azure/py/WorkerRole/virtualenv.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

    Function call_subprocess has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

    def call_subprocess(cmd, show_stdout=True,
                        filter_stdout=None, cwd=None,
                        raise_on_returncode=True, extra_env=None,
                        remove_from_env=None):
        cmd_parts = []
    Severity: Minor
    Found in templates/azure/py/WorkerRole/virtualenv.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 _install_req has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

    def _install_req(py_executable, unzip=False, distribute=False,
                     search_dirs=None, never_download=False):
    
        if search_dirs is None:
            search_dirs = file_search_dirs()
    Severity: Minor
    Found in templates/azure/py/WorkerRole/virtualenv.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

    Function fixup_pth_and_egg_link has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def fixup_pth_and_egg_link(home_dir, sys_path=None):
        """Makes .pth and .egg-link files use relative paths"""
        home_dir = os.path.normcase(os.path.abspath(home_dir))
        if sys_path is None:
            sys_path = sys.path
    Severity: Minor
    Found in templates/azure/py/WorkerRole/virtualenv.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 log has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def log(self, level, msg, *args, **kw):
            if args:
                if kw:
                    raise TypeError(
                        "You may give positional or keyword arguments, not both")
    Severity: Minor
    Found in templates/azure/py/WorkerRole/virtualenv.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 main has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def main():
        parser = optparse.OptionParser(
            version=virtualenv_version,
            usage="%prog [OPTIONS] DEST_DIR")
    
    
    Severity: Minor
    Found in templates/azure/py/WorkerRole/virtualenv.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

    Function fixup_scripts has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def fixup_scripts(home_dir):
        # This is what we expect at the top of scripts:
        shebang = '#!%s/bin/python' % os.path.normcase(os.path.abspath(home_dir))
        # This is what we'll put:
        new_shebang = '#!/usr/bin/env python%s' % sys.version[:3]
    Severity: Minor
    Found in templates/azure/py/WorkerRole/virtualenv.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 copy_required_modules has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def copy_required_modules(dst_prefix):
        import imp
        for modname in REQUIRED_MODULES:
            if modname in sys.builtin_module_names:
                logger.info("Ignoring built-in bootstrap module: %s" % modname)
    Severity: Minor
    Found in templates/azure/py/WorkerRole/virtualenv.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 install_python has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear):
        """Install just the base environment, no distutils patches etc"""
        if sys.executable.startswith(bin_dir):
            print('Please use the *system* python to run this script')
            return
    Severity: Minor
    Found in templates/azure/py/WorkerRole/virtualenv.py - About 1 hr to fix

      Function main has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def main():
          parser = optparse.OptionParser(
              version=virtualenv_version,
              usage="%prog [OPTIONS] DEST_DIR")
      
      
      Severity: Minor
      Found in templates/azure/py/WorkerRole/virtualenv.py - About 1 hr to fix

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

        def filter_ez_setup(line, project_name='setuptools'):
            if not line.strip():
                return Logger.DEBUG
            if project_name == 'distribute':
                for prefix in ('Extracting', 'Now working', 'Installing', 'Before',
        Severity: Minor
        Found in templates/azure/py/WorkerRole/virtualenv.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 create_environment has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def create_environment(home_dir, site_packages=True, clear=False,
        Severity: Major
        Found in templates/azure/py/WorkerRole/virtualenv.py - About 1 hr to fix

          Function fixup_pth_file has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def fixup_pth_file(filename):
              lines = []
              prev_lines = []
              f = open(filename)
              prev_lines = f.readlines()
          Severity: Minor
          Found in templates/azure/py/WorkerRole/virtualenv.py - About 55 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 path_locations has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def path_locations(home_dir):
              """Return the path locations for the environment (where libraries are,
              where scripts go, etc)"""
              # XXX: We'd use distutils.sysconfig.get_python_inc/lib but its
              # prefix arg is broken: http://bugs.python.org/issue3386
          Severity: Minor
          Found in templates/azure/py/WorkerRole/virtualenv.py - About 55 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 install_pip has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def install_pip(py_executable, search_dirs=None, never_download=False):    
              if search_dirs is None:
                  search_dirs = file_search_dirs()
          
              filenames = []
          Severity: Minor
          Found in templates/azure/py/WorkerRole/virtualenv.py - About 55 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 copyfile has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def copyfile(src, dest, symlink=True):
              if not os.path.exists(src):
                  # Some bad symlink in the src
                  logger.warn('Cannot find file %s (bad symlink)', src)
                  return
          Severity: Minor
          Found in templates/azure/py/WorkerRole/virtualenv.py - About 55 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 call_subprocess has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def call_subprocess(cmd, show_stdout=True,
          Severity: Major
          Found in templates/azure/py/WorkerRole/virtualenv.py - About 50 mins to fix

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

            def resolve_interpreter(exe):
                """
                If the executable given isn't an absolute path, search $PATH for the interpreter
                """
                if os.path.abspath(exe) != exe:
            Severity: Minor
            Found in templates/azure/py/WorkerRole/virtualenv.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 install_activate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            def install_activate(home_dir, bin_dir, prompt=None):
                if sys.platform == 'win32' or is_jython and os._name == 'nt':
                    files = {'activate.bat': ACTIVATE_BAT,
                             'deactivate.bat': DEACTIVATE_BAT}
                    if os.environ.get('OS') == 'Windows_NT' and os.environ.get('OSTYPE') == 'cygwin':
            Severity: Minor
            Found in templates/azure/py/WorkerRole/virtualenv.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 install_python has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear):
            Severity: Minor
            Found in templates/azure/py/WorkerRole/virtualenv.py - About 45 mins to fix

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

              def writefile(dest, content, overwrite=True):
                  if not os.path.exists(dest):
                      logger.info('Writing %s', dest)
                      f = open(dest, 'wb')
                      f.write(content.encode('utf-8'))
              Severity: Minor
              Found in templates/azure/py/WorkerRole/virtualenv.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 _install_req has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              def _install_req(py_executable, unzip=False, distribute=False,
              Severity: Minor
              Found in templates/azure/py/WorkerRole/virtualenv.py - About 35 mins to fix

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

                    def level_matches(self, level, consumer_level):
                        """
                        >>> l = Logger([])
                        >>> l.level_matches(3, 4)
                        False
                Severity: Minor
                Found in templates/azure/py/WorkerRole/virtualenv.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

                Avoid too many return statements within this function.
                Open

                    return Logger.INFO
                Severity: Major
                Found in templates/azure/py/WorkerRole/virtualenv.py - About 30 mins to fix

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

                  Severity: Major
                  Found in templates/azure/py/WorkerRole/virtualenv.py and 1 other location - About 3 mos to fix
                  templates/azure/java/WorkerRole/virtualenv.py on lines 0..1952

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

                  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

                  There are no issues that match your filters.

                  Category
                  Status