CenterForOpenScience/scrapi

View on GitHub

Showing 35 of 45 total issues

File helpers.py has 354 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import unicode_literals

import re
import logging
import functools
Severity: Minor
Found in scrapi/base/helpers.py - About 4 hrs to fix

    Function cross_db has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def cross_db(docs, source_db=None, target_db=None, index=None, versions=False, **kwargs):
        """
        Migration to go between
            cassandra > postgres
            postgres > cassandra
    Severity: Minor
    Found in scrapi/migrations.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

    File cassandra.py has 290 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    from __future__ import absolute_import
    
    import six
    import json
    import logging
    Severity: Minor
    Found in scrapi/processing/cassandra.py - About 2 hrs to fix

      File tasks.py has 255 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import os
      import base64
      import logging
      import platform
      from datetime import date, timedelta
      Severity: Minor
      Found in tasks.py - About 2 hrs to fix

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

        def logged(event, index=None):
            def _logged(func):
                @wraps(func)
                def wrapped(*args, **kwargs):
                    context = extract_context(func, *args, **kwargs)
        Severity: Minor
        Found in scrapi/events.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 seperate_provider_object_uris has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        def seperate_provider_object_uris(identifiers):
            object_uris = gather_object_uris(identifiers)
            provider_uris = []
            for item in identifiers:
        
        
        Severity: Minor
        Found in scrapi/base/helpers.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 documents has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def documents(self, *sources):
                q = Document.objects.all()
                querysets = (q.filter(source=source) for source in sources) if sources else [q]
                for query in querysets:
                    for doc in paginated(query):
        Severity: Minor
        Found in scrapi/processing/postgres.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 strip_empty has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        def strip_empty(document, required=tuple()):
            ''' Removes empty fields from the processed schema
            '''
            new_doc = {}
            for k, v in document.items():
        Severity: Minor
        Found in scrapi/linter/document.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 to_normalized has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def to_normalized(self, doc):
                # make the new dict actually contain real items
                normed = {}
                do_not_include = ['docID', 'doc', 'filetype', 'timestamps', 'source', 'versions', 'key']
                for key, value in dict(doc).items():
        Severity: Minor
        Found in scrapi/processing/cassandra.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 migrate has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def migrate(migration, source_db=None, sources=tuple(), async=False, dry=True, group_size=1000, **kwargs):
        Severity: Major
        Found in scrapi/tasks.py - About 50 mins to fix

          Function record_or_load_response has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def record_or_load_response(method, url, throttle=None, force=False, params=None, expected=(200,), **kwargs):
          Severity: Major
          Found in scrapi/requests.py - About 50 mins to fix

            Function cross_db has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def cross_db(docs, source_db=None, target_db=None, index=None, versions=False, **kwargs):
            Severity: Minor
            Found in scrapi/migrations.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if norm_version:
                                          target_processor.process_normalized(raw_version, norm_version)
                                      else:
                                          logger.info('Not storing migrated normalized version from {} with id {}, document is not in approved set list.'.format(raw.attributes['source'], raw.attributes['docID']))
                              else:
              Severity: Major
              Found in scrapi/migrations.py - About 45 mins to fix

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

                def format_tags(all_tags, sep=','):
                    tags = []
                    if isinstance(all_tags, six.string_types):
                        tags = all_tags.split(sep)
                    elif isinstance(all_tags, list):
                Severity: Minor
                Found in scrapi/base/helpers.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 populate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def populate(grid_file):
                    transformer = JSONTransformer(schema)
                    for doc in get_jsons(grid_file):
                        transformed = transformer.transform(doc, load=False)
                        try:
                Severity: Minor
                Found in institutions/grid.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 record_or_load_response has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def record_or_load_response(method, url, throttle=None, force=False, params=None, expected=(200,), **kwargs):
                
                    resp = _maybe_load_response(method, url)
                
                    if not force and resp and resp.ok:
                Severity: Minor
                Found in scrapi/requests.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 migrate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def migrate(migration, source_db=None, sources=tuple(), async=False, dry=True, group_size=1000, **kwargs):
                
                    source_db = source_db or settings.CANONICAL_PROCESSOR
                    documents = processing.get_processor(source_db).documents
                
                
                Severity: Minor
                Found in scrapi/tasks.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 migrate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def migrate(migration, sources=None, kwargs_string=None, dry=True, async=False, group_size=1000):
                    ''' Task to run a migration.
                
                    :param migration: The migration function to run. This is passed in
                    as a string then interpreted as a function by the invoke task.
                Severity: Minor
                Found in tasks.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 migrate has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                def migrate(migration, sources=None, kwargs_string=None, dry=True, async=False, group_size=1000):
                Severity: Minor
                Found in tasks.py - About 45 mins to fix

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

                  def test(cov=True, doctests=True, verbose=False, debug=False, pdb=False):
                  Severity: Minor
                  Found in tasks.py - About 35 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language