Skip to content

Commit

Permalink
Renaming explicit_git_mods to specified_mods and slightly reducin…
Browse files Browse the repository at this point in the history
…g the number of places I use the word "explicit"! (I never realized how big a part of my vocab it has become)
  • Loading branch information
luketpeterson committed Jun 6, 2024
1 parent 46f1df0 commit da74ea2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
18 changes: 9 additions & 9 deletions lib/src/metta/runner/builtin_mods/catalog_mods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ impl Grounded for CatalogListOp {
}

let mut found_one = false;
if cat_name == "all" || cat_name == "git-modules" {
if let Some(explicit_git_catalog) = &self.metta.environment().explicit_git_mods {
list_catalog(explicit_git_catalog);
if cat_name == "all" || cat_name == "specified-mods" {
if let Some(specified_mods) = &self.metta.environment().specified_mods {
list_catalog(specified_mods);
found_one = true;
}
}
Expand Down Expand Up @@ -187,9 +187,9 @@ impl Grounded for CatalogUpdateOp {
};

let mut found_one = false;
if cat_name == "all" || cat_name == "git-modules" {
if let Some(explicit_git_catalog) = &self.metta.environment().explicit_git_mods {
explicit_git_catalog.fetch_newest_for_all(UpdateMode::FetchLatest)?;
if cat_name == "all" || cat_name == "specified-mods" {
if let Some(specified_mods) = &self.metta.environment().specified_mods {
specified_mods.fetch_newest_for_all(UpdateMode::FetchLatest)?;
found_one = true;
}
}
Expand Down Expand Up @@ -253,9 +253,9 @@ impl Grounded for CatalogClearOp {
};

let mut found_one = false;
if cat_name == "all" || cat_name == "git-modules" {
if let Some(explicit_git_catalog) = &self.metta.environment().explicit_git_mods {
explicit_git_catalog.clear_all()?;
if cat_name == "all" || cat_name == "specified-mods" {
if let Some(specified_mods) = &self.metta.environment().specified_mods {
specified_mods.clear_all()?;
found_one = true;
}
}
Expand Down
16 changes: 8 additions & 8 deletions lib/src/metta/runner/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ pub struct Environment {
catalogs: Vec<Box<dyn ModuleCatalog>>,
#[cfg(feature = "pkg_mgmt")]
pub(crate) fs_mod_formats: Arc<Vec<Box<dyn FsModuleFormat>>>,
/// The store for modules loaded from git by explicit URL
/// The store for modules cached locally after loading from a specific location, for example, via git.
#[cfg(feature = "pkg_mgmt")]
pub(crate) explicit_git_mods: Option<LocalCatalog>,
pub(crate) specified_mods: Option<LocalCatalog>,
}

const DEFAULT_INIT_METTA: &[u8] = include_bytes!("init.default.metta");
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Environment {
#[cfg(feature = "pkg_mgmt")]
fs_mod_formats: Arc::new(vec![]),
#[cfg(feature = "pkg_mgmt")]
explicit_git_mods: None,
specified_mods: None,
}
}
}
Expand Down Expand Up @@ -362,11 +362,11 @@ impl EnvBuilder {
//If we have a caches dir to cache modules locally then register remote catalogs
if let Some(caches_dir) = &env.caches_dir {

//Setup the explicit_git_mods managed catalog to hold mods fetched by explicit URL
let mut explicit_git_mods = LocalCatalog::new(caches_dir, "git-modules").unwrap();
let git_mod_catalog = GitCatalog::new_without_source_repo(caches_dir, env.fs_mod_formats.clone(), "git-modules").unwrap();
explicit_git_mods.push_upstream_catalog(Box::new(git_mod_catalog));
env.explicit_git_mods = Some(explicit_git_mods);
//Setup the specified_mods managed catalog to hold mods fetched by explicit means
let mut specified_mods = LocalCatalog::new(caches_dir, "specified-mods").unwrap();
let git_mod_catalog = GitCatalog::new_without_source_repo(caches_dir, env.fs_mod_formats.clone(), "specified-mods").unwrap();
specified_mods.push_upstream_catalog(Box::new(git_mod_catalog));
env.specified_mods = Some(specified_mods);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/metta/runner/pkg_mgmt/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ pub(crate) fn resolve_module(pkg_info: Option<&PkgInfo>, context: &RunContext, n

//Get the module if it's specified with git keys
if entry.git_location.get_url().is_some() {
match context.metta.environment().explicit_git_mods.as_ref() {
Some(explicit_git_catalog) => if let Some(pair) = explicit_git_catalog.loader_for_explicit_git_module(mod_name, UpdateMode::FetchIfMissing, &entry.git_location)? {
match context.metta.environment().specified_mods.as_ref() {
Some(specified_mods) => if let Some(pair) = specified_mods.loader_for_explicit_git_module(mod_name, UpdateMode::FetchIfMissing, &entry.git_location)? {
return Ok(Some(pair));
},
None => return Err(format!("Unable to pull module \"{mod_name}\" from git; no local \"caches\" directory available"))
Expand Down
4 changes: 2 additions & 2 deletions lib/src/metta/runner/pkg_mgmt/managed_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use git_catalog::{GitCatalog, ModuleGitLocation};
use crate::metta::runner::*;
use crate::metta::runner::pkg_mgmt::*;

/// An interface to facilitate explicit management of a catalog, usually as a local mirror
/// of one or more remote catalogs used by a user to insulate them from upstream changes
/// An interface to facilitate direct programatic management of a catalog, usually as a local
/// mirror of one or more remote catalogs used by a user to insulate them from upstream changes
//
//NOTE FOR THE FUTURE: There are two major problems with this `fetch_newest_for_all`
// interface.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/metta/runner/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,8 @@ pub(crate) mod pkg_mgmt_ops {

let git_mod_location = ModuleGitLocation::new(url.to_string());

match context.metta.environment().explicit_git_mods.as_ref() {
Some(explicit_git_catalog) => if let Some((loader, descriptor)) = explicit_git_catalog.loader_for_explicit_git_module(&mod_name, UpdateMode::TryFetchLatest, &git_mod_location)? {
match context.metta.environment().specified_mods.as_ref() {
Some(specified_mods) => if let Some((loader, descriptor)) = specified_mods.loader_for_explicit_git_module(&mod_name, UpdateMode::TryFetchLatest, &git_mod_location)? {
context.get_or_init_module_with_descriptor(&mod_name, descriptor, loader).map_err(|e| ExecError::from(e))?;
},
None => return Err(ExecError::from(format!("Unable to pull module \"{mod_name}\" from git; no local \"caches\" directory available")))
Expand Down

0 comments on commit da74ea2

Please sign in to comment.