Skip to content

Commit a3b7454

Browse files
committed
cargo fmt
1 parent e14ea7f commit a3b7454

File tree

7 files changed

+85
-49
lines changed

7 files changed

+85
-49
lines changed

cli/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ fn main() -> Result<()> {
157157
} else {
158158
// if the command is NOT init and the .ontoenv directory doesn't exist, raise an error
159159
let path = current_dir()?;
160-
if let Commands::Init { .. } = cmd.command && !path.exists() {
160+
if let Commands::Init { .. } = cmd.command
161+
&& !path.exists()
162+
{
161163
return Err(anyhow::anyhow!(
162164
"OntoEnv not found. Run `ontoenv init` to create a new OntoEnv."
163165
));

lib/src/api.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::config::Config;
2-
use std::path::Path;
3-
use petgraph::visit::EdgeRef;
42
use crate::doctor::{Doctor, DuplicateOntology, OntologyDeclaration};
53
use crate::environment::Environment;
64
use crate::transform;
75
use crate::{EnvironmentStatus, FailedImport};
86
use chrono::prelude::*;
9-
use oxigraph::model::{Dataset, NamedNode, NamedNodeRef, SubjectRef, Graph};
7+
use oxigraph::model::{Dataset, Graph, NamedNode, NamedNodeRef, SubjectRef};
8+
use petgraph::visit::EdgeRef;
109
use std::io::{BufReader, Write};
10+
use std::path::Path;
1111
use std::path::PathBuf;
1212

1313
use crate::io::GraphIO;
@@ -146,12 +146,12 @@ impl OntoEnv {
146146
}
147147
env.locations = locations;
148148

149-
// Initialize the IO to the persistent graph type. We know that it exists because we
149+
// Initialize the IO to the persistent graph type. We know that it exists because we
150150
// are loading from a directory
151151
let mut io: Box<dyn GraphIO> = Box::new(crate::io::PersistentGraphIO::new(
152-
ontoenv_dir.into(),
153-
config.offline,
154-
config.strict,
152+
ontoenv_dir.into(),
153+
config.offline,
154+
config.strict,
155155
)?);
156156

157157
// copy the graphs from the persistent store to the memory store if we are a 'temporary'
@@ -619,7 +619,10 @@ impl OntoEnv {
619619
.node_indices()
620620
.find(|i| self.dependency_graph[*i] == *node.id())
621621
.ok_or(anyhow::anyhow!("Node not found"))?;
622-
for edge in self.dependency_graph.edges_directed(index, petgraph::Direction::Incoming) {
622+
for edge in self
623+
.dependency_graph
624+
.edges_directed(index, petgraph::Direction::Incoming)
625+
{
623626
let dependent = self.dependency_graph[edge.source()].clone();
624627
dependents.push(dependent);
625628
}

lib/src/errors.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ pub struct OfflineRetrievalError {
99

1010
impl fmt::Display for OfflineRetrievalError {
1111
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12-
write!(f, "OFFLINE enabled: Failed to fetch ontology from {}", self.file)
12+
write!(
13+
f,
14+
"OFFLINE enabled: Failed to fetch ontology from {}",
15+
self.file
16+
)
1317
}
1418
}
1519

lib/src/io.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::ontology::{GraphIdentifier, Ontology, OntologyLocation};
21
use crate::errors::OfflineRetrievalError;
2+
use crate::ontology::{GraphIdentifier, Ontology, OntologyLocation};
33
use crate::util::read_format;
4-
use anyhow::{anyhow, Result, Error};
4+
use anyhow::{anyhow, Error, Result};
55
use chrono::prelude::*;
66
use log::{debug, error};
77
use oxigraph::io::{RdfFormat, RdfParser};
@@ -125,7 +125,11 @@ pub trait GraphIO: Send + Sync {
125125
.send()?;
126126
if !resp.status().is_success() {
127127
error!("Failed to fetch ontology from {} ({})", file, resp.status());
128-
return Err(anyhow::anyhow!("Failed to fetch ontology from {} ({})", file, resp.status()));
128+
return Err(anyhow::anyhow!(
129+
"Failed to fetch ontology from {} ({})",
130+
file,
131+
resp.status()
132+
));
129133
}
130134
let content_type = resp.headers().get("Content-Type");
131135
let content_type = content_type.and_then(|ct| ct.to_str().ok());
@@ -171,7 +175,9 @@ impl GraphIO for PersistentGraphIO {
171175
}
172176

173177
fn flush(&mut self) -> Result<()> {
174-
self.store.flush().map_err(|e| anyhow!("Failed to flush store: {}", e))
178+
self.store
179+
.flush()
180+
.map_err(|e| anyhow!("Failed to flush store: {}", e))
175181
}
176182

177183
fn size(&self) -> Result<StoreStats> {
@@ -207,13 +213,13 @@ impl GraphIO for PersistentGraphIO {
207213
fn add(&mut self, location: OntologyLocation, overwrite: bool) -> Result<Ontology> {
208214
let graph = match location {
209215
OntologyLocation::File(ref path) => self.read_file(&path)?,
210-
OntologyLocation::Url(ref url) => if self.offline {
211-
return Err(Error::new(OfflineRetrievalError {
212-
file: url.clone(),
213-
}))
214-
} else {
215-
self.read_url(&url)?
216-
},
216+
OntologyLocation::Url(ref url) => {
217+
if self.offline {
218+
return Err(Error::new(OfflineRetrievalError { file: url.clone() }));
219+
} else {
220+
self.read_url(&url)?
221+
}
222+
}
217223
};
218224

219225
let ontology = Ontology::from_graph(&graph, location.clone(), self.strict)?;
@@ -286,7 +292,7 @@ impl GraphIO for MemoryGraphIO {
286292
None
287293
}
288294

289-
fn flush(&mut self) -> Result<()>{
295+
fn flush(&mut self) -> Result<()> {
290296
Ok(())
291297
}
292298

@@ -323,13 +329,13 @@ impl GraphIO for MemoryGraphIO {
323329
fn add(&mut self, location: OntologyLocation, overwrite: bool) -> Result<Ontology> {
324330
let graph = match location {
325331
OntologyLocation::File(ref path) => self.read_file(&path)?,
326-
OntologyLocation::Url(ref url) => if self.offline {
327-
return Err(Error::new(OfflineRetrievalError {
328-
file: url.clone(),
329-
}))
330-
} else {
331-
self.read_url(&url)?
332-
},
332+
OntologyLocation::Url(ref url) => {
333+
if self.offline {
334+
return Err(Error::new(OfflineRetrievalError { file: url.clone() }));
335+
} else {
336+
self.read_url(&url)?
337+
}
338+
}
333339
};
334340

335341
let ontology = Ontology::from_graph(&graph, location.clone(), self.strict)?;

lib/src/util.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use oxigraph::model::{GraphNameRef, Quad, Triple, TripleRef};
1212

1313
use std::io::BufReader;
1414

15-
use log::{debug, info, error};
15+
use log::{debug, error, info};
1616

1717
pub fn write_dataset_to_file(dataset: &Dataset, file: &str) -> Result<()> {
1818
info!(
@@ -107,7 +107,11 @@ pub fn read_url(file: &str) -> Result<OxigraphGraph> {
107107
.send()?;
108108
if !resp.status().is_success() {
109109
error!("Failed to fetch ontology from {} ({})", file, resp.status());
110-
return Err(anyhow::anyhow!("Failed to fetch ontology from {} ({})", file, resp.status()));
110+
return Err(anyhow::anyhow!(
111+
"Failed to fetch ontology from {} ({})",
112+
file,
113+
resp.status()
114+
));
111115
}
112116
let content_type = resp.headers().get("Content-Type");
113117
let content_type = content_type.and_then(|ct| ct.to_str().ok());

lib/tests/ontoenv_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
2+
use ontoenv::api::OntoEnv;
23
use ontoenv::config::{Config, HowCreated};
34
use ontoenv::ontology::OntologyLocation;
4-
use ontoenv::api::OntoEnv;
55
use oxigraph::model::NamedNodeRef;
66
use std::path::PathBuf;
77
use tempdir::TempDir;

python/src/lib.rs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ impl OntoEnv {
197197
.map_err(anyhow_to_pyerr)
198198
} else if let Some(c) = config {
199199
// If a config is provided, initialize a new OntoEnv
200-
OntoEnvRs::init(c.cfg, read_only)
201-
.map_err(anyhow_to_pyerr)
200+
OntoEnvRs::init(c.cfg, read_only).map_err(anyhow_to_pyerr)
202201
} else {
203202
// Return an error if neither a valid path nor a config is provided
204203
Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(
@@ -211,7 +210,9 @@ impl OntoEnv {
211210
env.update().map_err(anyhow_to_pyerr)?;
212211
env.save_to_directory().map_err(anyhow_to_pyerr)?;
213212

214-
Ok(OntoEnv { inner: inner.clone() })
213+
Ok(OntoEnv {
214+
inner: inner.clone(),
215+
})
215216
}
216217

217218
fn update(&self) -> PyResult<()> {
@@ -234,9 +235,7 @@ impl OntoEnv {
234235
let stats = env.stats().map_err(anyhow_to_pyerr)?;
235236
Ok(format!(
236237
"<OntoEnv: {} ontologies, {} graphs, {} triples>",
237-
stats.num_ontologies,
238-
stats.num_graphs,
239-
stats.num_triples,
238+
stats.num_ontologies, stats.num_graphs, stats.num_triples,
240239
))
241240
}
242241

@@ -253,8 +252,14 @@ impl OntoEnv {
253252
let rdflib = py.import("rdflib")?;
254253
let iri = NamedNode::new(uri)
255254
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string()))?;
256-
let graphid = env.resolve(ResolveTarget::Graph(iri.clone()).into())
257-
.ok_or_else(|| PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Failed to resolve graph for URI: {}", uri)))?;
255+
let graphid = env
256+
.resolve(ResolveTarget::Graph(iri.clone()).into())
257+
.ok_or_else(|| {
258+
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
259+
"Failed to resolve graph for URI: {}",
260+
uri
261+
))
262+
})?;
258263
let mut graph = env.get_graph(&graphid).map_err(anyhow_to_pyerr)?;
259264

260265
let uriref_constructor = rdflib.getattr("URIRef")?;
@@ -302,8 +307,14 @@ impl OntoEnv {
302307
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string()))?;
303308
let inner = self.inner.clone();
304309
let env = inner.lock().unwrap();
305-
let graphid = env.resolve(ResolveTarget::Graph(iri.clone()).into())
306-
.ok_or_else(|| PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Failed to resolve graph for URI: {}", uri)))?;
310+
let graphid = env
311+
.resolve(ResolveTarget::Graph(iri.clone()).into())
312+
.ok_or_else(|| {
313+
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
314+
"Failed to resolve graph for URI: {}",
315+
uri
316+
))
317+
})?;
307318
let ont = env.ontologies().get(&graphid).ok_or_else(|| {
308319
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Ontology {} not found", iri))
309320
})?;
@@ -331,7 +342,9 @@ impl OntoEnv {
331342
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string()))?;
332343
let inner = self.inner.clone();
333344
let env = inner.lock().unwrap();
334-
let graphid = env.resolve(ResolveTarget::Graph(iri.clone()).into()).unwrap();
345+
let graphid = env
346+
.resolve(ResolveTarget::Graph(iri.clone()).into())
347+
.unwrap();
335348
let ont = env.ontologies().get(&graphid).ok_or_else(|| {
336349
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Ontology {} not found", iri))
337350
})?;
@@ -460,12 +473,16 @@ impl OntoEnv {
460473
let graph = {
461474
let inner = self.inner.clone();
462475
let env = inner.lock().unwrap();
463-
let graphid = env.resolve(ResolveTarget::Graph(iri).into())
464-
.ok_or_else(|| PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Failed to resolve graph for URI: {}", uri)))?;
476+
let graphid = env
477+
.resolve(ResolveTarget::Graph(iri).into())
478+
.ok_or_else(|| {
479+
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
480+
"Failed to resolve graph for URI: {}",
481+
uri
482+
))
483+
})?;
465484
println!("graphid: {:?}", graphid);
466-
let graph = env
467-
.get_graph(&graphid)
468-
.map_err(anyhow_to_pyerr)?;
485+
let graph = env.get_graph(&graphid).map_err(anyhow_to_pyerr)?;
469486
graph
470487
};
471488
let res = rdflib.getattr("Graph")?.call0()?;
@@ -522,7 +539,7 @@ impl OntoEnv {
522539
Ok(env.store_path().unwrap().to_string_lossy().to_string())
523540
}
524541

525-
pub fn flush(&mut self, py: Python<'_> ) -> PyResult<()> {
542+
pub fn flush(&mut self, py: Python<'_>) -> PyResult<()> {
526543
py.allow_threads(|| {
527544
let inner = self.inner.clone();
528545
let mut env = inner.lock().unwrap();

0 commit comments

Comments
 (0)