diff --git a/requirements.check.txt b/requirements.check.txt index 6a9fe43dc..463b1c51f 100644 --- a/requirements.check.txt +++ b/requirements.check.txt @@ -2,7 +2,7 @@ toml # Lint mypy>=0.910 -ruff +ruff>=0.9 # Unit tests pytest>=6.2.2 diff --git a/ruff.toml b/ruff.toml index 7c4462856..87f58a7ac 100644 --- a/ruff.toml +++ b/ruff.toml @@ -88,8 +88,16 @@ ignore = [ # Avoid trying to fix flake8-bugbear (`B`) violations. unfixable = ["B"] +# Skip non UTF-8 test files +exclude = ["tests/**/invalid_file*"] + # B008 Do not perform function calls in argument defaults. # The call is performed only once at function definition time. [lint.per-file-ignores] "strictdoc/server/routers/main_router.py" = ["B008"] + +# Some of our helpers have deliberatly the name of a standard library module + +[lint.flake8-builtins] +builtins-allowed-modules = ["math", "pickle", "string"] diff --git a/strictdoc/backend/reqif/reqif_import.py b/strictdoc/backend/reqif/reqif_import.py index 2056ac77b..d1c82f29b 100644 --- a/strictdoc/backend/reqif/reqif_import.py +++ b/strictdoc/backend/reqif/reqif_import.py @@ -21,9 +21,9 @@ def import_from_file( ) -> List[SDocDocument]: converter = ReqIFImport.select_reqif_profile(import_config) - assert os.path.isfile( + assert os.path.isfile(import_config.input_path), ( import_config.input_path - ), import_config.input_path + ) if import_config.input_path.endswith(".reqifz"): reqifz_bundle: ReqIFZBundle = ReqIFZParser.parse( diff --git a/strictdoc/backend/sdoc/error_handling.py b/strictdoc/backend/sdoc/error_handling.py index 135ecdda9..f5bede24a 100644 --- a/strictdoc/backend/sdoc/error_handling.py +++ b/strictdoc/backend/sdoc/error_handling.py @@ -128,9 +128,9 @@ def wrong_field_order( problematic_field: SDocNodeField, path_to_sdoc_file: str, ): - assert isinstance( - problematic_field, SDocNodeField - ), f"{problematic_field}" + assert isinstance(problematic_field, SDocNodeField), ( + f"{problematic_field}" + ) requirement_dump = node.dump_fields_as_parsed() grammar_dump = document_grammar.dump_fields(node.node_type) return StrictDocSemanticError( diff --git a/strictdoc/backend/sdoc/models/node.py b/strictdoc/backend/sdoc/models/node.py index b7006f3ff..0de2bf85a 100644 --- a/strictdoc/backend/sdoc/models/node.py +++ b/strictdoc/backend/sdoc/models/node.py @@ -60,9 +60,9 @@ def create_from_string( multiline: bool, ) -> "SDocNodeField": assert isinstance(field_name, str) and len(field_name) > 0, field_name - assert ( - isinstance(field_value, str) and len(field_value) > 0 - ), field_value + assert isinstance(field_value, str) and len(field_value) > 0, ( + field_value + ) return SDocNodeField( parent=parent, @@ -223,9 +223,9 @@ def reserved_tags(self) -> Optional[List[str]]: field: SDocNodeField = self.ordered_fields_lookup[ RequirementFieldName.TAGS ][0] - assert ( - not field.is_multiline() - ), f"Field {RequirementFieldName.TAGS} must be a single-line field." + assert not field.is_multiline(), ( + f"Field {RequirementFieldName.TAGS} must be a single-line field." + ) tags = field.get_text_value().split(", ") return tags @@ -286,9 +286,9 @@ def document(self) -> SDocDocument: document: Optional[SDocDocument] = ( self.ng_document_reference.get_document() ) - assert ( - document is not None - ), "A valid requirement must always have a reference to the document." + assert document is not None, ( + "A valid requirement must always have a reference to the document." + ) return document def get_document(self) -> Optional[SDocDocument]: @@ -325,9 +325,9 @@ def parent_or_including_document(self) -> SDocDocument: document: Optional[SDocDocument] = ( self.ng_document_reference.get_document() ) - assert ( - document is not None - ), "A valid requirement must always have a reference to the document." + assert document is not None, ( + "A valid requirement must always have a reference to the document." + ) return document def document_is_included(self) -> bool: diff --git a/strictdoc/backend/sdoc/models/object_factory.py b/strictdoc/backend/sdoc/models/object_factory.py index d0ed1aa5e..67a00e44c 100644 --- a/strictdoc/backend/sdoc/models/object_factory.py +++ b/strictdoc/backend/sdoc/models/object_factory.py @@ -74,9 +74,9 @@ def create_requirement( ) ) if statement_multiline is not None: - assert isinstance( - statement_multiline, str - ), f"{statement_multiline}" + assert isinstance(statement_multiline, str), ( + f"{statement_multiline}" + ) fields.append( SDocNodeField.create_from_string( parent=None, diff --git a/strictdoc/backend/sdoc/models/section.py b/strictdoc/backend/sdoc/models/section.py index 9b35f2b5b..9f0007d23 100644 --- a/strictdoc/backend/sdoc/models/section.py +++ b/strictdoc/backend/sdoc/models/section.py @@ -110,9 +110,9 @@ def parent_or_including_document(self) -> SDocDocument: document: Optional[SDocDocument] = ( self.ng_document_reference.get_document() ) - assert ( - document is not None - ), "A valid requirement must always have a reference to the document." + assert document is not None, ( + "A valid requirement must always have a reference to the document." + ) return document def document_is_included(self): diff --git a/strictdoc/backend/sdoc/processor.py b/strictdoc/backend/sdoc/processor.py index cc5c7be7e..09fdacc5b 100644 --- a/strictdoc/backend/sdoc/processor.py +++ b/strictdoc/backend/sdoc/processor.py @@ -168,9 +168,9 @@ def process_section(self, section: SDocSection): ) def process_document_from_file(self, document_from_file: DocumentFromFile): - assert isinstance( - document_from_file, DocumentFromFile - ), document_from_file + assert isinstance(document_from_file, DocumentFromFile), ( + document_from_file + ) # Windows paths are backslashes, so using abspath in addition. resolved_path_to_fragment_file = os.path.abspath( diff --git a/strictdoc/backend/sdoc/writer.py b/strictdoc/backend/sdoc/writer.py index 817a815f4..fe840ee36 100644 --- a/strictdoc/backend/sdoc/writer.py +++ b/strictdoc/backend/sdoc/writer.py @@ -261,9 +261,9 @@ def _print_node( document_iterator: DocumentCachingIterator, convert_free_text_to_text: bool = False, ): - assert isinstance( - document_iterator, DocumentCachingIterator - ), document_iterator + assert isinstance(document_iterator, DocumentCachingIterator), ( + document_iterator + ) if isinstance(root_node, SDocDocument): output = "" diff --git a/strictdoc/backend/sdoc_source_code/reader.py b/strictdoc/backend/sdoc_source_code/reader.py index 3e7fb17e6..684a5c819 100644 --- a/strictdoc/backend/sdoc_source_code/reader.py +++ b/strictdoc/backend/sdoc_source_code/reader.py @@ -32,9 +32,9 @@ def __init__(self, lines_total): def req_processor(req: Req): - assert isinstance( - req, Req - ), f"Expected req to be Req, got: {req}, {type(req)}" + assert isinstance(req, Req), ( + f"Expected req to be Req, got: {req}, {type(req)}" + ) location = get_location(req) assert location req.ng_source_line = location["line"] diff --git a/strictdoc/core/actions/export_action.py b/strictdoc/core/actions/export_action.py index 2be4b0711..efb81776d 100644 --- a/strictdoc/core/actions/export_action.py +++ b/strictdoc/core/actions/export_action.py @@ -51,9 +51,9 @@ def build_index(self) -> None: @timing_decorator("Export SDoc") def export(self) -> None: - assert ( - self.traceability_index is not None - ), "The index must be built at this point." + assert self.traceability_index is not None, ( + "The index must be built at this point." + ) if ( "html" in self.project_config.export_formats or "html-standalone" in self.project_config.export_formats diff --git a/strictdoc/core/asset_manager.py b/strictdoc/core/asset_manager.py index 2bec3dbe5..f94457db4 100644 --- a/strictdoc/core/asset_manager.py +++ b/strictdoc/core/asset_manager.py @@ -11,9 +11,9 @@ class AssetDir: relative_path: SDocRelativePath def __post_init__(self): - assert isinstance( - self.relative_path, SDocRelativePath - ), self.relative_path + assert isinstance(self.relative_path, SDocRelativePath), ( + self.relative_path + ) class AssetManager: diff --git a/strictdoc/core/document_finder.py b/strictdoc/core/document_finder.py index a71bbbb0e..8390b7920 100644 --- a/strictdoc/core/document_finder.py +++ b/strictdoc/core/document_finder.py @@ -115,9 +115,9 @@ def _build_document_tree( doc_file: File for doc_file, file_tree_mount_folder, document in found_documents: - assert isinstance( - file_tree_mount_folder, str - ), file_tree_mount_folder + assert isinstance(file_tree_mount_folder, str), ( + file_tree_mount_folder + ) if isinstance(document, DocumentGrammar): map_grammars_by_filenames[doc_file.file_name] = document diff --git a/strictdoc/core/document_meta.py b/strictdoc/core/document_meta.py index 0de84f045..3607cb296 100644 --- a/strictdoc/core/document_meta.py +++ b/strictdoc/core/document_meta.py @@ -38,18 +38,18 @@ def __init__( output_document_dir_rel_path = "doc_project" ) """ - assert isinstance( - input_doc_rel_path, SDocRelativePath - ), input_doc_rel_path - assert isinstance( - input_doc_dir_rel_path, SDocRelativePath - ), input_doc_dir_rel_path - assert isinstance( - input_doc_assets_dir_rel_path, SDocRelativePath - ), input_doc_assets_dir_rel_path - assert isinstance( - output_document_dir_rel_path, SDocRelativePath - ), output_document_dir_rel_path + assert isinstance(input_doc_rel_path, SDocRelativePath), ( + input_doc_rel_path + ) + assert isinstance(input_doc_dir_rel_path, SDocRelativePath), ( + input_doc_dir_rel_path + ) + assert isinstance(input_doc_assets_dir_rel_path, SDocRelativePath), ( + input_doc_assets_dir_rel_path + ) + assert isinstance(output_document_dir_rel_path, SDocRelativePath), ( + output_document_dir_rel_path + ) self.level: int = level self.file_tree_mount_folder = file_tree_mount_folder diff --git a/strictdoc/core/graph/one_to_one_dictionary.py b/strictdoc/core/graph/one_to_one_dictionary.py index 36612b17a..2e8561841 100644 --- a/strictdoc/core/graph/one_to_one_dictionary.py +++ b/strictdoc/core/graph/one_to_one_dictionary.py @@ -34,9 +34,9 @@ def create_link( assert edge is None assert isinstance(lhs_node, self._lhs_type), (lhs_node, self._lhs_type) assert isinstance(rhs_node, self._rhs_type), (rhs_node, self._rhs_type) - assert ( - lhs_node not in self._dict - ), f"OneToOneDictionary: Cannot create a link because lhs_node already exists: {lhs_node}." + assert lhs_node not in self._dict, ( + f"OneToOneDictionary: Cannot create a link because lhs_node already exists: {lhs_node}." + ) self._dict[lhs_node] = rhs_node def create_link_weak(self, *, lhs_node: Any, rhs_node: Any): diff --git a/strictdoc/core/project_config.py b/strictdoc/core/project_config.py index e2905f32b..ae43e347e 100644 --- a/strictdoc/core/project_config.py +++ b/strictdoc/core/project_config.py @@ -586,9 +586,9 @@ def _load_from_dictionary( # FIXME reqif_import_markup = reqif_content.get("import_markup", None) if reqif_import_markup is not None: - assert ( - reqif_import_markup in SDocMarkup.ALL - ), reqif_import_markup + assert reqif_import_markup in SDocMarkup.ALL, ( + reqif_import_markup + ) return ProjectConfig( environment=environment, diff --git a/strictdoc/core/traceability_index_builder.py b/strictdoc/core/traceability_index_builder.py index 721e4672b..ebb93c9aa 100644 --- a/strictdoc/core/traceability_index_builder.py +++ b/strictdoc/core/traceability_index_builder.py @@ -710,9 +710,9 @@ def child_cycle_traverse_(node_id): for document_from_file_ in document_.fragments_from_files: traceability_index.contains_included_documents = True - assert isinstance( - document_from_file_, DocumentFromFile - ), document_from_file_ + assert isinstance(document_from_file_, DocumentFromFile), ( + document_from_file_ + ) assert ( document_from_file_.resolved_full_path_to_document_file diff --git a/strictdoc/export/html/form_objects/form_object.py b/strictdoc/export/html/form_objects/form_object.py index d8391124a..4732eaaa8 100644 --- a/strictdoc/export/html/form_objects/form_object.py +++ b/strictdoc/export/html/form_objects/form_object.py @@ -12,9 +12,9 @@ class RowWithReservedFieldFormObject: jinja_environment: JinjaEnvironment def __post_init__(self): - assert isinstance( - self.jinja_environment, JinjaEnvironment - ), self.jinja_environment + assert isinstance(self.jinja_environment, JinjaEnvironment), ( + self.jinja_environment + ) def render(self): rendered_template = self.jinja_environment.render_template_as_markup( @@ -35,9 +35,9 @@ class RowWithCustomFieldFormObject: def __post_init__(self): assert self.field is not None - assert isinstance( - self.jinja_environment, JinjaEnvironment - ), self.jinja_environment + assert isinstance(self.jinja_environment, JinjaEnvironment), ( + self.jinja_environment + ) def render(self): rendered_template = self.jinja_environment.render_template_as_markup( @@ -58,9 +58,9 @@ class RowWithRelationFormObject: def __post_init__(self): assert self.relation is not None - assert isinstance( - self.jinja_environment, JinjaEnvironment - ), self.jinja_environment + assert isinstance(self.jinja_environment, JinjaEnvironment), ( + self.jinja_environment + ) def render(self): rendered_template = self.jinja_environment.render_template_as_markup( diff --git a/strictdoc/export/html/form_objects/rows/row_with_grammar_element_form_object.py b/strictdoc/export/html/form_objects/rows/row_with_grammar_element_form_object.py index b8143ed9b..b1aefde89 100644 --- a/strictdoc/export/html/form_objects/rows/row_with_grammar_element_form_object.py +++ b/strictdoc/export/html/form_objects/rows/row_with_grammar_element_form_object.py @@ -13,9 +13,9 @@ class RowWithGrammarElementFormObject: def __post_init__(self): assert self.field is not None - assert isinstance( - self.jinja_environment, JinjaEnvironment - ), self.jinja_environment + assert isinstance(self.jinja_environment, JinjaEnvironment), ( + self.jinja_environment + ) def render(self): if self.field.is_new: diff --git a/strictdoc/export/html/generators/source_file_view_generator.py b/strictdoc/export/html/generators/source_file_view_generator.py index 88dd8caa3..5c899e6ec 100644 --- a/strictdoc/export/html/generators/source_file_view_generator.py +++ b/strictdoc/export/html/generators/source_file_view_generator.py @@ -196,9 +196,9 @@ def get_pygmented_source_lines( start_pattern = '
'
end_pattern = "