Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/origen_metal/origen_metal/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# This needs to be commented out to run pdoc, but is required for functionality
from ._origen_metal import *
Empty file.
Empty file.
33 changes: 33 additions & 0 deletions python/origen_metal/origen_metal/utils/differ/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from typing import Optional


def has_diffs(
file_a: str,
file_b: str,
ignore_comments: Optional[str] = None,
suspend_on: Optional[str] = None,
resume_on: Optional[str] = None,
ignore_blank_lines: bool = True,
) -> bool:
"""
This function compares the two ASCII files at the given paths and returns True if any
differences are found between them.

Blank lines will be ignored by default, so additional blank lines in one file will
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

# Examples

```python
# Ignore Python style comments
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="//", suspend_on="/*", resume_on="*/")

```
"""
...
6 changes: 3 additions & 3 deletions python/origen_metal/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion python/origen_metal/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "origen_metal"
version = "0.2.0"
version = "0.3.0"
description = "Bare metal APIs for the Origen SDK"
authors = ["Origen-SDK"]

Expand All @@ -9,3 +9,5 @@ python = ">=3.6,<3.9"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
# Only works with 3.7 and above
#pdoc = "^7"
127 changes: 127 additions & 0 deletions python/origen_metal/tests/test_differ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from origen_metal.utils.differ import has_diffs
import tempfile
import os


def test_basic_operation():
fa, file_a = tempfile.mkstemp()
fb, file_b = tempfile.mkstemp()
os.write(fa, b"This part is the same // But this is different\n")
os.write(fb, b"This part is the same // But this is not\n")
os.write(fb, b"\n") # An extra blank line in file B
os.close(fa)
os.close(fb)

assert (has_diffs(file_a, file_b))
assert (not has_diffs(file_a, file_b, ignore_comments="//"))
assert (has_diffs(file_a,
file_b,
ignore_comments="//",
ignore_blank_lines=False))


def test_basic_suspend_works():
fa, file_a = tempfile.mkstemp()
fb, file_b = tempfile.mkstemp()
os.write(
fa, b"""This part is the same
until here<START> dfodisgsg
soemghow dosghsg
iewg<STOP>
and now we are back""")
os.write(
fb, b"""This part is the same
until here<START>
some diff
<STOP>
and now we are back""")
os.close(fa)
os.close(fb)

assert (has_diffs(file_a, file_b))
assert (not has_diffs(
file_a, file_b, suspend_on="<START>", resume_on="<STOP>"))


def test_pre_suspend_works():
fa, file_a = tempfile.mkstemp()
fb, file_b = tempfile.mkstemp()
os.write(
fa, b"""This part is the same
until here is a pre diff<START> dfodisgsg
soemghow dosghsg
iewg<STOP>
and now we are back""")
os.write(
fb, b"""This part is the same
until here<START>
some diff
<STOP>
and now we are back""")
os.close(fa)
os.close(fb)

assert (has_diffs(file_a, file_b))
assert (has_diffs(file_a, file_b, suspend_on="<START>",
resume_on="<STOP>"))


def test_post_suspend_works():
fa, file_a = tempfile.mkstemp()
fb, file_b = tempfile.mkstemp()
os.write(
fa, b"""This part is the same
until here is a pre diff<START> dfodisgsg
soemghow dosghsg
iewg<STOP>
and now we are back""")
os.write(
fb, b"""This part is the same
until here<START>
some diff
<STOP> here is a diff!
and now we are back""")
os.close(fa)
os.close(fb)

assert (has_diffs(file_a, file_b))
assert (has_diffs(file_a, file_b, suspend_on="<START>",
resume_on="<STOP>"))


def test_blank_lines_works():
fa, file_a = tempfile.mkstemp()
fb, file_b = tempfile.mkstemp()
os.write(
fa, b"""This part is the same
This part is the same
This part is the same""")
os.write(
fb, b"""This part is the same
This part is the same

This part is the same""")

assert (not has_diffs(file_a, file_b))
assert (has_diffs(file_a, file_b, ignore_blank_lines=False))


def test_c_style_comments():
fa, file_a = tempfile.mkstemp()
fb, file_b = tempfile.mkstemp()
os.write(
fa, b"""This part is the same
about to change /* jdhkjdghsg
dfdfsfsf ioihjsdgs sdfsdf */ and we're back
This part is the same
This part is the same""")
os.write(
fb, b"""This part is the same
about to change /*
dflslkj ebiuhw sdogih
dflslkj ebiuhw sdogih */ and we're back
This part is the same
This part is the same""")

assert (has_diffs(file_a, file_b))
assert (not has_diffs(file_a, file_b, suspend_on="/*", resume_on="*/"))
5 changes: 0 additions & 5 deletions python/origen_metal/tests/test_origen_metal.py

This file was deleted.

64 changes: 53 additions & 11 deletions rust/origen/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion rust/origen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ octocrab = "0.9.1"
futures = {version = "0.3.15", features = ["executor"]}
tokio = {version = "1.7", features = ["full"] }
reqwest = {version = "0.11.3", features = ["blocking", "json"]}
anyhow = "1"

[patch.crates-io]
keyring = { git = "https://github.com/hwchen/keyring-rs.git", rev = "a30e65f" }
Expand Down
1 change: 0 additions & 1 deletion rust/origen/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ tar = "0.4"
sha2 = "0.9"
base64-url = "1.4.6"
phf = { version = "0.8.0", features = ["macros"] }
anyhow = "1"

[build-dependencies]
walkdir = "2"
Expand Down
2 changes: 1 addition & 1 deletion rust/origen/cli/src/commands/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::CommandHelp;
use clap::{App, Arg, ArgMatches, SubCommand};
use origen::core::file_handler::File;
use origen_metal::utils::file::{symlink, cd};
use origen::utility::file_utils::with_dir;
use origen::utility::version::Version;
use origen::{Result, STATUS};
use origen_metal::utils::file::{cd, symlink};
use regex::Regex;
use sha2::{Digest, Sha256};
use std::path::Path;
Expand Down
4 changes: 2 additions & 2 deletions rust/origen/cli/src/commands/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::python::PYTHON_CONFIG;
use crate::Result;
use origen::core::term::*;
use origen::STATUS;
use origen_metal::utils::file::cd;
use std::env;
use std::io::stdout;
use std::io::Write;
use std::path::Path;
use std::process::Command;
use origen_metal::utils::file::cd;
use anyhow::Result;

pub fn run() -> Result<()> {
let orig_dir = env::current_dir().expect("Couldn't read the PWD");
Expand Down
2 changes: 1 addition & 1 deletion rust/origen/cli/src/commands/proj/bom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use super::group::{Group, TempGroup};
use super::package::Package;
use super::{error_and_exit, BOM_FILE};
use indexmap::IndexMap;
use origen_metal::utils::file::symlink;
use origen::utility::file_utils::with_dir;
use origen::Result;
use origen_metal::utils::file::symlink;
use std::path::{Path, PathBuf};
use std::{fmt, fs};

Expand Down
2 changes: 1 addition & 1 deletion rust/origen/cli/src/commands/proj/package.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::error_and_exit;
use flate2::read::GzDecoder;
use origen::revision_control::{Credentials, RevisionControl, RevisionControlAPI};
use origen_metal::utils::file::symlink;
use origen::utility::file_utils::{copy, copy_contents, mv};
use origen::Result;
use origen_metal::utils::file::symlink;
use std::fs::File;
use std::path::{Path, PathBuf};
use std::{fmt, fs};
Expand Down
Loading