CenterForOpenScience/scrapi

View on GitHub

Showing 45 of 45 total issues

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

class XMLHarvester(BaseHarvester, XMLTransformer):
    file_format = 'xml'

    def normalize(self, raw_doc):
        transformed = self.transform(etree.XML(raw_doc['doc']), fail=settings.RAISE_IN_TRANSFORMER)
Severity: Major
Found in scrapi/base/__init__.py and 1 other location - About 5 hrs to fix
scrapi/base/__init__.py on lines 85..95

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

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

class JSONHarvester(BaseHarvester, JSONTransformer):
    file_format = 'json'

    def normalize(self, raw_doc):
        transformed = self.transform(json.loads(raw_doc['doc']), fail=settings.RAISE_IN_TRANSFORMER)
Severity: Major
Found in scrapi/base/__init__.py and 1 other location - About 5 hrs to fix
scrapi/base/__init__.py on lines 98..108

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

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

        Similar blocks of code found in 2 locations. Consider refactoring.
        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']))
        Severity: Major
        Found in scrapi/migrations.py and 1 other location - About 1 hr to fix
        scrapi/migrations.py on lines 75..78

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

        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 normalized:
                                target_processor.process_normalized(raw, normalized)
                            else:
                                logger.info('Not storing migrated normalized from {} with id {}, document is not in approved set list.'.format(raw.attributes['source'], raw.attributes['docID']))
        Severity: Major
        Found in scrapi/migrations.py and 1 other location - About 1 hr to fix
        scrapi/migrations.py on lines 69..72

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

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

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

                if normalized.attributes['shareProperties'].get('status', None) == 'deleted':
                    self.manager.es.delete(
                        refresh=True,
                        index=index,
                        doc_type=raw_doc['source'],
        Severity: Major
        Found in scrapi/processing/elasticsearch.py and 1 other location - About 1 hr to fix
        scrapi/processing/elasticsearch.py on lines 84..90

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

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

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

                if data['shareProperties'].get('status', None) == 'deleted':
                    self.manager.es.delete(
                        refresh=True,
                        index=index,
                        doc_type=raw_doc['source'],
        Severity: Major
        Found in scrapi/processing/elasticsearch.py and 1 other location - About 1 hr to fix
        scrapi/processing/elasticsearch.py on lines 125..131

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

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

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

                    for version in doc.version_set.all().order_by('id'):
                        yield DocumentTuple(
                            RawDocument(version.raw, clean=False, validate=False),
                            NormalizedDocument(version.normalized, clean=False, validate=False)
            Severity: Minor
            Found in scrapi/processing/postgres.py and 1 other location - About 50 mins to fix
            scrapi/processing/postgres.py on lines 149..151

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

            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

                    yield DocumentTuple(
                        RawDocument(doc.raw, clean=False, validate=False),
                        NormalizedDocument(doc.normalized, clean=False, validate=False)
            Severity: Minor
            Found in scrapi/processing/postgres.py and 1 other location - About 50 mins to fix
            scrapi/processing/postgres.py on lines 144..147

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

            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 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
              Severity
              Category
              Status
              Source
              Language