Skip to content

Commit

Permalink
Merge branch 'main' into adds-api-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
deanq committed Sep 26, 2024
2 parents 41102e4 + f1e6450 commit fbd1200
Show file tree
Hide file tree
Showing 142 changed files with 3,883 additions and 2,951 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/CI-codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
name: "CI | CodeQL"

on:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/CI-pylint.yml

This file was deleted.

7 changes: 3 additions & 4 deletions .github/workflows/CI-pytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: CI | Unit Tests

on:
push:
branches-ignore:
- main-ci
- release
branches:
- main

pull_request:
branches:
Expand Down Expand Up @@ -33,4 +32,4 @@ jobs:
pip install '.[test]'
- name: Run Tests
run: pytest --cov-config=.coveragerc --timeout=120 --timeout_method=thread --cov=runpod --cov-report=xml --cov-report=term-missing --cov-fail-under=98 -W error -p no:cacheprovider -p no:unraisableexception
run: pytest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test_logging.py
/example_project
IGNORE.py
/quick-test
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
6 changes: 2 additions & 4 deletions examples/api/create_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
try:

new_template = runpod.create_template(
name="test",
image_name="runpod/base:0.4.4",
is_serverless=True
name="test", image_name="runpod/base:0.4.4", is_serverless=True
)

print(new_template)
Expand All @@ -21,7 +19,7 @@
gpu_ids="AMPERE_16",
workers_min=0,
workers_max=1,
flashboot=True
flashboot=True,
)

print(new_endpoint)
Expand Down
5 changes: 1 addition & 4 deletions examples/api/create_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

try:

new_template = runpod.create_template(
name="test",
image_name="runpod/base:0.1.0"
)
new_template = runpod.create_template(name="test", image_name="runpod/base:0.1.0")

print(new_template)

Expand Down
1 change: 0 additions & 1 deletion examples/api/get_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" Get all endpoints from the API """


import runpod

endpoints = runpod.get_endpoints()
Expand Down
11 changes: 7 additions & 4 deletions examples/endpoints/asyncio_job_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
import asyncio

import runpod
from runpod import http_client, AsyncioEndpoint, AsyncioJob
from runpod import AsyncioEndpoint, AsyncioJob, http_client

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # For Windows Users
asyncio.set_event_loop_policy(
asyncio.WindowsSelectorEventLoopPolicy()
) # For Windows Users

runpod.api_key = "YOUR_API_KEY"


async def main():
'''
"""
Function to run the example.
'''
"""
async with http_client.AsyncClientSession() as session:
# Invoke API
payload = {}
Expand All @@ -34,4 +36,5 @@ async def main():
# Print output
print(output)


asyncio.run(main())
12 changes: 5 additions & 7 deletions examples/endpoints/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
"""
Example of calling an endpoint using the RunPod Python Language Library.
'''
"""

import runpod

Expand All @@ -9,11 +9,9 @@

endpoint = runpod.Endpoint("sdxl") # Where "sdxl" is the endpoint ID

run_request = endpoint.run({
"input": {
"prompt": "a photo of a horse the size of a Boeing 787"
}
})
run_request = endpoint.run(
{"input": {"prompt": "a photo of a horse the size of a Boeing 787"}}
)

# Check the status of the run request
print(run_request.status())
Expand Down
12 changes: 4 additions & 8 deletions examples/endpoints/run_sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
"""
Example of calling an endpoint using the RunPod Python Language Library.
'''
"""

import runpod

Expand All @@ -12,12 +12,8 @@
try:
# Run the endpoint synchronously, blocking until the endpoint run is complete.
run_request = endpoint.run_sync(
{
"input": {
"prompt": "a photo of a horse the size of a Boeing 787"
}
},
timeout=60 # Seconds
{"input": {"prompt": "a photo of a horse the size of a Boeing 787"}},
timeout=60, # Seconds
)

print(run_request)
Expand Down
12 changes: 7 additions & 5 deletions examples/endpoints/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

endpoint = runpod.Endpoint("gwp4kx5yd3nur1")

run_request = endpoint.run({
"input": {
"mock_return": ["a", "b", "c", "d", "e", "f", "g"],
"mock_delay": 1,
run_request = endpoint.run(
{
"input": {
"mock_return": ["a", "b", "c", "d", "e", "f", "g"],
"mock_delay": 1,
}
}
})
)

for output in run_request.stream():
print(output)
6 changes: 3 additions & 3 deletions examples/graphql_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
''''
"""'
GraphQL wrapper for the RunPod API
'''
"""

import time
import runpod

import runpod

runpod.api_key = "YOUR_RUNPOD_API_KEY"

Expand Down
22 changes: 17 additions & 5 deletions examples/serverless/concurrent_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@

# ---------------------------------- Handler --------------------------------- #
async def async_generator_handler(job):
'''
"""
Async generator type handler.
'''
"""
return job


runpod.serverless.start({
"handler": async_generator_handler,
})
# --------------------------- Concurrency Modifier --------------------------- #
def concurrency_modifier(current_concurrency=1):
"""
Concurrency modifier.
"""
desired_concurrency = current_concurrency

# Do some logic to determine the desired concurrency.

return desired_concurrency


runpod.serverless.start(
{"handler": async_generator_handler, "concurrency_modifier": concurrency_modifier}
)
20 changes: 10 additions & 10 deletions examples/serverless/logger.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
""" Example of using the RunPodLogger class. """""
""" Example of using the RunPodLogger class. """ ""

import runpod

JOB_ID = '1234567890'
JOB_ID = "1234567890"
log = runpod.RunPodLogger()


log.debug('A debug message')
log.info('An info message')
log.warn('A warning message')
log.error('An error message')
log.debug("A debug message")
log.info("An info message")
log.warn("A warning message")
log.error("An error message")

# Output:
# DEBUG | A debug message
Expand All @@ -18,10 +18,10 @@
# ERROR | An error message


log.debug('A debug message', request_id=JOB_ID)
log.info('An info message', request_id=JOB_ID)
log.warn('A warning message', request_id=JOB_ID)
log.error('An error message', request_id=JOB_ID)
log.debug("A debug message", request_id=JOB_ID)
log.info("An info message", request_id=JOB_ID)
log.warn("A warning message", request_id=JOB_ID)
log.error("An error message", request_id=JOB_ID)

# Output:
# {"requestId": "1234567890", "message": "A debug message", "level": "DEBUG"}
Expand Down
2 changes: 1 addition & 1 deletion examples/serverless/simple_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def handler(job):
""" Simple handler """
"""Simple handler"""
job_input = job["input"]

return f"Hello {job_input['name']}!"
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pytest]
addopts = --durations=10 --cov-config=.coveragerc --timeout=120 --timeout_method=thread --cov=runpod --cov-report=xml --cov-report=term-missing --cov-fail-under=98 -W error -p no:cacheprovider -p no:unraisableexception
addopts = --durations=10 --cov-config=.coveragerc --timeout=120 --timeout_method=thread --cov=runpod --cov-report=xml --cov-report=term-missing --cov-fail-under=90 -W error -p no:cacheprovider -p no:unraisableexception
python_files = tests.py test_*.py *_test.py
norecursedirs = venv *.egg-info .git build
8 changes: 6 additions & 2 deletions runpod/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
""" Allows runpod to be imported as a module. """

import os
import logging
import os

from . import serverless
from .api.ctl_commands import (
create_container_registry_auth,
create_endpoint,
create_pod,
create_template,
delete_container_registry_auth,
get_endpoints,
get_gpu,
get_gpus,
Expand All @@ -18,6 +19,7 @@
resume_pod,
stop_pod,
terminate_pod,
update_container_registry_auth,
update_endpoint_template,
update_user_settings,
)
Expand All @@ -42,7 +44,9 @@
else:
api_key = None # pylint: disable=invalid-name

endpoint_url_base = os.environ.get("RUNPOD_ENDPOINT_BASE_URL", "https://api.runpod.ai/v2") # pylint: disable=invalid-name
endpoint_url_base = os.environ.get(
"RUNPOD_ENDPOINT_BASE_URL", "https://api.runpod.ai/v2"
) # pylint: disable=invalid-name


# --------------------------- Force Logging Levels --------------------------- #
Expand Down
2 changes: 1 addition & 1 deletion runpod/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
''' Allows api_wrapper to be imported as a module.'''
""" Allows api_wrapper to be imported as a module."""
36 changes: 36 additions & 0 deletions runpod/api/ctl_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
RunPod | API Wrapper | CTL Commands
"""

# pylint: disable=too-many-arguments,too-many-locals

from typing import Optional
Expand Down Expand Up @@ -370,3 +371,38 @@ def create_container_registry_auth(name: str, username: str, password: str):
)
)
return raw_response["data"]["saveRegistryAuth"]


def update_container_registry_auth(registry_auth_id: str, username: str, password: str):
"""
Update a container registry authentication.
Args:
registry_auth_id (str): The id of the container registry authentication
username (str): The username for authentication.
password (str): The password for authentication.
Returns:
dict: The response data containing the updated container registry authentication.
"""
raw_response = run_graphql_query(
container_register_auth_mutations.update_container_registry_auth(
registry_auth_id, username, password
)
)
return raw_response["data"]["updateRegistryAuth"]


def delete_container_registry_auth(registry_auth_id: str):
"""
Delete a container registry authentication.
Args:
registry_auth_id (str): The id of the container registry authentication
"""
raw_response = run_graphql_query(
container_register_auth_mutations.delete_container_registry_auth(
registry_auth_id
)
)
return raw_response["data"]["deleteRegistryAuth"]
Loading

0 comments on commit fbd1200

Please sign in to comment.