Skip to content

Commit

Permalink
add --recreate flag for 0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Apr 28, 2024
1 parent ffebc20 commit 2988597
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [
resolver = "2"

[workspace.package]
version = "0.1.4"
version = "0.1.5"
authors = ["Gabe Fierro <gtfierro@mines.edu>"]
license = "BSD-3-Clause"
edition = "2021"
Expand Down
5 changes: 4 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ enum Commands {
/// Glob patterns for which files to exclude, defaults to []
#[clap(long, short, num_args = 1..)]
excludes: Vec<String>,
#[clap(long, short, default_value = "false")]
recreate: bool,
},
/// Update the ontology environment
Refresh,
Expand Down Expand Up @@ -110,6 +112,7 @@ fn main() -> Result<()> {
offline,
includes,
excludes,
recreate,
} => {
// if search_directories is empty, use the current directory
let config = Config::new(
Expand All @@ -122,7 +125,7 @@ fn main() -> Result<()> {
offline,
policy,
)?;
let mut env = OntoEnv::new(config)?;
let mut env = OntoEnv::new(config, recreate)?;
env.update()?;
env.save_to_directory()?;
}
Expand Down
11 changes: 10 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,19 @@ pub struct OntoEnv {
// probably need some graph "identifier" that incorporates location and version..

impl OntoEnv {
pub fn new(config: Config) -> Result<Self> {
pub fn new(config: Config, recreate: bool) -> Result<Self> {
// create the config.root/.ontoenv directory so it exists before the store
// is created
let ontoenv_dir = config.root.join(".ontoenv");

// if recreate is False, raise an error if the directory already exists
if ontoenv_dir.exists() && !recreate {
return Err(anyhow::anyhow!(
"OntoEnv directory already exists: {:?}. Run 'refresh' or use the --recreate flag to recreate the environment.",
ontoenv_dir
));
}

std::fs::create_dir_all(&ontoenv_dir)?;

// create the store in the root/.ontoenv/store.db directory
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ features = ["pyo3/extension-module"]

[tool.poetry]
name = "ontoenv"
version = "0.1.4"
version = "0.1.5"
description = "Python bindings for the OntoEnv Rust library. Manages ontology-based environments for building knowledge graphs."
license = "bsd-3-clause"
authors = ["Gabe Fierro <gtfierro@mines.edu>"]
Expand Down
7 changes: 4 additions & 3 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ struct OntoEnv {
#[pymethods]
impl OntoEnv {
#[new]
#[pyo3(signature = (config=None, path=Path::new(".").to_owned()))]
#[pyo3(signature = (config=None, path=Path::new(".").to_owned(), recreate=false))]
fn new(
_py: Python,
config: Option<&Bound<'_, Config>>,
path: Option<PathBuf>,
recreate: bool,
) -> PyResult<Self> {
// wrap env_logger::init() in a Once to ensure it's only called once. This can
// happen if a user script creates multiple OntoEnv instances
Expand All @@ -191,13 +192,13 @@ impl OntoEnv {
} else {
println!("Creating new OntoEnv");
OntoEnv {
inner: ontoenvrs::OntoEnv::new(config.unwrap().borrow().cfg.clone())
inner: ontoenvrs::OntoEnv::new(config.unwrap().borrow().cfg.clone(), recreate)
.map_err(anyhow_to_pyerr)?,
}
}
} else {
OntoEnv {
inner: ontoenvrs::OntoEnv::new(config.unwrap().borrow().cfg.clone())
inner: ontoenvrs::OntoEnv::new(config.unwrap().borrow().cfg.clone(), recreate)
.map_err(anyhow_to_pyerr)?,
}
};
Expand Down

0 comments on commit 2988597

Please sign in to comment.