Skip to content

Commit c6807f0

Browse files
committed
Define ConfigDirectory#default_profile().
1 parent bfdbe9b commit c6807f0

8 files changed

Lines changed: 141 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 23 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ unstable = []
1717

1818
[dependencies]
1919
#asimov = { package = "asimov-sdk", version = "25.1", default-features = false, features = [] }
20-
asimov-directory = { version = "25.1", default-features = false, features = [] }
20+
asimov-config = { version = "25.1", default-features = false, features = [] }
21+
asimov-core = { version = "25.1", default-features = false, features = [] }
22+
asimov-directory = { version = "25.1", default-features = false, features = ["fs"] }
2123
derive_more = { version = "2", default-features = false, features = ["display"] }
2224
pyo3 = { version = "0.27", default-features = false, features = ["extension-module", "macros"] }
2325

2426
[patch.crates-io]
27+
asimov-config = { git = "https://github.com/asimov-platform/asimov.rs.git" }
28+
asimov-core = { git = "https://github.com/asimov-platform/asimov.rs.git" }
2529
asimov-directory = { git = "https://github.com/asimov-platform/asimov.rs.git" }
30+
#asimov-config = { path = "../asimov.rs/lib/asimov-config" }
31+
#asimov-core = { path = "../asimov.rs/lib/asimov-core" }
2632
#asimov-directory = { path = "../asimov.rs/lib/asimov-directory" }

src/asimov/sdk.pyi

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,63 @@ __version__: str
44
__version_tuple__: tuple[int, int, int, str | None]
55

66
class ConfigDirectory:
7-
pass
7+
@staticmethod
8+
def home() -> ConfigDirectory:
9+
pass
10+
def __init__(self, path: str) -> None:
11+
pass
12+
def __repr__(self) -> str:
13+
pass
14+
def default_profile(self) -> ConfigProfile:
15+
pass
16+
17+
class ConfigProfile:
18+
name: str
19+
def __repr__(self) -> str:
20+
pass
821

922
class ModuleDirectory:
23+
@staticmethod
24+
def home() -> ModuleDirectory:
25+
pass
26+
def __init__(self, path: str) -> None:
27+
pass
28+
def __repr__(self) -> str:
29+
pass
30+
def is_installed(self, module_name: str) -> bool:
31+
pass
32+
def is_enabled(self, module_name: str) -> bool:
33+
pass
34+
35+
class ModuleNameIterator:
1036
pass
1137

1238
class ProgramDirectory:
13-
pass
39+
@staticmethod
40+
def home() -> ProgramDirectory:
41+
pass
42+
def __init__(self, path: str) -> None:
43+
pass
44+
def __repr__(self) -> str:
45+
pass
1446

1547
class StateDirectory:
16-
pass
48+
@staticmethod
49+
def home() -> StateDirectory:
50+
pass
51+
def __init__(self, path: str) -> None:
52+
pass
53+
def __repr__(self) -> str:
54+
pass
55+
def has_configs(self) -> bool:
56+
pass
57+
def has_modules(self) -> bool:
58+
pass
59+
def has_programs(self) -> bool:
60+
pass
61+
def configs(self) -> ConfigDirectory:
62+
pass
63+
def modules(self) -> ModuleDirectory:
64+
pass
65+
def programs(self) -> ProgramDirectory:
66+
pass

src/directory/config_directory.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This is free and unencumbered software released into the public domain.
22

3+
use super::ConfigProfile;
34
use asimov_directory::fs::ConfigDirectory as FsConfigDirectory;
45
use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyString};
56

@@ -36,4 +37,15 @@ impl ConfigDirectory {
3637
let class_name: Bound<'_, PyString> = slf.get_type().qualname()?;
3738
Ok(format!("{}({:?})", class_name, slf.borrow().0.as_str()))
3839
}
40+
41+
/// Returns the default configuration profile (e.g., at
42+
/// `$HOME/.asimov/configs/default/`).
43+
pub fn default_profile(&self) -> PyResult<ConfigProfile> {
44+
let Ok(result) = self.0.default_profile() else {
45+
Err(PyErr::new::<PyRuntimeError, _>(
46+
"Failed to open configuration profile", // TODO
47+
))?
48+
};
49+
Ok(ConfigProfile(result))
50+
}
3951
}

src/directory/config_profile.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This is free and unencumbered software released into the public domain.
2+
3+
use asimov_core::Named;
4+
use asimov_directory::fs::ConfigProfile as FsConfigProfile;
5+
use pyo3::{prelude::*, types::PyString};
6+
7+
/// A configuration profile stored on a file system (e.g., `$HOME/.asimov/configs/default/`).
8+
#[pyclass(frozen, module = "asimov", str = "{0}")]
9+
pub struct ConfigProfile(pub(crate) FsConfigProfile);
10+
11+
#[pymethods]
12+
impl ConfigProfile {
13+
pub fn __repr__(slf: &Bound<'_, Self>) -> PyResult<String> {
14+
let class_name: Bound<'_, PyString> = slf.get_type().qualname()?;
15+
Ok(format!("{}({:?})", class_name, slf.borrow().0.as_str()))
16+
}
17+
18+
#[getter]
19+
pub fn name(&self) -> String {
20+
self.0.name().into_owned()
21+
}
22+
}

src/directory/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
mod config_directory;
44
pub use config_directory::*;
55

6+
mod config_profile;
7+
pub use config_profile::*;
8+
69
mod module_directory;
710
pub use module_directory::*;
811

12+
mod module_iterators;
13+
pub use module_iterators::*;
14+
915
mod program_directory;
1016
pub use program_directory::*;
1117

src/directory/module_iterators.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This is free and unencumbered software released into the public domain.
2+
3+
use asimov_directory::fs::ModuleDirectory as FsModuleDirectory;
4+
use pyo3::prelude::*;
5+
6+
/// TODO
7+
#[pyclass(frozen, module = "asimov", str = "{0}")]
8+
pub struct ModuleNameIterator(pub(crate) FsModuleDirectory);
9+
10+
#[pymethods]
11+
impl ModuleNameIterator {}

src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ mod sdk {
99
#[pymodule_init]
1010
fn init(m: &Bound<'_, PyModule>) -> PyResult<()> {
1111
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
12-
m.add("__version_tuple__", (26, 0, 0, Some("dev1")))?; // TODO
12+
m.add("__version_tuple__", (26, 0, 0, Some("dev1")))?; // TODO: 26.0.0.dev1
1313
Ok(())
1414
}
1515

1616
#[pymodule_export]
1717
use super::ConfigDirectory;
1818

19+
#[pymodule_export]
20+
use super::ConfigProfile;
21+
1922
#[pymodule_export]
2023
use super::ModuleDirectory;
2124

25+
#[pymodule_export]
26+
use super::ModuleNameIterator;
27+
2228
#[pymodule_export]
2329
use super::ProgramDirectory;
2430

0 commit comments

Comments
 (0)