diff --git a/python/origen_metal/origen_metal/framework/__init__.py b/python/origen_metal/origen_metal/framework/__init__.py index fc1e7885..f6ceb5c7 100644 --- a/python/origen_metal/origen_metal/framework/__init__.py +++ b/python/origen_metal/origen_metal/framework/__init__.py @@ -1,5 +1,5 @@ """ -This module provides APIs that are closely related to creating feature for an application framework +This module provides APIs that are closely related to creating features for an application framework like Origen, e.g. a logging system. They are generic enough to allow you to use them to create a similar feature in your own diff --git a/python/origen_metal/origen_metal/utils/__init__.py b/python/origen_metal/origen_metal/utils/__init__.py index e69de29b..03f114ab 100644 --- a/python/origen_metal/origen_metal/utils/__init__.py +++ b/python/origen_metal/origen_metal/utils/__init__.py @@ -0,0 +1,4 @@ +""" +This module contains low-level APIs that are very generic and could be used in many +different applications. +""" \ No newline at end of file diff --git a/python/origen_metal/origen_metal/utils/differ.py b/python/origen_metal/origen_metal/utils/differ.py index e31e94c7..11958f30 100644 --- a/python/origen_metal/origen_metal/utils/differ.py +++ b/python/origen_metal/origen_metal/utils/differ.py @@ -5,7 +5,7 @@ def has_diffs( file_a: str, file_b: str, ignore_comments: Optional[List[str]] = None, - ignore_block: Optional[List[Tuple[str, str]]] = None, + ignore_blocks: Optional[List[Tuple[str, str]]] = None, ignore_blank_lines: bool = True, ) -> bool: """ @@ -16,8 +16,9 @@ def has_diffs( not result in a diff being reported if they are otherwise the same. Differences in comments can be ignored by specifying the comment char(s) to be used, - and also start and end sequences for C-style block comments - + and blocks of content can be ignored (e.g. C-style block comments) by specifying start + and end characters. + # Examples ```python @@ -25,7 +26,13 @@ def has_diffs( has_diffs("file_a.py", "file_b.py", ignore_comments=["#"]) # Ignore C++ style comments, including blocks - has_diffs("file_a.cpp", "file_b.cpp", ignore_comments=["//"], ignore_block=[("/*", "*/")]) + has_diffs("file_a.cpp", "file_b.cpp", ignore_comments=["//"], ignore_blocks=[("/*", "*/")]) + + # Multiple entries can be given to both the ignore_comments and ignore_blocks arguments + has_diffs("file_a.cpp", + "file_b.cpp", + ignore_comments=["//", "#"], + ignore_blocks=[("/*", "*/"), ("{{", "}}")]) ``` """ ... diff --git a/python/origen_metal/tests/test_differ.py b/python/origen_metal/tests/test_differ.py index 92d50cf9..c3e5f7a4 100644 --- a/python/origen_metal/tests/test_differ.py +++ b/python/origen_metal/tests/test_differ.py @@ -13,10 +13,10 @@ def test_basic_operation(): os.close(fb) assert (has_diffs(file_a, file_b)) - assert (not has_diffs(file_a, file_b, ignore_comments="//")) + assert (not has_diffs(file_a, file_b, ignore_comments=["//"])) assert (has_diffs(file_a, file_b, - ignore_comments="//", + ignore_comments=["//"], ignore_blank_lines=False)) @@ -40,7 +40,7 @@ def test_basic_suspend_works(): assert (has_diffs(file_a, file_b)) assert (not has_diffs( - file_a, file_b, suspend_on="", resume_on="")) + file_a, file_b, ignore_blocks=[("", "")])) def test_pre_suspend_works(): @@ -62,8 +62,7 @@ def test_pre_suspend_works(): os.close(fb) assert (has_diffs(file_a, file_b)) - assert (has_diffs(file_a, file_b, suspend_on="", - resume_on="")) + assert (has_diffs(file_a, file_b, ignore_blocks=[("", "")])) def test_post_suspend_works(): @@ -85,8 +84,7 @@ def test_post_suspend_works(): os.close(fb) assert (has_diffs(file_a, file_b)) - assert (has_diffs(file_a, file_b, suspend_on="", - resume_on="")) + assert (has_diffs(file_a, file_b, ignore_blocks=[("", "")])) def test_blank_lines_works(): @@ -124,4 +122,4 @@ def test_c_style_comments(): This part is the same""") assert (has_diffs(file_a, file_b)) - assert (not has_diffs(file_a, file_b, suspend_on="/*", resume_on="*/")) + assert (not has_diffs(file_a, file_b, ignore_blocks=[("/*", "*/")])) diff --git a/rust/origen/Cargo.lock b/rust/origen/Cargo.lock index 5609e119..69d7b143 100644 --- a/rust/origen/Cargo.lock +++ b/rust/origen/Cargo.lock @@ -2435,7 +2435,7 @@ dependencies = [ [[package]] name = "origen_metal" -version = "0.3.0" +version = "0.4.0" dependencies = [ "built", "lazy_static 1.4.0", diff --git a/rust/pyapi/Cargo.lock b/rust/pyapi/Cargo.lock index 6b495bdf..e3539fd8 100644 --- a/rust/pyapi/Cargo.lock +++ b/rust/pyapi/Cargo.lock @@ -2143,7 +2143,7 @@ dependencies = [ [[package]] name = "origen_metal" -version = "0.3.0" +version = "0.4.0" dependencies = [ "built", "lazy_static 1.4.0", @@ -2492,7 +2492,7 @@ dependencies = [ [[package]] name = "pyapi_metal" -version = "0.3.0" +version = "0.4.0" dependencies = [ "built", "curl-sys", diff --git a/rust/pyapi_metal/src/utils/differ.rs b/rust/pyapi_metal/src/utils/differ.rs index 87488dfd..025ead9e 100644 --- a/rust/pyapi_metal/src/utils/differ.rs +++ b/rust/pyapi_metal/src/utils/differ.rs @@ -5,14 +5,14 @@ use std::path::Path; #[pyfunction( ignore_comments = "None", - ignore_block = "None", + ignore_blocks = "None", ignore_blank_lines = "true" )] pub fn has_diffs( file_a: &str, file_b: &str, ignore_comments: Option>, - ignore_block: Option>>, + ignore_blocks: Option>>, ignore_blank_lines: bool, ) -> PyResult { let mut differ = ASCIIDiffer::new(Path::new(file_a), Path::new(file_b)); @@ -22,9 +22,9 @@ pub fn has_diffs( differ.ignore_comments(&c)?; } } - if let Some(blocks) = ignore_block { + if let Some(blocks) = ignore_blocks { for b in blocks { - differ.suspend_on(&c)?; + differ.ignore_block(&b[0], &b[1])?; } } Ok(differ.has_diffs()?)