Skip to content

Commit

Permalink
Merge pull request #38 from Oxen-AI/adding_delete_branch
Browse files Browse the repository at this point in the history
added delete function to delete a branch from python
  • Loading branch information
gschoeni committed Feb 11, 2024
2 parents 729422e + b4740c0 commit 58edbc7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -131,6 +131,25 @@ Code bases to contribute to:

If you are building anything with Oxen.ai or have any questions we would love to hear from you in our [discord](https://discord.gg/s3tBEn7Ptg).

## Build 🔨

Set up virtual environment:

```Bash
# Set up your python virtual environment
$ python -m venv ~/.venv_oxen # could be python3
$ source ~/.venv_oxen/bin/activate
$ pip install maturin
```

```Bash
# Install rust
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Run maturin
$ maturin develop
```

## Why build Oxen?

Oxen was build by a team of machine learning engineers, who have spent countless hours in their careers managing datasets. We have used many different tools, but none of them were as easy to use and as ergonomic as we would like.
Expand All @@ -150,3 +169,4 @@ We built Oxen to be the tool we wish we had.
<!---------------------------------------------------------------------------->

[Learn The Basics]: https://img.shields.io/badge/Learn_The_Basics-37a779?style=for-the-badge

4 changes: 2 additions & 2 deletions oxen/Cargo.lock

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

4 changes: 2 additions & 2 deletions oxen/Cargo.toml
Expand Up @@ -16,8 +16,8 @@ pyo3-log = "0.9.0"
tokio = { version = "1", features = ["full"] }
pyo3-polars = "0.9.0"
serde_json = "1.0.106"
liboxen = "0.10.14"
# liboxen = { path = "../../Oxen/src/lib" }
liboxen = "0.10.16"
# liboxen = { path = "../../rust/Oxen/src/lib" }

[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
Expand Down
9 changes: 7 additions & 2 deletions oxen/python/oxen/local_repo.py
Expand Up @@ -80,6 +80,11 @@ def branches(self):
"""
return self._repo.list_branches()

def branch(self, name: str, delete=False):
"""
"""
return self._repo.branch(name, delete)

def checkout(self, revision: str, create=False):
"""
Checkout a branch or commit id.
Expand Down Expand Up @@ -164,7 +169,7 @@ def set_remote(self, name: str, url: str):
def create_remote(self, name: str):
self._repo.create_remote(name)

def push(self, remote_name: str = "origin", branch: str = "main"):
def push(self, remote_name: str = "origin", branch: str = "main", delete: bool = False):
"""
Push data to a remote repo from a local repo.
Expand All @@ -174,7 +179,7 @@ def push(self, remote_name: str = "origin", branch: str = "main"):
branch: `str`
The name of the branch to push to.
"""
return self._repo.push(remote_name, branch)
return self._repo.push(remote_name, branch, delete)

def pull(self, remote_name: str = "origin", branch: str = "main", all=False):
"""
Expand Down
32 changes: 26 additions & 6 deletions oxen/src/py_local_repo.rs
Expand Up @@ -2,6 +2,7 @@
//!

use liboxen::error::OxenError;
use liboxen::model::Branch;
use liboxen::model::LocalRepository;
use liboxen::opts::CloneOpts;
use liboxen::opts::RmOpts;
Expand Down Expand Up @@ -81,7 +82,7 @@ impl PyLocalRepo {

pyo3_asyncio::tokio::get_runtime().block_on(async {
command::rm(&repo, &rm_opts).await
}).unwrap();
})?;

Ok(())
}
Expand All @@ -98,6 +99,17 @@ impl PyLocalRepo {
Ok(PyCommit { commit })
}

pub fn branch(&self, name: &str, delete: bool) -> Result<PyBranch, PyOxenError> {
let repo = LocalRepository::from_dir(&self.path)?;
let branch = if delete {
api::local::branches::delete(&repo, name)
} else {
api::local::branches::get_by_name(&repo, name)?
.ok_or(OxenError::local_branch_not_found(name))
};
Ok(PyBranch::from(branch?))
}

pub fn checkout(&self, revision: &str, create: bool) -> Result<PyBranch, PyOxenError> {
let repo = LocalRepository::from_dir(&self.path)?;
let branch = if create {
Expand Down Expand Up @@ -137,12 +149,20 @@ impl PyLocalRepo {
Ok(())
}

pub fn push(&self, remote: &str, branch: &str) -> Result<(), PyOxenError> {
pyo3_asyncio::tokio::get_runtime().block_on(async {
pub fn push(&self, remote: &str, branch: &str, delete: bool) -> Result<PyBranch, PyOxenError> {
let result: Result<Branch, OxenError> = pyo3_asyncio::tokio::get_runtime().block_on(async {
let repo = LocalRepository::from_dir(&self.path)?;
command::push_remote_branch(&repo, remote, branch).await
})?;
Ok(())
if delete {
// Delete the remote branch
api::remote::branches::delete_remote(&repo, remote, branch).await
} else {
// Push to the remote branch
command::push_remote_branch(&repo, remote, branch).await
}
});

let py_branch = PyBranch::from(result?);
Ok(py_branch)
}

pub fn pull(&self, remote: &str, branch: &str, all: bool) -> Result<(), PyOxenError> {
Expand Down

0 comments on commit 58edbc7

Please sign in to comment.