From 81d2be650adbef19b6417c1fc5ca26b9c0b8f623 Mon Sep 17 00:00:00 2001 From: Greg Schoeninger Date: Wed, 4 Oct 2023 08:53:59 -0700 Subject: [PATCH 1/2] organize user config outside of auth module --- oxen/python/oxen/auth.py | 15 +++----------- oxen/python/oxen/user.py | 16 ++++++++++++++ oxen/src/auth.rs | 21 ++----------------- oxen/src/lib.rs | 21 +++++++++++++------ oxen/src/py_user.rs | 45 ++++++++++++++++++++++++++++++++++++++++ oxen/src/user.rs | 27 ++++++++++++++++++++++++ oxen/src/util.rs | 8 +++++++ 7 files changed, 116 insertions(+), 37 deletions(-) create mode 100644 oxen/python/oxen/user.py create mode 100644 oxen/src/py_user.rs create mode 100644 oxen/src/user.rs diff --git a/oxen/python/oxen/auth.py b/oxen/python/oxen/auth.py index 587d0b2..bb9274d 100644 --- a/oxen/python/oxen/auth.py +++ b/oxen/python/oxen/auth.py @@ -1,18 +1,9 @@ -from .oxen import auth +from .oxen import auth, util from typing import Optional - -def create_user_config(name: str, email: str, path: Optional[str] = None): - if path is None: - path = f"{auth.get_oxen_home_dir()}/user_config.toml" - if not path.endswith(".toml"): - raise ValueError("Path must end with .toml") - auth.create_user_config(name, email, path) - - -def add_host_auth(host: str, token: str, path: Optional[str] = None): +def config_auth(host: str, token: str, path: Optional[str] = None): if path is None: - path = f"{auth.get_oxen_home_dir()}/user_config.toml" + path = f"{util.get_oxen_home_dir()}/user_config.toml" if not path.endswith(".toml"): raise ValueError("Path must end with .toml") auth.add_host_auth(host, token, path) diff --git a/oxen/python/oxen/user.py b/oxen/python/oxen/user.py new file mode 100644 index 0000000..c57d928 --- /dev/null +++ b/oxen/python/oxen/user.py @@ -0,0 +1,16 @@ +from .oxen import user, util +from typing import Optional + +def config_user(name: str, email: str, path: Optional[str] = None): + if path is None: + path = f"{util.get_oxen_home_dir()}/user_config.toml" + if not path.endswith(".toml"): + raise ValueError(f"Path {path} must end with .toml") + return user.config_user(name, email, path) + +def current_user(path: Optional[str] = None): + if path is None: + path = f"{util.get_oxen_home_dir()}/user_config.toml" + if not path.endswith(".toml"): + raise ValueError(f"Path {path} must end with .toml") + return user.current_user(path) \ No newline at end of file diff --git a/oxen/src/auth.rs b/oxen/src/auth.rs index cfa459e..930041f 100644 --- a/oxen/src/auth.rs +++ b/oxen/src/auth.rs @@ -3,31 +3,14 @@ use crate::error::PyOxenError; use liboxen::config::user_config::UserConfig; -use liboxen::model::User; -use liboxen::util::fs::oxen_home_dir; use pyo3::prelude::*; -use std::path::{Path, PathBuf}; +use std::path::Path; #[pyfunction] -pub fn create_user_config(name: String, email: String, path: String) -> Result<(), PyOxenError> { - let final_path = Path::new(&path); - let user = User { name, email }; - let config = UserConfig::from_user(&user); - config.save(final_path)?; - Ok(()) -} - -#[pyfunction] -pub fn add_host_auth(host: String, token: String, path: String) -> Result<(), PyOxenError> { +pub fn config_auth(host: String, token: String, path: String) -> Result<(), PyOxenError> { let final_path = Path::new(&path); let mut config = UserConfig::new(final_path); config.add_host_auth_token(host, token); config.save(final_path)?; Ok(()) } - -#[pyfunction] -pub fn get_oxen_home_dir() -> Result { - let path = oxen_home_dir()?; - Ok(path) -} diff --git a/oxen/src/lib.rs b/oxen/src/lib.rs index 95e4c1b..1e63e7f 100644 --- a/oxen/src/lib.rs +++ b/oxen/src/lib.rs @@ -16,6 +16,8 @@ pub mod py_local_repo; pub mod py_remote_repo; pub mod py_paginated_dir_entries; pub mod py_staged_data; +pub mod py_user; +pub mod user; pub mod util; /// A Python module implemented in Rust. @@ -40,25 +42,32 @@ fn oxen(py: Python, m: &PyModule) -> PyResult<()> { // https://docs.rs/pyo3-log/latest/pyo3_log/#interaction-with-python-gil // pyo3_log::init(); - m.add_class::()?; m.add_class::()?; - m.add_class::()?; + m.add_class::()?; m.add_class::()?; + m.add_class::()?; + m.add_class::()?; m.add_class::()?; - m.add_class::()?; + m.add_class::()?; // Util Module let util_module = PyModule::new(py, "util")?; util_module.add_function(wrap_pyfunction!(util::is_tabular, util_module)?)?; util_module.add_function(wrap_pyfunction!(util::read_df, util_module)?)?; + util_module.add_function(wrap_pyfunction!(util::get_oxen_home_dir, util_module)?)?; m.add_submodule(util_module)?; // Auth Module let auth_module = PyModule::new(py, "auth")?; - auth_module.add_function(wrap_pyfunction!(auth::get_oxen_home_dir, auth_module)?)?; - auth_module.add_function(wrap_pyfunction!(auth::add_host_auth, auth_module)?)?; - auth_module.add_function(wrap_pyfunction!(auth::create_user_config, auth_module)?)?; + auth_module.add_function(wrap_pyfunction!(auth::config_auth, auth_module)?)?; m.add_submodule(auth_module)?; + + // User Module + let user_module = PyModule::new(py, "user")?; + user_module.add_function(wrap_pyfunction!(user::config_user, user_module)?)?; + user_module.add_function(wrap_pyfunction!(user::current_user, user_module)?)?; + m.add_submodule(user_module)?; + Ok(()) } diff --git a/oxen/src/py_user.rs b/oxen/src/py_user.rs new file mode 100644 index 0000000..08aeca9 --- /dev/null +++ b/oxen/src/py_user.rs @@ -0,0 +1,45 @@ +use liboxen::model::User; +use pyo3::prelude::*; + +#[pyclass] +pub struct PyUser { + _user: User, +} + +#[pymethods] +impl PyUser { + #[new] + #[pyo3(signature = (name, email))] + pub fn new(name: String, email: String) -> Self { + Self { + _user: User { + name, + email + }, + } + } + + #[getter] + pub fn name(&self) -> &str { + &self._user.name + } + + #[getter] + pub fn email(&self) -> &str { + &self._user.email + } + + fn __repr__(&self) -> String { + format!("PyUser(name='{}', email={})", self._user.name, self._user.email) + } + + fn __str__(&self) -> String { + format!("{}", self._user.name) + } +} + +impl From for PyUser { + fn from(user: User) -> PyUser { + PyUser { _user: user } + } +} diff --git a/oxen/src/user.rs b/oxen/src/user.rs new file mode 100644 index 0000000..51e16b6 --- /dev/null +++ b/oxen/src/user.rs @@ -0,0 +1,27 @@ +//! Oxen User Functions +//! + +use crate::error::PyOxenError; +use crate::py_user::PyUser; +use liboxen::config::user_config::UserConfig; +use liboxen::model::User; +use pyo3::prelude::*; +use std::path::Path; + +#[pyfunction] +pub fn config_user(name: String, email: String, path: String) -> Result { + let final_path = Path::new(&path); + let user = User { name, email }; + let config = UserConfig::from_user(&user); + config.save(final_path)?; + Ok(user.into()) +} + +#[pyfunction] +pub fn current_user(path: String) -> Result { + let path = Path::new(&path); + let config = UserConfig::new(&path); + Ok(config.to_user().into()) +} + + diff --git a/oxen/src/util.rs b/oxen/src/util.rs index 3535fbd..0da5cdb 100644 --- a/oxen/src/util.rs +++ b/oxen/src/util.rs @@ -8,6 +8,14 @@ use std::path::PathBuf; use crate::error::PyOxenError; use liboxen::{opts::DFOpts, util}; +use liboxen::util::fs::oxen_home_dir; + +/// Get the default home directory for exen +#[pyfunction] +pub fn get_oxen_home_dir() -> Result { + let path = oxen_home_dir()?; + Ok(path) +} /// Checks if a path is tabular #[pyfunction] From f3c8ab114716a7bbce10be1f1d8ba8f1727ab401 Mon Sep 17 00:00:00 2001 From: Greg Schoeninger Date: Mon, 9 Oct 2023 09:03:49 -0700 Subject: [PATCH 2/2] bump python 0.2.0 and liboxen 0.9.1 --- oxen/Cargo.lock | 7 ++++--- oxen/Cargo.toml | 6 +++--- oxen/python/oxen/auth.py | 2 +- oxen/python/oxen/user.py | 4 ++-- oxen/src/auth.rs | 4 ++-- oxen/src/lib.rs | 4 +++- oxen/src/py_diff.rs | 30 ++++++++++++++++++++++++++++++ oxen/src/py_local_repo.rs | 6 ++++++ oxen/src/util.rs | 6 +++--- 9 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 oxen/src/py_diff.rs diff --git a/oxen/Cargo.lock b/oxen/Cargo.lock index b93bad9..5b089bb 100644 --- a/oxen/Cargo.lock +++ b/oxen/Cargo.lock @@ -2575,9 +2575,9 @@ checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" [[package]] name = "liboxen" -version = "0.8.6" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d895b3c7e04c2941f977c58087be00fe0a3318fcd41584baf8c983eee9d2931c" +checksum = "f5c336147545f23b80f22ff06faf3fc9e766043c7a6a87151e3fff2eed824868" dependencies = [ "actix-files", "actix-web", @@ -2587,6 +2587,7 @@ dependencies = [ "async-recursion", "async-std", "async-tar", + "blocking", "bytecount", "bytes", "bytesize", @@ -3127,7 +3128,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "oxen" -version = "0.1.28" +version = "0.2.0" dependencies = [ "bindgen 0.66.1", "cc", diff --git a/oxen/Cargo.toml b/oxen/Cargo.toml index 11324ac..bdcb510 100644 --- a/oxen/Cargo.toml +++ b/oxen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxen" -version = "0.1.28" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -15,8 +15,8 @@ log = "0.4.17" pyo3-log = "0.8.1" tokio = { version = "1", features = ["full"] } pyo3-polars = "0.6.0" -liboxen = "0.8.6" -# liboxen = { path = "../../Oxen/src/lib" } +liboxen = "0.9.1" +# liboxen = { path = "../../rust/Oxen/src/lib" } [build-dependencies] cc = { version = "1.0", features = ["parallel"] } diff --git a/oxen/python/oxen/auth.py b/oxen/python/oxen/auth.py index bb9274d..4623e16 100644 --- a/oxen/python/oxen/auth.py +++ b/oxen/python/oxen/auth.py @@ -3,7 +3,7 @@ def config_auth(host: str, token: str, path: Optional[str] = None): if path is None: - path = f"{util.get_oxen_home_dir()}/user_config.toml" + path = f"{util.get_oxen_config_dir()}/user_config.toml" if not path.endswith(".toml"): raise ValueError("Path must end with .toml") auth.add_host_auth(host, token, path) diff --git a/oxen/python/oxen/user.py b/oxen/python/oxen/user.py index c57d928..3ab9526 100644 --- a/oxen/python/oxen/user.py +++ b/oxen/python/oxen/user.py @@ -3,14 +3,14 @@ def config_user(name: str, email: str, path: Optional[str] = None): if path is None: - path = f"{util.get_oxen_home_dir()}/user_config.toml" + path = f"{util.get_oxen_config_dir()}/user_config.toml" if not path.endswith(".toml"): raise ValueError(f"Path {path} must end with .toml") return user.config_user(name, email, path) def current_user(path: Optional[str] = None): if path is None: - path = f"{util.get_oxen_home_dir()}/user_config.toml" + path = f"{util.get_oxen_config_dir()}/user_config.toml" if not path.endswith(".toml"): raise ValueError(f"Path {path} must end with .toml") return user.current_user(path) \ No newline at end of file diff --git a/oxen/src/auth.rs b/oxen/src/auth.rs index 930041f..2f4d563 100644 --- a/oxen/src/auth.rs +++ b/oxen/src/auth.rs @@ -2,14 +2,14 @@ //! use crate::error::PyOxenError; -use liboxen::config::user_config::UserConfig; +use liboxen::config::auth_config::AuthConfig; use pyo3::prelude::*; use std::path::Path; #[pyfunction] pub fn config_auth(host: String, token: String, path: String) -> Result<(), PyOxenError> { let final_path = Path::new(&path); - let mut config = UserConfig::new(final_path); + let mut config = AuthConfig::new(final_path); config.add_host_auth_token(host, token); config.save(final_path)?; Ok(()) diff --git a/oxen/src/lib.rs b/oxen/src/lib.rs index 1e63e7f..ba6235f 100644 --- a/oxen/src/lib.rs +++ b/oxen/src/lib.rs @@ -11,6 +11,7 @@ pub mod py_branch; pub mod auth; pub mod py_commit; pub mod py_dataset; +pub mod py_diff; pub mod py_entry; pub mod py_local_repo; pub mod py_remote_repo; @@ -45,6 +46,7 @@ fn oxen(py: Python, m: &PyModule) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; m.add_class::()?; m.add_class::()?; m.add_class::()?; @@ -54,7 +56,7 @@ fn oxen(py: Python, m: &PyModule) -> PyResult<()> { let util_module = PyModule::new(py, "util")?; util_module.add_function(wrap_pyfunction!(util::is_tabular, util_module)?)?; util_module.add_function(wrap_pyfunction!(util::read_df, util_module)?)?; - util_module.add_function(wrap_pyfunction!(util::get_oxen_home_dir, util_module)?)?; + util_module.add_function(wrap_pyfunction!(util::get_oxen_config_dir, util_module)?)?; m.add_submodule(util_module)?; // Auth Module diff --git a/oxen/src/py_diff.rs b/oxen/src/py_diff.rs new file mode 100644 index 0000000..103cf38 --- /dev/null +++ b/oxen/src/py_diff.rs @@ -0,0 +1,30 @@ +use pyo3::prelude::*; + +use liboxen::model::diff::generic_diff::GenericDiff; + +#[pyclass] +pub struct PyDiff { + pub diff: GenericDiff, +} + +#[pymethods] +impl PyDiff { + fn __repr__(&self) -> String { + format!("PyDiff(type={})", self.get_type()) + } + + #[getter] + pub fn get_type(&self) -> String { + match &self.diff { + GenericDiff::DirDiff(_diff) => { + "dir".to_string() + }, + GenericDiff::TabularDiff(_diff) => { + "tabular".to_string() + }, + // GenericDiff::TextDiff(_diff) => { + // "text".to_string() + // }, + } + } +} \ No newline at end of file diff --git a/oxen/src/py_local_repo.rs b/oxen/src/py_local_repo.rs index 11180a8..45c753b 100644 --- a/oxen/src/py_local_repo.rs +++ b/oxen/src/py_local_repo.rs @@ -15,6 +15,7 @@ use std::path::PathBuf; use crate::error::PyOxenError; use crate::py_branch::PyBranch; use crate::py_commit::PyCommit; +// use crate::py_diff::PyDiff; use crate::py_staged_data::PyStagedData; #[pyclass] @@ -151,4 +152,9 @@ impl PyLocalRepo { })?; Ok(()) } + + // pub fn diff(&self, path: &str) -> Result { + // let repo = LocalRepository::from_dir(&self.path)?; + // let diff = + // } } diff --git a/oxen/src/util.rs b/oxen/src/util.rs index 0da5cdb..a2fa144 100644 --- a/oxen/src/util.rs +++ b/oxen/src/util.rs @@ -8,12 +8,12 @@ use std::path::PathBuf; use crate::error::PyOxenError; use liboxen::{opts::DFOpts, util}; -use liboxen::util::fs::oxen_home_dir; +use liboxen::util::fs::oxen_config_dir; /// Get the default home directory for exen #[pyfunction] -pub fn get_oxen_home_dir() -> Result { - let path = oxen_home_dir()?; +pub fn get_oxen_config_dir() -> Result { + let path = oxen_config_dir()?; Ok(path) }