HumanCellAtlas/ingest-archiver

View on GitHub

Showing 20 of 20 total issues

File archiver.py has 605 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import logging
import sys

import polling as polling
Severity: Major
Found in archiver/archiver.py - About 1 day to fix

    File converter.py has 426 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import logging
    import re
    
    from flatten_json import flatten
    
    
    Severity: Minor
    Found in archiver/converter.py - About 6 hrs to fix

      IngestAPI has 27 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class IngestAPI:
          def __init__(self, url=None):
              self.logger = logging.getLogger(__name__)
              self.headers = {
                  'Content-type': 'application/json',
      Severity: Minor
      Found in archiver/ingest_api.py - About 3 hrs to fix

        USIAPI has 24 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class USIAPI:
            def __init__(self, url=None):
                self.logger = logging.getLogger(__name__)
                self.url = url if url else config.USI_API_URL
                self.logger.info(f'Using {self.url}')
        Severity: Minor
        Found in archiver/usi_api.py - About 2 hrs to fix

          Function rename_attributes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              def rename_attributes(self, converted_data, hca_data):
                  new_attributes = {}
                  attributes = converted_data.get('attributes')
          
                  for field, value in attributes.items():
          Severity: Minor
          Found in archiver/converter.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 _convert has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              def _convert(self, assay_bundle: AssayBundle):
                  aggregator = ArchiveEntityAggregator(assay_bundle, alias_prefix=self.alias_prefix)
          
                  entities = []
                  for archive_entity_type in ["project", "study", "sample", "sequencingExperiment", "sequencingRun"]:
          Severity: Minor
          Found in archiver/archiver.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 _flatten has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def _flatten(self, hca_data):
                  input_data = dict(hca_data)
          
                  for key in self.exclude_data:
                      if key in input_data:
          Severity: Minor
          Found in archiver/converter.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 _build_output has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              def _build_output(self, extracted_data, flattened_hca_data, hca_data=None):
                  # TODO BioStudies minimum length
                  title_len = len(extracted_data["title"])
                  MIN_LEN = 25
                  DELIM = ' , '
          Severity: Minor
          Found in archiver/converter.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 get_conversion_summary has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_conversion_summary(self):
                  summary = {}
                  for entities_dict in self.entities_dict_type.values():
                      for entity in entities_dict.values():
                          if entity.conversion and not entity.errors:
          Severity: Minor
          Found in archiver/archiver.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 _extract_attributes has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def _extract_attributes(self, flattened_hca_data):
                  attributes = {}
                  prefix = "content__"
                  ontology_keyword = "__ontology"
                  ontology_text_keyword = "__text"
          Severity: Minor
          Found in archiver/converter.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 notify_file_archiver has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def notify_file_archiver(self, archive_submission: ArchiveSubmission):
          
                  messages = []
                  # TODO a bit redundant with converter, refactor this
                  for entity in archive_submission.converted_entities:
          Severity: Minor
          Found in archiver/archiver.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 _build_output has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def _build_output(self, extracted_data, flattened_hca_data, hca_data=None):
                  extracted_data["studyRef"] = {}
                  extracted_data["sampleUses"] = []
          
                  if not extracted_data.get("attributes"):
          Severity: Minor
          Found in archiver/converter.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 _extract_fields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def _extract_fields(self, flattened_hca_data, hca_data):
                  extracted_data = {}
          
                  for key, new_key in self.field_mapping.items():
                      if key in flattened_hca_data:
          Severity: Minor
          Found in archiver/converter.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self, ingest_api, usi_api, ontology_api, exclude_types=None, alias_prefix=None):
          Severity: Minor
          Found in archiver/archiver.py - About 45 mins to fix

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

                def _get_all(self, url, entity_type):
                    r = self.session.get(url, headers=self.headers)
                    r.raise_for_status()
                    if "_embedded" in r.json():
                        for entity in r.json()["_embedded"][entity_type]:
            Severity: Minor
            Found in archiver/ingest_api.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 _get_all has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def _get_all(self, url, entity_type):
                    r = self.session.get(url, headers=self.get_headers())
                    r.raise_for_status()
                    if "_embedded" in r.json():
                        for entity in r.json()["_embedded"][entity_type]:
            Severity: Minor
            Found in archiver/usi_api.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 get_converted_entities has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_converted_entities(self):
                    for entities_dict in self.entities_dict_type.values():
                        for entity in entities_dict.values():
                            if entity.conversion and not entity.errors:
                                yield entity
            Severity: Minor
            Found in archiver/archiver.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 get_all_validation_errors has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_all_validation_errors(self):
                    get_validation_results_url = self.usi_submission['_links']['validationResults']['href']
                    validation_results = self.usi_api.get_validation_results(get_validation_results_url)
            
                    errors = []
            Severity: Minor
            Found in archiver/archiver.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

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

                def validate_and_submit(self):
                    if not self.usi_submission:
                        return self
            
                    print("Waiting for the submission to be validated in USI...")
            Severity: Minor
            Found in archiver/archiver.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

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

                def expand_curie(self, term):
                    term = quote(term)
                    params = f'q={term}&exact=true&groupField=true&queryFields=obo_id'
                    query_url = f'{self.url}/api/search?{params}'
            
            
            Severity: Minor
            Found in archiver/ontology_api.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

            Severity
            Category
            Status
            Source
            Language