File io.py
has 2243 lines of code (exceeds 250 allowed). Consider refactoring. Open
""" Reading/writing schema objects to/from files
* Comma separated values (.csv)
* XLSX (.xlsx)
* JavaScript Object Notation (.json)
Function run
has a Cognitive Complexity of 147 (exceeds 5 allowed). Consider refactoring. Open
def run(self, path, schema_name=None, models=None,
allow_multiple_sheets_per_model=False,
ignore_missing_models=False, ignore_extra_models=False,
ignore_sheet_order=False,
include_all_attributes=True, ignore_missing_attributes=False, ignore_extra_attributes=False,
- Read upRead up
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 read_model
has a Cognitive Complexity of 109 (exceeds 5 allowed). Consider refactoring. Open
def read_model(self, reader, sheet_name, schema_name, model, include_all_attributes=True,
ignore_missing_attributes=False, ignore_extra_attributes=False,
ignore_attribute_order=False, ignore_empty_rows=True,
validate=True):
""" Instantiate a list of objects from data in a table in a file
- Read upRead up
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 write_model
has a Cognitive Complexity of 94 (exceeds 5 allowed). Consider refactoring. Open
def write_model(self, writer, model, objects, schema_name, date, doc_metadata, doc_metadata_model, model_metadata, sheet_models,
include_all_attributes=True, encoded=None, write_empty_models=True, write_empty_cols=True,
extra_entries=0, protected=True):
""" Write a list of model objects to a file
- Read upRead up
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 link_model
has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring. Open
def link_model(self, model, attributes, data, objects, objects_by_primary_attribute, decoded=None):
""" Construct object graph
Args:
model (:obj:`Model`): an :obj:`obj_tables.core.Model`
- Read upRead up
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 read_sheet
has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring. Open
def read_sheet(self, model, reader, sheet_name, num_row_heading_columns=0, num_column_heading_rows=0,
ignore_empty_rows=False, ignore_empty_cols=False):
""" Read worksheet or file into a two-dimensional list
Args:
- Read upRead up
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 run
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
def run(self, path, objects, schema_name=None, doc_metadata=None, model_metadata=None,
models=None, get_related=True, include_all_attributes=True,
validate=True, title=None, description=None, keywords=None, version=None, language=None, creator=None,
write_toc=False, write_schema=False, write_empty_models=True, write_empty_cols=True,
extra_entries=0, group_objects_by_model=True,
- Read upRead up
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 run
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
def run(self, path, objects, schema_name=None, doc_metadata=None, model_metadata=None,
models=None, get_related=True, include_all_attributes=True, validate=True,
title=None, description=None, keywords=None, version=None, language=None, creator=None,
write_toc=True, write_schema=False, write_empty_models=True, write_empty_cols=True,
extra_entries=0, group_objects_by_model=True, data_repo_metadata=False, schema_package=None,
- Read upRead up
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 run
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def run(self, path, schema_name=None, models=None,
allow_multiple_sheets_per_model=False,
ignore_missing_models=False, ignore_extra_models=False,
ignore_sheet_order=False,
include_all_attributes=True, ignore_missing_attributes=False, ignore_extra_attributes=False,
- Read upRead up
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 run
has 24 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, objects, schema_name=None, doc_metadata=None, model_metadata=None, models=None,
Function run
has 24 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, objects, schema_name=None, doc_metadata=None, model_metadata=None,
Function run
has 24 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, objects, schema_name=None, doc_metadata=None, model_metadata=None,
Function run
has 24 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, objects, schema_name=None, doc_metadata=None, model_metadata=None,
Function run
has 24 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, objects, schema_name=None, doc_metadata=None, model_metadata=None,
Function read_worksheet_metadata
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def read_worksheet_metadata(cls, sheet_name, rows):
""" Read worksheet metadata
Args:
sheet_name (:obj:`str`): sheet name
- Read upRead up
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 write_sheet
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def write_sheet(self, writer, model, data, headings, metadata_headings, validation,
extra_entries=0, merge_ranges=None, protected=True):
""" Write data to sheet
Args:
- Read upRead up
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 write_schema
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def write_schema(self, writer, models, name, date, doc_metadata, protected=True):
""" Write a worksheet with a schema
Args:
writer (:obj:`wc_utils.workbook.io.Writer`): io writer
- Read upRead up
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 run
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def run(self, path, objects, schema_name=None, doc_metadata=None, model_metadata=None,
models=None, get_related=True, include_all_attributes=True, validate=True,
title=None, description=None, keywords=None, version=None, language=None, creator=None,
write_toc=True, write_schema=False, write_empty_models=True, write_empty_cols=True,
extra_entries=0, group_objects_by_model=True, data_repo_metadata=False, schema_package=None,
- Read upRead up
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_ordered_attributes
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def get_ordered_attributes(cls, include_all_attributes=True):
""" Get the attributes for a class in the order that they should be printed
Args:
cls (:obj:`type`): Model type (subclass of :obj:`Model`)
- Read upRead up
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
Consider simplifying this complex logical expression. Open
if not row or all(cell in ['', None] for cell in row):
rows.remove(row)
elif row and isinstance(row[0], str) and \
row[0].startswith('%/') and row[0].endswith('/%') and \
not any(row[1:]):
Function create_template
has 16 arguments (exceeds 4 allowed). Consider refactoring. Open
def create_template(path, schema_name, models, title=None, description=None, keywords=None,
Function write_model
has 15 arguments (exceeds 4 allowed). Consider refactoring. Open
def write_model(self, writer, model, objects, schema_name, date, doc_metadata, doc_metadata_model, model_metadata, sheet_models,
Function run
has 14 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, schema_name=None, models=None,
Function get_fields
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def get_fields(cls, schema_name, date, doc_metadata, doc_metadata_model, model_metadata, include_all_attributes=True, sheet_models=None):
""" Get the attributes, headings, and validation for a worksheet
Args:
cls (:obj:`type`): Model type (subclass of :obj:`Model`)
- Read upRead up
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 run
has 14 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, schema_name=None, models=None,
Function run
has 14 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, schema_name=None, models=None,
Function convert
has 14 arguments (exceeds 4 allowed). Consider refactoring. Open
def convert(source, destination, schema_name=None, models=None,
Function run
has 14 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, schema_name=None, models=None,
Function run
has 14 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, path, schema_name=None, models=None,
Function write_sheet
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def write_sheet(self, writer, model, data, headings, metadata_headings, validation,
extra_entries=0, merge_ranges=None, protected=False):
""" Write data to sheet
Args:
- Read upRead up
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 run
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def run(self, path, schema_name=None, models=None,
allow_multiple_sheets_per_model=False,
ignore_missing_models=False, ignore_extra_models=False,
ignore_sheet_order=False,
include_all_attributes=True, ignore_missing_attributes=False, ignore_extra_attributes=False,
- Read upRead up
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 run
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run(self, path, schema_name=None, models=None,
allow_multiple_sheets_per_model=False,
ignore_missing_models=False, ignore_extra_models=False,
ignore_sheet_order=False,
include_all_attributes=True, ignore_missing_attributes=False, ignore_extra_attributes=False,
Function get_fields
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_fields(cls, schema_name, date, doc_metadata, doc_metadata_model, model_metadata, include_all_attributes=True, sheet_models=None):
""" Get the attributes, headings, and validation for a worksheet
Args:
cls (:obj:`type`): Model type (subclass of :obj:`Model`)
Function make_metadata_objects
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def make_metadata_objects(self, data_repo_metadata, path, schema_package):
""" Make models that store Git repository metadata
Metadata models can only be created from suitable Git repos.
Failures to obtain metadata are reported as warnings that do not interfeer with writing
- Read upRead up
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 read_model
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
def read_model(self, reader, sheet_name, schema_name, model, include_all_attributes=True,
Function write_toc
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def write_toc(self, writer, models, schema_name, date, doc_metadata, grouped_objects, write_schema=False, protected=True):
""" Write a worksheet with a table of contents
Args:
writer (:obj:`wc_utils.workbook.io.Writer`): io writer
- Read upRead up
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 write_sheet
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
def write_sheet(self, writer, model, data, headings, metadata_headings, validation,
Function write_sheet
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
def write_sheet(self, writer, model, data, headings, metadata_headings, validation,
Function run
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run(self, path, objects, schema_name=None, doc_metadata=None, model_metadata=None,
models=None, get_related=True, include_all_attributes=True, validate=True,
title=None, description=None, keywords=None, version=None, language=None, creator=None,
write_toc=True, write_schema=False, write_empty_models=True, write_empty_cols=True,
extra_entries=0, group_objects_by_model=True, data_repo_metadata=False, schema_package=None,
Function write_toc
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def write_toc(self, writer, models, schema_name, date, doc_metadata, grouped_objects, write_schema=False, protected=True):
Function get_fields
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def get_fields(cls, schema_name, date, doc_metadata, doc_metadata_model, model_metadata, include_all_attributes=True, sheet_models=None):
Function read_sheet
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def read_sheet(self, model, reader, sheet_name, num_row_heading_columns=0, num_column_heading_rows=0,
Function run
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def run(self, objects, schema_name=None, models=None, get_related=True,
Avoid deeply nested control flow statements. Open
if same_val:
for sub_attr in attr.related_class.Meta.attributes.values():
sub_val = getattr(val, sub_attr.name)
if isinstance(sub_val, list):
setattr(val, sub_attr.name, [])
Function get_model_sheet_name
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_model_sheet_name(cls, sheet_names, model):
""" Get the name of the worksheet/file which corresponds to a model
Args:
sheet_names (:obj:`list` of :obj:`str`): names of the sheets in the workbook/files
- Read upRead up
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 deeply nested control flow statements. Open
if merged_model_metadata[model][key] != val:
errors.append('Attribute "{}" for model "{}" is not consistent'.format(
key, model.__name__, ))
else:
Avoid deeply nested control flow statements. Open
if deserialize_error:
deserialize_error.set_location_and_value(utils.source_report(obj, sub_attr.name),
attr_value)
obj_errors.append(deserialize_error)
if validation_error:
Avoid deeply nested control flow statements. Open
if attr.related_class not in objects_by_primary_attribute:
objects_by_primary_attribute[attr.related_class] = {}
serialized_val = val.serialize()
Avoid deeply nested control flow statements. Open
if validation_error:
validation_error.set_location_and_value(utils.source_report(obj, sub_attr.name),
attr_value)
obj_errors.append(validation_error)
setattr(obj, sub_attr.name, value)
Avoid deeply nested control flow statements. Open
if is_col_empty:
row.pop(i_col)
Avoid deeply nested control flow statements. Open
if not sub_obj:
sub_obj = group_attr.related_class()
setattr(obj, group_attr.name, sub_obj)
setattr(sub_obj, sub_attr.name, value)
Avoid deeply nested control flow statements. Open
for sub_attr in sub_attrs:
if val:
sub_val = getattr(val, sub_attr.name)
if isinstance(sub_attr, RelatedAttribute):
obj_data.append(sub_attr.serialize(sub_val, encoded=encoded))
Avoid deeply nested control flow statements. Open
if not line.startswith('!!!'):
out_file.write(line)
if i_path < len(all_tmp_paths) - 1:
Function write_schema
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def write_schema(self, writer, models, name, date, doc_metadata, protected=True):
Function link_model
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def link_model(self, model, attributes, data, objects, objects_by_primary_attribute, decoded=None):
Avoid too many return
statements within this function. Open
return (sub_attrs, data, errors, objects)
Function parse_worksheet_heading_metadata
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def parse_worksheet_heading_metadata(cls, heading, sheet_name=None):
""" Parse key-value pairs of metadata from heading
Args:
heading (:obj:`str`): heading with key-value pairs of metadata
- Read upRead up
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"