Skip to content

Commit

Permalink
Merge pull request #2057 from haxtibal/tdmg/fix_saving_date
Browse files Browse the repository at this point in the history
Don't discard date on save
  • Loading branch information
stanislaw authored Jan 15, 2025
2 parents 55dbb3f + 7f39176 commit 59961fd
Show file tree
Hide file tree
Showing 35 changed files with 150 additions and 147 deletions.
2 changes: 1 addition & 1 deletion requirements.check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ toml

# Lint
mypy>=0.910
ruff
ruff>=0.9

# Unit tests
pytest>=6.2.2
Expand Down
8 changes: 8 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 2 additions & 2 deletions strictdoc/backend/reqif/reqif_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/backend/sdoc/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 12 additions & 12 deletions strictdoc/backend/sdoc/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/backend/sdoc/models/object_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/backend/sdoc/models/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/backend/sdoc/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 8 additions & 3 deletions strictdoc/backend/sdoc/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def write_with_fragments(
output += f"VERSION: {version}"
output += "\n"

date = document_config.date
if date is not None:
output += f"DATE: {date}"
output += "\n"

classification = document_config.classification
if classification is not None:
output += f"CLASSIFICATION: {classification}"
Expand Down Expand Up @@ -256,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 = ""
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/backend/sdoc_source_code/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/core/actions/export_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/core/asset_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/core/document_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions strictdoc/core/document_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/core/graph/one_to_one_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/core/project_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions strictdoc/core/traceability_index_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions strictdoc/export/html/form_objects/form_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions strictdoc/export/html/generators/source_file_view_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def get_pygmented_source_lines(
start_pattern = '<div class="highlight"><pre>'
end_pattern = "</pre></div>\n"
assert pygmented_source_file_content.startswith(start_pattern)
assert pygmented_source_file_content.endswith(
end_pattern
), f"{pygmented_source_file_content}"
assert pygmented_source_file_content.endswith(end_pattern), (
f"{pygmented_source_file_content}"
)

slice_start = len(start_pattern)
slice_end = len(pygmented_source_file_content) - len(end_pattern)
Expand All @@ -213,9 +213,9 @@ def get_pygmented_source_lines(

if pygmented_source_file_lines[-1] == "":
pygmented_source_file_lines.pop()
assert (
"###" in pygmented_source_file_lines[-1]
), "Expected marker to be in place."
assert "###" in pygmented_source_file_lines[-1], (
"Expected marker to be in place."
)
# Pop ###, pop "\n"
pygmented_source_file_lines.pop()
if pygmented_source_file_lines[-1] == "":
Expand Down
6 changes: 1 addition & 5 deletions strictdoc/export/html/renderers/link_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,7 @@ def render_source_file_link(
document: SDocDocument = document_or_none
path_prefix = document.meta.get_root_path_prefix()
source_file_link = (
f"{path_prefix}"
"/"
f"_source_files"
"/"
f"{requirement_source_path}.html"
f"{path_prefix}/_source_files/{requirement_source_path}.html"
)
return source_file_link

Expand Down
6 changes: 3 additions & 3 deletions strictdoc/export/spdx/spdx_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ def export_tree(
if node.reserved_uid is None:
continue

assert (
node.reserved_title is not None
), "The current implementation only supports requirements with a title."
assert node.reserved_title is not None, (
"The current implementation only supports requirements with a title."
)

"""
Create SPDX Snippet from SDoc Requirement.
Expand Down
Loading

0 comments on commit 59961fd

Please sign in to comment.