Skip to content

Commit

Permalink
feat: add pre-commit integrations (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kalen Michael <kalenmike@gmail.com>
  • Loading branch information
3 people authored Dec 29, 2023
1 parent d58fd91 commit 3e9a124
Show file tree
Hide file tree
Showing 28 changed files with 507 additions and 498 deletions.
92 changes: 92 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
# Pre-commit hooks. For more information see https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md
# Optionally remove from local hooks with 'rm .git/hooks/pre-commit'

# Define bot property if installed via https://github.com/marketplace/pre-commit-ci
ci:
autofix_prs: true
autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions'
autoupdate_schedule: monthly
submodules: true

# Exclude directories from checks (optional)
# exclude: 'docs/'

# Define repos to run
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
# - id: check-yaml
- id: check-docstring-first
- id: double-quote-string-fixer
- id: detect-private-key

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
name: Upgrade code

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
name: Sort imports

- repo: https://github.com/google/yapf
rev: v0.40.2
hooks:
- id: yapf
name: YAPF formatting

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
name: MD formatting
additional_dependencies:
- mdformat-gfm
# - mdformat-black
# - mdformat-frontmatter
args:
- --wrap=no
exclude: 'docs/.*\.md'
# exclude: "README.md|README.zh-CN.md|CONTRIBUTING.md"

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
name: PEP8

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
exclude: 'docs/de|docs/fr|docs/pt|docs/es|docs/mkdocs_de.yml'
args:
- --ignore-words-list=crate,nd,strack,dota,ane,segway,fo,gool,winn

- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter

# - repo: https://github.com/asottile/yesqa
# rev: v1.4.0
# hooks:
# - id: yesqa

# - repo: https://github.com/asottile/dead
# rev: v1.5.0
# hooks:
# - id: dead

# - repo: https://github.com/ultralytics/pre-commit
# rev: bd60a414f80a53fb8f593d3bfed4701fc47e4b23
# hooks:
# - id: capitalize-comments
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ Welcome to the Ultralytics HUB-SDK documentation! 📖 Our aim is to guide you t
Ready to dive into HUB-SDK? Follow these steps to set it up on your machine.

### Prerequisites

Ensure you have the following requirements met before proceeding:

- **Python:** HUB-SDK requires Python. Download and install Python from [python.org](https://www.python.org/downloads/) if it's not already installed on your system.
- **Python:** HUB-SDK requires Python. Download and install Python from [python.org](https://www.python.org/downloads/) if it's not already installed on your system.

- **Git (Optional):** If you're looking to install HUB-SDK via the GitHub repository, you'll need Git. Grab Git from [git-scm.com](https://git-scm.com/downloads) if you don't have it.
- **Git (Optional):** If you're looking to install HUB-SDK via the GitHub repository, you'll need Git. Grab Git from [git-scm.com](https://git-scm.com/downloads) if you don't have it.

### Installation Methods

Choose from the following options to install HUB-SDK:

#### Installing from PyPI

For the latest stable release of HUB-SDK, use PyPI by running the following command:

```sh
Expand Down Expand Up @@ -137,7 +140,7 @@ We're thrilled to have you contribute to Ultralytics' open-source projects! Your
Ultralytics provides two types of licensing options:

- **AGPL-3.0 License**: An [OSI-approved](https://opensource.org/licenses/) open-source license. Ideal for academics, researchers, and enthusiasts, this license promotes sharing knowledge and collaboration. See the [LICENSE](https://github.com/ultralytics/ultralytics/blob/main/LICENSE) file for details.

- **Enterprise License**: Tailored for commercial applications, this license allows for the integration of Ultralytics software into proprietary products and services. If you're considering using our solutions commercially, please get in touch through [Ultralytics Licensing](https://ultralytics.com/license).

## 🤝 Contact
Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ To install the latest stable release of HUB-SDK from PyPI, run the following com
pip install hub-sdk
```

## Initilize HUBClient
## Initialize HUBClient
In the provided code snippet, you are attempting to initialize an HUBClient object, presumably for some kind of API or service access. You have two options for providing credentials: using an API key or using an email/password combination.

```sh
crednetials = {"api_key": "<ADD-API-KEY>"}
credentials = {"api_key": "<ADD-API-KEY>"}
```

In this option, you are initializing the HUBClient by providing an API key in the credentials dictionary. This is commonly used when you have an API that requires an API key for authentication.

```sh
crednetials = {"email": "<EMAIL>", "password": "<PASSWORD>"}
credentials = {"email": "<EMAIL>", "password": "<PASSWORD>"}
```
In this option, you are initializing the HUBClient by providing an email and password in the credentials dictionary. This is typically used when you need to authenticate using a username (email) and password combination.


```sh
client = HUBClient(crednetials)
client = HUBClient(credentials)
```

In this line of code, a client for the HUB service is being initialized with the provided credentials. The HUBClient class is used to create a connection to the HUB platform, with authentication details such as an API key or email/password pair stored in the credentials dictionary.
6 changes: 3 additions & 3 deletions docs/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ print(model.data)
### Project and Dataset Check
This code snippet checks whether both a project and a dataset exist based on their respective IDs. It initializes project and dataset objects using their IDs and raises an exception if either of them is not available.
```sh
project = client.project("<Poject ID>")
project = client.project("<Project ID>")
dataset = client.dataset("<Dataset ID>")
if None in (project.id, dataset.id):
raise "Available"
Expand All @@ -35,15 +35,15 @@ model = client.model()
model.create_model(data)
```
### Update Model
### Update Model
This code demonstrates how to update the metadata of an existing model. You can change attributes like the model's name by specifying the model's ID and providing updated metadata.
```sh
model = client.model("<Model ID>")
model.update({"meta": {"name": "model Name"}})
```
### Delete Model
### Delete Model
This function allows you to delete a specific model by providing its ID. Be cautious when using this function, as it permanently removes the model and its associated data.
```sh
model = client.model("Model ID")
Expand Down
8 changes: 4 additions & 4 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ pip install hub-sdk
```


## Initilize HUBClient
## Initialize HUBClient

In the provided code snippet, you are attempting to initialize an HUBClient object, presumably for some kind of API or service access. You have two options for providing credentials: using an API key or using an email/password combination.

```sh
crednetials = {"api_key": "<ADD-API-KEY>"}
credentials = {"api_key": "<ADD-API-KEY>"}
```

In this option, you are initializing the HUBClient by providing an API key in the credentials dictionary. This is commonly used when you have an API that requires an API key for authentication.

```sh
crednetials = {"email": "<EMAIL>", "password": "<PASSWORD>"}
credentials = {"email": "<EMAIL>", "password": "<PASSWORD>"}
```
In this option, you are initializing the HUBClient by providing an email and password in the credentials dictionary. This is typically used when you need to authenticate using a username (email) and password combination.


```sh
client = HUBClient(crednetials)
client = HUBClient(credentials)
```

In this line of code, a client for the HUB service is being initialized with the provided credentials. The HUBClient class is used to create a connection to the HUB platform, with authentication details such as an API key or email/password pair stored in the credentials dictionary.
2 changes: 1 addition & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: hub_sdk.hub_client.HUBClient
::: hub_sdk.hub_client.HUBClient
2 changes: 1 addition & 1 deletion hub_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Ultralytics HUB CLient SDK 🚀

from hub_sdk.hub_client import HUBClient
from hub_sdk.config import HUB_API_ROOT, HUB_WEB_ROOT
from hub_sdk.hub_client import HUBClient

__version__ = '1.0.0'
__all__ = '__version__', 'HUBClient', 'HUB_API_ROOT', 'HUB_WEB_ROOT'
50 changes: 26 additions & 24 deletions hub_sdk/base/api_client.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import requests
from hub_sdk.helpers.error_handler import ErrorHandler

from hub_sdk.config import HUB_EXCEPTIONS
from hub_sdk.helpers.error_handler import ErrorHandler
from hub_sdk.helpers.logger import logger


class APIClientError(Exception):

def __init__(self, message: str, status_code: int = None):
super().__init__(message)
self.status_code = status_code
self.message = message

def __str__(self) -> str:
return f"{self.__class__.__name__}: {self.args[0]}"
return f'{self.__class__.__name__}: {self.args[0]}'


class APIClient:

def __init__(self, base_url: str, headers: dict = None):
"""
Initialize an instance of the APIClient class.
Expand All @@ -26,7 +30,14 @@ def __init__(self, base_url: str, headers: dict = None):
self.headers = headers
self.logger = logger

def _make_request(self, method: str, endpoint: str, data: dict=None, json=None, params=None, files=None, stream : bool=False):
def _make_request(self,
method: str,
endpoint: str,
data: dict = None,
json=None,
params=None,
files=None,
stream: bool = False):
"""
Make an HTTP request to the API.
Expand All @@ -47,27 +58,18 @@ def _make_request(self, method: str, endpoint: str, data: dict=None, json=None,
based on the HTTP status code.
"""
# Overwrite the base url if a http url is submitted
url = endpoint if endpoint.startswith("http") else self.base_url + endpoint
url = endpoint if endpoint.startswith('http') else self.base_url + endpoint

kwargs = {
"params": params,
"files": files,
"headers": self.headers,
"stream": stream
}
kwargs = {'params': params, 'files': files, 'headers': self.headers, 'stream': stream}

# Determine the request data based on 'data' or 'json_data'
if json is not None:
kwargs["json"] = json
kwargs['json'] = json
else:
kwargs["data"] = data
kwargs['data'] = data

try:
response = requests.request(
method,
url,
**kwargs
)
response = requests.request(method, url, **kwargs)

response.raise_for_status()
return response
Expand All @@ -92,9 +94,9 @@ def get(self, endpoint: str, params=None):
Returns:
requests.Response: The response object from the HTTP GET request.
"""
return self._make_request("GET", endpoint, params=params)
return self._make_request('GET', endpoint, params=params)

def post(self, endpoint: str, data: dict =None, json=None, files=None):
def post(self, endpoint: str, data: dict = None, json=None, files=None):
"""
Make a POST request to the API.
Expand All @@ -105,7 +107,7 @@ def post(self, endpoint: str, data: dict =None, json=None, files=None):
Returns:
requests.Response: The response object from the HTTP POST request.
"""
return self._make_request("POST", endpoint, data=data, json=json, files=files)
return self._make_request('POST', endpoint, data=data, json=json, files=files)

def put(self, endpoint: str, data=None, json=None):
"""
Expand All @@ -118,7 +120,7 @@ def put(self, endpoint: str, data=None, json=None):
Returns:
requests.Response: The response object from the HTTP PUT request.
"""
return self._make_request("PUT", endpoint, data=data, json=json)
return self._make_request('PUT', endpoint, data=data, json=json)

def delete(self, endpoint: str, params=None):
"""
Expand All @@ -130,8 +132,8 @@ def delete(self, endpoint: str, params=None):
Returns:
requests.Response: The response object from the HTTP DELETE request.
"""
return self._make_request("DELETE", endpoint, params=params)
return self._make_request('DELETE', endpoint, params=params)

def patch(self, endpoint: str, data=None, json=None):
"""
Make a PATCH request to the API.
Expand All @@ -143,4 +145,4 @@ def patch(self, endpoint: str, data=None, json=None):
Returns:
requests.Response: The response object from the HTTP PATCH request.
"""
return self._make_request("PATCH", endpoint, data=data, json=json)
return self._make_request('PATCH', endpoint, data=data, json=json)
Loading

0 comments on commit 3e9a124

Please sign in to comment.