-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Oxen-AI/feat/high-level-commands
Feat/high level commands
- Loading branch information
Showing
16 changed files
with
438 additions
and
72 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Optional | ||
from oxen.local_repo import LocalRepo | ||
|
||
|
||
def clone( | ||
repo_id: str, | ||
path: Optional[str] = None, | ||
host: str = "hub.oxen.ai", | ||
branch: str = "main", | ||
protocol: str = "https", | ||
shallow=False, | ||
all=False, | ||
): | ||
""" | ||
Clone a repository | ||
Args: | ||
repo_id: `str` | ||
Name of the repository in the format 'namespace/repo_name'. | ||
For example 'ox/chatbot' | ||
path: `Optional[str]` | ||
The path to clone the repo to. Defaults to the name of the repository. | ||
host: `str` | ||
The host to connect to. Defaults to 'hub.oxen.ai' | ||
branch: `str` | ||
The branch name id to clone. Defaults to 'main' | ||
protocol: `str` | ||
The protocol to use. Defaults to 'https' | ||
shallow: `bool` | ||
Whether to do a shallow clone or not. Default: False | ||
all: `bool` | ||
Whether to clone the full commit history or not. Default: False | ||
Returns: | ||
[LocalRepo](/python-api/local_repo) | ||
A LocalRepo object that can be used to interact with the cloned repo. | ||
""" | ||
# Verify repo_id format | ||
if not "/" in repo_id: | ||
raise ValueError(f"Invalid repo_id format: {repo_id}") | ||
# Get repo name from repo_id | ||
repo_name = repo_id.split("/")[1] | ||
# Get path from repo_name if not provided | ||
if path is None: | ||
path = repo_name | ||
# Get repo url | ||
repo_url = f"{protocol}://{host}/{repo_id}" | ||
# Clone repo | ||
local_repo = LocalRepo(path) | ||
local_repo.clone(repo_url, branch=branch, shallow=shallow, all=all) | ||
return local_repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from oxen.local_repo import LocalRepo | ||
|
||
|
||
def init( | ||
path: str, | ||
): | ||
""" | ||
Initialize a [LocalRepo](/python-api/local_repo) at the given path. | ||
Args: | ||
path: `str` | ||
The path to initialize the repo at. | ||
Returns: | ||
[LocalRepo](/python-api/local_repo) | ||
A LocalRepo object that can be used to interact with the repo. | ||
""" | ||
# Init Repo | ||
local_repo = LocalRepo(path) | ||
return local_repo.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
from .oxen import user, util | ||
from typing import Optional | ||
|
||
|
||
def config_user(name: str, email: str, path: Optional[str] = None): | ||
""" | ||
Configures user for a host. | ||
Args: | ||
name: `str` | ||
The name to use for user. | ||
email: `str` | ||
The email to use for user. | ||
path: `Optional[str]` | ||
The path to save the user config to. | ||
Defaults to $HOME/.config/oxen/user_config.toml | ||
""" | ||
if path is None: | ||
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): | ||
""" | ||
Gets the current user. | ||
Args: | ||
path: `Optional[str]` | ||
The path to load the user config from. | ||
Defaults to $HOME/.config/oxen/user_config.toml | ||
""" | ||
if path is None: | ||
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) | ||
return user.current_user(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.