NationalGenomicsInfrastructure/ngi_pipeline

View on GitHub
ngi_pipeline/utils/filesystem.py

Summary

Maintainability
F
3 days
Test Coverage

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

def recreate_project_from_filesystem(project_dir,
                                     restrict_to_samples=None,
                                     restrict_to_libpreps=None,
                                     restrict_to_seqruns=None,
                                     config=None, config_file_path=None):
Severity: Minor
Found in ngi_pipeline/utils/filesystem.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

File filesystem.py has 335 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import print_function

import contextlib
import datetime
import fnmatch
Severity: Minor
Found in ngi_pipeline/utils/filesystem.py - About 4 hrs to fix

    Function match_files_under_dir has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def match_files_under_dir(dirname, pattern, pt_style="regex", realpath=True):
        """Find all the files under a directory that match pattern.
    
        :parm str dirname: The directory under which to search
        :param str pattern: The pattern against which to match
    Severity: Minor
    Found in ngi_pipeline/utils/filesystem.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 locate_project has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def locate_project(project, subdir="DATA", resolve_symlinks=True,
                       config=None, config_file_path=None):
        """Given a project, returns the full path to the project if possible,
        searching the config file's specified analysis.top_dir if needed.
        If the project passed in is already a valid path, returns that.
    Severity: Minor
    Found in ngi_pipeline/utils/filesystem.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 locate_flowcell has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def locate_flowcell(flowcell, config=None, config_file_path=None):
        """Given a flowcell, returns the full path to the flowcell if possible,
        searching the config file's specified environment.flowcell_inbox
        if needed. If the flowcell passed in is already a valid path, returns that.
    
    
    Severity: Minor
    Found in ngi_pipeline/utils/filesystem.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 execute_command_line has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def execute_command_line(cl, shell=False, stdout=None, stderr=None, cwd=None):
        """Execute a command line and return the subprocess.Popen object.
    
        :param cl: Can be either a list or a string; if string, gets shlex.splitted
        :param bool shell: value of shell to pass to subprocess
    Severity: Minor
    Found in ngi_pipeline/utils/filesystem.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 recreate_project_from_filesystem has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def recreate_project_from_filesystem(project_dir,
    Severity: Minor
    Found in ngi_pipeline/utils/filesystem.py - About 45 mins to fix

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

      def locate_project(project, subdir="DATA", resolve_symlinks=True,
      Severity: Minor
      Found in ngi_pipeline/utils/filesystem.py - About 35 mins to fix

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

        def execute_command_line(cl, shell=False, stdout=None, stderr=None, cwd=None):
        Severity: Minor
        Found in ngi_pipeline/utils/filesystem.py - About 35 mins to fix

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

          def rotate_file(file_path, new_subdirectory="rotated_files"):
              if os.path.exists(file_path) and os.path.isfile(file_path):
                  file_dirpath, extension = os.path.splitext(file_path)
                  file_name = os.path.basename(file_dirpath)
                  current_datetime = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S:%f")
          Severity: Minor
          Found in ngi_pipeline/utils/filesystem.py - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function safe_makedir has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def safe_makedir(dname, mode=0o2770):
              """Make a directory (tree) if it doesn't exist, handling concurrent race
              conditions.
              """
              if not os.path.exists(dname):
          Severity: Minor
          Found in ngi_pipeline/utils/filesystem.py - About 25 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

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

                      project_data_dir=os.path.join(config["analysis"]["base_root"], config["analysis"]["sthlm_root"], config["analysis"]["top_dir"], subdir)
          Severity: Major
          Found in ngi_pipeline/utils/filesystem.py and 1 other location - About 2 hrs to fix
          ngi_pipeline/utils/filesystem.py on lines 110..111

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

          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 not os.path.exists(project_data_dir):
                          project_data_dir=os.path.join(config["analysis"]["base_root"], config["analysis"]["upps_root"], config["analysis"]["top_dir"], subdir)
          Severity: Major
          Found in ngi_pipeline/utils/filesystem.py and 1 other location - About 2 hrs to fix
          ngi_pipeline/utils/filesystem.py on lines 109..109

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

          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 4 locations. Consider refactoring.
          Open

                  if restrict_to_samples and sample_name not in restrict_to_samples:
                      LOG.debug('Skipping sample "{}": not in specified samples '
                                '"{}"'.format(sample_name, ', '.join(restrict_to_samples)))
                      continue
          Severity: Major
          Found in ngi_pipeline/utils/filesystem.py and 3 other locations - About 1 hr to fix
          ngi_pipeline/conductor/flowcell.py on lines 240..243
          ngi_pipeline/utils/filesystem.py on lines 310..313
          ngi_pipeline/utils/filesystem.py on lines 324..327

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

          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 4 locations. Consider refactoring.
          Open

                          if restrict_to_seqruns and seqrun_name not in restrict_to_seqruns:
                              LOG.debug('Skipping seqrun "{}": not in specified seqruns '
                                        '"{}"'.format(seqrun_name, ', '.join(restrict_to_seqruns)))
                              continue
          Severity: Major
          Found in ngi_pipeline/utils/filesystem.py and 3 other locations - About 1 hr to fix
          ngi_pipeline/conductor/flowcell.py on lines 240..243
          ngi_pipeline/utils/filesystem.py on lines 297..300
          ngi_pipeline/utils/filesystem.py on lines 310..313

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

          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 4 locations. Consider refactoring.
          Open

                      if restrict_to_libpreps and libprep_name not in restrict_to_libpreps:
                          LOG.debug('Skipping libprep "{}": not in specified libpreps '
                                    '"{}"'.format(libprep_name, ', '.join(restrict_to_libpreps)))
                          continue
          Severity: Major
          Found in ngi_pipeline/utils/filesystem.py and 3 other locations - About 1 hr to fix
          ngi_pipeline/conductor/flowcell.py on lines 240..243
          ngi_pipeline/utils/filesystem.py on lines 297..300
          ngi_pipeline/utils/filesystem.py on lines 324..327

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

          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