Workdir config
This commit is contained in:
@@ -33,9 +33,6 @@ pub struct DatasetConfig {
|
|||||||
/// Must be unique
|
/// Must be unique
|
||||||
pub name: Label,
|
pub name: Label,
|
||||||
|
|
||||||
/// Root dir for indices
|
|
||||||
pub working_dir: Option<PathBuf>,
|
|
||||||
|
|
||||||
/// Where to find this field
|
/// Where to find this field
|
||||||
pub source: HashMap<Label, Source>,
|
pub source: HashMap<Label, Source>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,8 +102,6 @@ impl Datasets {
|
|||||||
let config = ConfigToml {
|
let config = ConfigToml {
|
||||||
dataset: DatasetConfig {
|
dataset: DatasetConfig {
|
||||||
name: Label::new("virtual-dataset").unwrap(),
|
name: Label::new("virtual-dataset").unwrap(),
|
||||||
working_dir: None,
|
|
||||||
|
|
||||||
source: [(
|
source: [(
|
||||||
Self::virt_source(),
|
Self::virt_source(),
|
||||||
Source::Filesystem {
|
Source::Filesystem {
|
||||||
@@ -155,7 +153,10 @@ impl Datasets {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn open(config: impl Into<PathBuf>) -> Result<Self, std::io::Error> {
|
pub async fn open(
|
||||||
|
config: impl Into<PathBuf>,
|
||||||
|
working_dir_root: impl Into<PathBuf>,
|
||||||
|
) -> Result<Self, std::io::Error> {
|
||||||
let path_config = config.into();
|
let path_config = config.into();
|
||||||
let path_parent = path_config
|
let path_parent = path_config
|
||||||
.parent()
|
.parent()
|
||||||
@@ -184,12 +185,7 @@ impl Datasets {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let path_workdir = config
|
let path_workdir = working_dir_root.into().join(config.dataset.name.as_str());
|
||||||
.dataset
|
|
||||||
.working_dir
|
|
||||||
.clone()
|
|
||||||
.unwrap_or(path_parent.join(".pile"))
|
|
||||||
.join(config.dataset.name.as_str());
|
|
||||||
|
|
||||||
let mut sources = HashMap::new();
|
let mut sources = HashMap::new();
|
||||||
let mut disabled_sources = HashMap::new();
|
let mut disabled_sources = HashMap::new();
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ pub struct CheckCommand {
|
|||||||
/// Path to dataset config
|
/// Path to dataset config
|
||||||
#[arg(long, short = 'c', default_value = "./pile.toml")]
|
#[arg(long, short = 'c', default_value = "./pile.toml")]
|
||||||
config: PathBuf,
|
config: PathBuf,
|
||||||
|
|
||||||
|
/// Working directory root
|
||||||
|
#[arg(long, default_value = "./.pile")]
|
||||||
|
workdir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliCmd for CheckCommand {
|
impl CliCmd for CheckCommand {
|
||||||
@@ -43,7 +47,7 @@ impl CliCmd for CheckCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ds = Datasets::open(&self.config)
|
let ds = Datasets::open(&self.config, self.workdir)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ pub struct FieldsCommand {
|
|||||||
/// Restrict to these sources (all sources if empty)
|
/// Restrict to these sources (all sources if empty)
|
||||||
#[arg(long, short = 's')]
|
#[arg(long, short = 's')]
|
||||||
source: Vec<String>,
|
source: Vec<String>,
|
||||||
|
|
||||||
|
/// Working directory root
|
||||||
|
#[arg(long, default_value = "./.pile")]
|
||||||
|
workdir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliCmd for FieldsCommand {
|
impl CliCmd for FieldsCommand {
|
||||||
@@ -53,7 +57,7 @@ impl CliCmd for FieldsCommand {
|
|||||||
_ctx: GlobalContext,
|
_ctx: GlobalContext,
|
||||||
flag: CancelFlag,
|
flag: CancelFlag,
|
||||||
) -> Result<i32, CancelableTaskError<anyhow::Error>> {
|
) -> Result<i32, CancelableTaskError<anyhow::Error>> {
|
||||||
let ds = Datasets::open(&self.config)
|
let ds = Datasets::open(&self.config, &self.workdir)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ pub struct IndexCommand {
|
|||||||
/// Number of threads to use for indexing
|
/// Number of threads to use for indexing
|
||||||
#[arg(long, short = 'j', default_value = "3")]
|
#[arg(long, short = 'j', default_value = "3")]
|
||||||
jobs: usize,
|
jobs: usize,
|
||||||
|
|
||||||
|
/// Working directory root
|
||||||
|
#[arg(long, default_value = "./.pile")]
|
||||||
|
workdir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliCmd for IndexCommand {
|
impl CliCmd for IndexCommand {
|
||||||
@@ -24,7 +28,7 @@ impl CliCmd for IndexCommand {
|
|||||||
_ctx: GlobalContext,
|
_ctx: GlobalContext,
|
||||||
flag: CancelFlag,
|
flag: CancelFlag,
|
||||||
) -> Result<i32, CancelableTaskError<anyhow::Error>> {
|
) -> Result<i32, CancelableTaskError<anyhow::Error>> {
|
||||||
let ds = Datasets::open(&self.config)
|
let ds = Datasets::open(&self.config, &self.workdir)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ pub struct ItemCommand {
|
|||||||
/// Path to dataset config
|
/// Path to dataset config
|
||||||
#[arg(long, short = 'c', default_value = "./pile.toml")]
|
#[arg(long, short = 'c', default_value = "./pile.toml")]
|
||||||
config: PathBuf,
|
config: PathBuf,
|
||||||
|
|
||||||
|
/// Working directory root
|
||||||
|
#[arg(long, default_value = "./.pile")]
|
||||||
|
workdir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliCmd for ItemCommand {
|
impl CliCmd for ItemCommand {
|
||||||
@@ -43,7 +47,7 @@ impl CliCmd for ItemCommand {
|
|||||||
let source = Label::new(&self.source)
|
let source = Label::new(&self.source)
|
||||||
.ok_or_else(|| anyhow::anyhow!("invalid source name {:?}", self.source))?;
|
.ok_or_else(|| anyhow::anyhow!("invalid source name {:?}", self.source))?;
|
||||||
|
|
||||||
let ds = Datasets::open(&self.config)
|
let ds = Datasets::open(&self.config, &self.workdir)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ pub struct ListCommand {
|
|||||||
/// Restrict to these sources (all sources if empty)
|
/// Restrict to these sources (all sources if empty)
|
||||||
#[arg(long, short = 's')]
|
#[arg(long, short = 's')]
|
||||||
source: Vec<String>,
|
source: Vec<String>,
|
||||||
|
|
||||||
|
/// Working directory root
|
||||||
|
#[arg(long, default_value = "./.pile")]
|
||||||
|
workdir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliCmd for ListCommand {
|
impl CliCmd for ListCommand {
|
||||||
@@ -44,7 +48,7 @@ impl CliCmd for ListCommand {
|
|||||||
.with_context(|| format!("invalid path {:?}", self.path))?;
|
.with_context(|| format!("invalid path {:?}", self.path))?;
|
||||||
let path = Arc::new(path);
|
let path = Arc::new(path);
|
||||||
|
|
||||||
let ds = Datasets::open(&self.config)
|
let ds = Datasets::open(&self.config, &self.workdir)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ pub struct LookupCommand {
|
|||||||
/// Number of threads to use for indexing
|
/// Number of threads to use for indexing
|
||||||
#[arg(long, short = 'j', default_value = "3")]
|
#[arg(long, short = 'j', default_value = "3")]
|
||||||
jobs: usize,
|
jobs: usize,
|
||||||
|
|
||||||
|
/// Working directory root
|
||||||
|
#[arg(long, default_value = "./.pile")]
|
||||||
|
workdir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliCmd for LookupCommand {
|
impl CliCmd for LookupCommand {
|
||||||
@@ -40,7 +44,7 @@ impl CliCmd for LookupCommand {
|
|||||||
_ctx: GlobalContext,
|
_ctx: GlobalContext,
|
||||||
flag: CancelFlag,
|
flag: CancelFlag,
|
||||||
) -> Result<i32, CancelableTaskError<anyhow::Error>> {
|
) -> Result<i32, CancelableTaskError<anyhow::Error>> {
|
||||||
let ds = Datasets::open(&self.config)
|
let ds = Datasets::open(&self.config, &self.workdir)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ pub struct ServeCommand {
|
|||||||
/// Number of threads to use for indexing
|
/// Number of threads to use for indexing
|
||||||
#[arg(long, short = 'j', default_value = "3")]
|
#[arg(long, short = 'j', default_value = "3")]
|
||||||
jobs: usize,
|
jobs: usize,
|
||||||
|
|
||||||
|
/// Working directory root
|
||||||
|
#[arg(long, default_value = "./.pile")]
|
||||||
|
workdir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliCmd for ServeCommand {
|
impl CliCmd for ServeCommand {
|
||||||
@@ -33,7 +37,7 @@ impl CliCmd for ServeCommand {
|
|||||||
_ctx: GlobalContext,
|
_ctx: GlobalContext,
|
||||||
flag: CancelFlag,
|
flag: CancelFlag,
|
||||||
) -> Result<i32, CancelableTaskError<anyhow::Error>> {
|
) -> Result<i32, CancelableTaskError<anyhow::Error>> {
|
||||||
let ds = Datasets::open(&self.config)
|
let ds = Datasets::open(&self.config, &self.workdir)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
.with_context(|| format!("while opening dataset for {}", self.config.display()))?;
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ pub struct ServerCommand {
|
|||||||
/// If provided, require this bearer token for all requests
|
/// If provided, require this bearer token for all requests
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
|
|
||||||
|
/// Working directory root
|
||||||
|
#[arg(long, default_value = "./.pile")]
|
||||||
|
workdir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliCmd for ServerCommand {
|
impl CliCmd for ServerCommand {
|
||||||
@@ -46,7 +50,7 @@ impl CliCmd for ServerCommand {
|
|||||||
let datasets = {
|
let datasets = {
|
||||||
let mut datasets = Vec::new();
|
let mut datasets = Vec::new();
|
||||||
for c in &self.config {
|
for c in &self.config {
|
||||||
let ds = Datasets::open(&c)
|
let ds = Datasets::open(&c, &self.workdir)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("while opening dataset for {}", c.display()))?;
|
.with_context(|| format!("while opening dataset for {}", c.display()))?;
|
||||||
datasets.push(Arc::new(ds));
|
datasets.push(Arc::new(ds));
|
||||||
|
|||||||
Reference in New Issue
Block a user