Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
.env
duckington_cli.egg-info
.coverage
.vscode
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.11
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-toml
- id: check-yaml
args:
- --unsafe
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.41.0
hooks:
- id: markdownlint
args: [ --disable=MD013, --disable=MD002,--disable=MD032,--disable=MD005,--disable=MD009 ]


ci:
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
62 changes: 12 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# Command Line Interface (CLI)
# Duckington CLI

The CLI is built using [click](https://click.palletsprojects.com/en/8.1.x/). Use the following command to get started with the CLI:
<!-- markdownlint-disable MD033 -->
<div style="text-align: center;">
<img src="docs/assets/duckington.png" alt="Le Duck" width="150" height="150">
</div>

The CLI is built using [click](https://click.palletsprojects.com/en/8.1.x/).

Use the following command to get started with the CLI:

```bash
quack
```

## Contributing

To get started contributing to this project see the [setup](docs/setup.md) page

## Testing

Expand All @@ -20,51 +30,3 @@ or
```bash
python3 -m pytest
```

## Setup

Follow these steps to set up a Python virtual environment using `venv`

### 1. Create Virtual Environment

```bash
python3 -m venv .venv
```

### 2. Activate Virtual Environment

- Linux / macOS:

```bash
source .venv/bin/activate
```

- Windows:

```bash
.venv\Scripts\activate
```

- Git Bash:

```bash
source .venv/Scripts/activate
```

### 3. Install Dependencies

```bash
pip install -r requirements.txt
```

### 4. Install CLI application in editable mode

```bash
pip install --editable .
```

### 5. To deactivate the venv

```bash
deactivate
```
Binary file added docs/assets/duckington.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions docs/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Setup

Follow these steps to get started with `quack`.

## TL;DR

1. Set up a Python virtual environment using `venv`
2. Install Pre-commit hooks
3. Install `quack` as an editable module

## Environment Setup

### 1. Create Virtual Environment

```bash
python3 -m venv .venv
```

### 2. Activate Virtual Environment

- **Linux / macOS:**

```bash
source .venv/bin/activate
```

- **Windows:**

```bash
. .venv\Scripts\activate
```

- **Git Bash:**

```bash
source .venv/Scripts/activate
```

### 3. Install Dependencies

```bash
pip install -r requirements.txt
```

### 4. Activate Pre-commit Hooks

```bash
pre-commit install
```

### 5. Install CLI Application in Editable Mode

```bash
pip install --editable .
```

### 6. Deactivate the Virtual Environment

```bash
deactivate
```
Binary file modified requirements.txt
Binary file not shown.
9 changes: 7 additions & 2 deletions src/api/api_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from io import BufferedReader
import requests
from typing import Optional, Dict, Any
from src.config.settings import API_BASE_URL
Expand All @@ -21,6 +22,7 @@ def _make_request(
data: Optional[Dict[str, Any]] = None,
params: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None,
files: Optional[Dict[str, BufferedReader]] = None,
) -> Dict[str, Any]:
url: str = f"{self.base_url}/{endpoint}"
headers = headers or {}
Expand All @@ -37,6 +39,7 @@ def _make_request(
data=data if endpoint == "auth" else None,
params=params,
headers=headers,
files=files,
)
response.raise_for_status()
return response.json()
Expand All @@ -55,9 +58,10 @@ def post(
data: Optional[Dict[str, Any]] = None,
params: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None,
files: Optional[Dict[str, BufferedReader]] = None,
) -> Dict[str, Any]:
return self._make_request(
"POST", endpoint, data=data, params=params, headers=headers
"POST", endpoint, data=data, params=params, headers=headers, files=files
)

def put(
Expand All @@ -66,9 +70,10 @@ def put(
data: Optional[Dict[str, Any]] = None,
params: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None,
files: Optional[Dict[str, str]] = None,
) -> Dict[str, Any]:
return self._make_request(
"PUT", endpoint, data=data, params=params, headers=headers
"PUT", endpoint, data=data, params=params, headers=headers, files=files
)

def delete(
Expand Down
52 changes: 52 additions & 0 deletions src/api/model_file_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
from typing import Dict

from src.api.api_client import APIClient
from src.utils.helpers.handle_api_errors import handle_api_errors


class ModelFileAPI:
def __init__(self, client: APIClient):
self.client = client

@handle_api_errors
def upload_model_file(
self, model_name: str, model_id: str, file_path: str
) -> Dict[str, str]:
with open(file_path, "rb") as file:
files = {
"file": (os.path.basename(file_path), file, "application/octet-stream")
}
params = {"model_name": model_name, "model_id": model_id}
return self.client.post("models", params=params, files=files)

@handle_api_errors
def get_model(self, model_id: str):
return self.client.get(f"models/{model_id}")

@handle_api_errors
def get_all_models(self):
return self.client.get("models")

@handle_api_errors
def read_model_file(self, model_id: str, file_name: str):
return self.client.get(f"models/{model_id}/{file_name}")

@handle_api_errors
def update_model_file(
self, model_name: str, model_id: str, file_path: str
) -> Dict[str, str]:
with open(file_path, "rb") as file:
files = {
"file": (os.path.basename(file_path), file, "application/octet-stream")
}
params = {"model_name": model_name, "model_id": model_id}
return self.client.put("models", params=params, files=files)

@handle_api_errors
def delete_model_file(self, model_id: str, file_name: str):
return self.client.delete(f"models/{model_id}/{file_name}")

@handle_api_errors
def delete_model(self, model_id: str):
return self.client.delete(f"models/{model_id}")
7 changes: 7 additions & 0 deletions src/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from src.commands import key
from src.commands import user_auth
from src.commands import machine
from src.commands import metrics
from src.commands import model_file

__all__ = [key, user_auth, machine, metrics, model_file]
Loading
Loading