Linted, formatted, and added hooks

This commit is contained in:
2024-05-08 17:23:29 +01:00
parent af8f631d9d
commit 005a38c8da
3 changed files with 14 additions and 10 deletions

View File

@@ -3,7 +3,7 @@ default_language_version:
repos: repos:
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4 rev: v0.4.3
hooks: hooks:
- id: ruff - id: ruff
types: [python] types: [python]
@@ -12,7 +12,7 @@ repos:
types: [python] types: [python]
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0 rev: v1.10.0
hooks: hooks:
- id: mypy - id: mypy
types: [python] types: [python]
@@ -24,6 +24,12 @@ repos:
- id: fmt - id: fmt
- id: cargo-check - id: cargo-check
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
- id: fmt
- repo: https://github.com/python-poetry/poetry - repo: https://github.com/python-poetry/poetry
rev: "1.8.0" rev: "1.8.0"
hooks: hooks:

View File

@@ -22,9 +22,7 @@ impl From<rust_fn::ReadError> for PyErr {
rust_fn::ReadError::ParseFloatError(e) => { rust_fn::ReadError::ParseFloatError(e) => {
PyErr::new::<exceptions::PyRuntimeError, _>(format!("{}", e)) PyErr::new::<exceptions::PyRuntimeError, _>(format!("{}", e))
} }
rust_fn::ReadError::MiscError(e) => { rust_fn::ReadError::MiscError(e) => PyErr::new::<exceptions::PyRuntimeError, _>(e),
PyErr::new::<exceptions::PyRuntimeError, _>(format!("{}", e))
}
} }
} }
} }

View File

@@ -36,8 +36,8 @@ pub fn read_layers(folder: &str) -> Result<Array2<f64>> {
let mut glob_iterator = glob(glob_string.as_str())? let mut glob_iterator = glob(glob_string.as_str())?
.collect::<std::result::Result<Vec<PathBuf>, glob::GlobError>>()?; .collect::<std::result::Result<Vec<PathBuf>, glob::GlobError>>()?;
glob_iterator.par_sort_unstable_by(|a, b| { glob_iterator.par_sort_unstable_by(|a, b| {
let az = get_z(&a).expect("Filename parsing failed."); let az = get_z(a).expect("Filename parsing failed.");
let bz = get_z(&b).expect("Filename parsing failed."); let bz = get_z(b).expect("Filename parsing failed.");
az.partial_cmp(&bz).expect("Filename sorting failed") az.partial_cmp(&bz).expect("Filename sorting failed")
}); });
let len: usize = glob_iterator.len(); let len: usize = glob_iterator.len();
@@ -168,7 +168,7 @@ pub fn read_file(filepath: PathBuf) -> Result<(Array2<f64>, f64, usize)> {
Ok((array_read, z, z_len)) Ok((array_read, z, z_len))
} }
pub fn get_z(filepath: &PathBuf) -> Result<f64> { pub fn get_z(filepath: &Path) -> Result<f64> {
Ok(filepath Ok(filepath
.file_stem() .file_stem()
.ok_or(ReadError::MiscError(format!( .ok_or(ReadError::MiscError(format!(
@@ -182,11 +182,11 @@ pub fn get_z(filepath: &PathBuf) -> Result<f64> {
.parse::<f64>()?) .parse::<f64>()?)
} }
pub fn correct_x(x: &mut f64) -> () { pub fn correct_x(x: &mut f64) {
*x = -((((*x + 16384.) * 0.009155273) - 87.) / 1.01); *x = -((((*x + 16384.) * 0.009155273) - 87.) / 1.01);
} }
pub fn correct_y(y: &mut f64) -> () { pub fn correct_y(y: &mut f64) {
*y = (((*y + 16384.) * 0.009155273) - 91.) / 1.02; *y = (((*y + 16384.) * 0.009155273) - 91.) / 1.02;
} }