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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ generate: install ## Generate the SDK from our public openapi spec


test-local: install ## Run integration tests against an API server running at http://localhost:8000/device-api (needs GROUNDLIGHT_API_TOKEN)
GROUNDLIGHT_TEST_API_ENDPOINT="http://localhost:8000/device-api" poetry run pytest --cov=src test --log-cli-level INFO
GROUNDLIGHT_ENDPOINT="http://localhost:8000/" poetry run pytest --cov=src test --log-cli-level INFO


test-integ: install ## Run integration tests against the integ API server (needs GROUNDLIGHT_API_TOKEN)
GROUNDLIGHT_TEST_API_ENDPOINT="https://api.integ.groundlight.ai/device-api" poetry run pytest --cov=src test --log-cli-level INFO
GROUNDLIGHT_ENDPOINT="https://api.integ.groundlight.ai/" poetry run pytest --cov=src test --log-cli-level INFO
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "groundlight"
version = "0.7.0"
version = "0.7.1"
license = "MIT"
readme = "README.md"
homepage = "https://www.groundlight.ai"
Expand Down
5 changes: 3 additions & 2 deletions src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class Groundlight:
POLLING_EXPONENTIAL_BACKOFF = 1.3 # This still has the nice backoff property that the max number of requests
# is O(log(time)), but with 1.3 the guarantee is that the call will return no more than 30% late

def __init__(self, endpoint: str = DEFAULT_ENDPOINT, api_token: str = None):
def __init__(self, endpoint: Optional[str] = None, api_token: str = None):
"""
:param endpoint: optionally specify a different endpoint
:param api_token: use this API token for your API calls. If unset, fallback to the
environment variable "GROUNDLIGHT_API_TOKEN".
"""
# Specify the endpoint
self.endpoint = sanitize_endpoint_url(endpoint)
configuration = Configuration(host=endpoint)
configuration = Configuration(host=self.endpoint)
Copy link
Member Author

@robotrapta robotrapta Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The missing self. here was actually the entirety of the bug. The rest of this PR is cleaning up tests and making it a bit more robust.


if api_token is None:
try:
Expand Down Expand Up @@ -201,6 +201,7 @@ def add_label(self, image_query: Union[ImageQuery, str], label: str):
image_query_id = image_query.id
else:
image_query_id = str(image_query)
# Some old imagequery id's started with "chk_"
if not (image_query_id.startswith("chk_") or image_query_id.startswith("iq_")):
raise ValueError(f"Invalid image query id {image_query_id}")
api_label = convert_display_label_to_internal(image_query_id, label)
Expand Down
4 changes: 1 addition & 3 deletions src/groundlight/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import os

API_TOKEN_WEB_URL = "https://app.groundlight.ai/reef/my-account/api-tokens"
API_TOKEN_VARIABLE_NAME = "GROUNDLIGHT_API_TOKEN"

DEFAULT_ENDPOINT = os.environ.get("GROUNDLIGHT_ENDPOINT", "https://api.groundlight.ai/")
DEFAULT_ENDPOINT = "https://api.groundlight.ai/"

__all__ = [
"API_TOKEN_WEB_URL",
Expand Down
10 changes: 9 additions & 1 deletion src/groundlight/internalapi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import logging
import os
import time
import uuid
from typing import Dict
from urllib.parse import urlsplit, urlunsplit
import uuid

from groundlight.config import DEFAULT_ENDPOINT

import model
import requests
Expand All @@ -17,6 +20,11 @@ def sanitize_endpoint_url(endpoint: str) -> str:
This allows people to leave that off entirely, or add a trailing slash.
Also some future-proofing by allowing "v1" or "v2" or "v3" paths.
"""
if not endpoint:
endpoint = os.environ.get("GROUNDLIGHT_ENDPOINT", "")
if not endpoint:
# Because sometimes people set an environment variable to a blank string by mistake
endpoint = "https://api.groundlight.ai/"
parts = urlsplit(endpoint)
if (parts.scheme not in ("http", "https")) or (not parts.netloc):
raise ValueError(
Expand Down
9 changes: 5 additions & 4 deletions test/integration/test_groundlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
@pytest.fixture
def gl() -> Groundlight:
"""Creates a Groundlight client object for testing."""
endpoint = os.environ.get("GROUNDLIGHT_TEST_API_ENDPOINT", "http://localhost:8000/device-api")
return Groundlight(endpoint=endpoint)
return Groundlight()


@pytest.fixture
Expand All @@ -26,7 +25,8 @@ def detector(gl: Groundlight) -> Detector:

@pytest.fixture
def image_query(gl: Groundlight, detector: Detector) -> ImageQuery:
return gl.submit_image_query(detector=detector.id, image="test/assets/dog.jpeg")
iq = gl.submit_image_query(detector=detector.id, image="test/assets/dog.jpeg")
return iq


def test_create_detector(gl: Groundlight):
Expand Down Expand Up @@ -121,7 +121,8 @@ def test_add_label_to_object(gl: Groundlight, image_query: ImageQuery):

def test_add_label_by_id(gl: Groundlight, image_query: ImageQuery):
iqid = image_query.id
assert iqid.startswith("chk_") # someday we'll probably change this to iq_
# TODO: Fully deprecate chk_ prefix
assert iqid.startswith("chk_") or iqid.startswith("iq_")
gl.add_label(iqid, "No")


Expand Down