diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 9b7da90fb..377e8c4a9 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -14,9 +14,23 @@ jobs: strategy: max-parallel: 1 matrix: - python-version: [3.6, 3.7] + python-version: [3.7, 3.8] steps: + + - name: Cancel previous workflow + uses: styfle/cancel-workflow-action@0.4.0 + with: + access_token: ${{ github.token }} + + - name: set environment for branch + run: | + if [[ "${{github.base_ref}}" == "master" || "${{github.ref}}" == "refs/heads/master" ]]; then + echo "::set-env name=LABELBOX_TEST_ENVIRON::prod" + else + echo "::set-env name=LABELBOX_TEST_ENVIRON::staging" + fi + - uses: actions/checkout@v2 with: token: ${{ secrets.ACTIONS_ACCESS_TOKEN }} @@ -51,16 +65,11 @@ jobs: - name: Test with tox env: # make sure to tell tox to use these environs in tox.ini - LABELBOX_TEST_API_KEY: ${{ secrets.LABELBOX_API_KEY }} - LABELBOX_TEST_ENDPOINT: "https://api.labelbox.com/graphql" - # TODO: create a staging environment (develop) - # we only test against prod right now because the merges are right into - # the main branch which is develop right now - LABELBOX_TEST_ENVIRON: "prod" # + # randall@labelbox.com + LABELBOX_TEST_API_KEY_PROD: ${{ secrets.LABELBOX_API_KEY }} + # randall+staging-python@labelbox.com - #LABELBOX_TEST_API_KEY: ${{ secrets.STAGING_LABELBOX_API_KEY }} - #LABELBOX_TEST_ENDPOINT: "https://staging-api.labelbox.com/graphql" - #LABELBOX_TEST_ENVIRON: "staging" + LABELBOX_TEST_API_KEY_STAGING: ${{ secrets.STAGING_LABELBOX_API_KEY }} run: | tox -- -svv diff --git a/Makefile b/Makefile index 3a32aebcf..60ceb6697 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,11 @@ build: test-staging: build docker run -it -v ${PWD}:/usr/src -w /usr/src \ -e LABELBOX_TEST_ENVIRON="staging" \ - -e LABELBOX_TEST_ENDPOINT="https://staging-api.labelbox.com/graphql" \ - -e LABELBOX_TEST_API_KEY="" \ - local/labelbox-python:test pytest $(PATH_TO_TEST) + -e LABELBOX_TEST_API_KEY_STAGING="" \ + local/labelbox-python:test pytest $(PATH_TO_TEST) -svvx test-prod: build docker run -it -v ${PWD}:/usr/src -w /usr/src \ -e LABELBOX_TEST_ENVIRON="prod" \ - -e LABELBOX_TEST_ENDPOINT="https://api.labelbox.com/graphql" \ - -e LABELBOX_TEST_API_KEY="" \ - local/labelbox-python:test pytest $(PATH_TO_TEST) + -e LABELBOX_TEST_API_KEY_PROD="" \ + local/labelbox-python:test pytest $(PATH_TO_TEST) -svvx diff --git a/labelbox/schema/project.py b/labelbox/schema/project.py index d32ca6be1..9ebb0b43f 100644 --- a/labelbox/schema/project.py +++ b/labelbox/schema/project.py @@ -161,8 +161,9 @@ def labeler_performance(self): def create_labeler_performance(client, result): result["user"] = Entity.User(client, result["user"]) - result["lastActivityTime"] = datetime.fromtimestamp( - result["lastActivityTime"] / 1000, timezone.utc) + # python isoformat doesn't accept Z as utc timezone + result["lastActivityTime"] = datetime.fromisoformat( + result["lastActivityTime"].replace('Z', '+00:00')) return LabelerPerformance( ** {utils.snake_case(key): value for key, value in result.items()}) diff --git a/setup.py b/setup.py index cf5b1931c..a5f4cbb0c 100644 --- a/setup.py +++ b/setup.py @@ -23,8 +23,9 @@ 'Development Status :: 3 - Alpha', 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', ], + python_requires='>=3.7', keywords=["labelbox"], ) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 71ef87186..0aeab7d53 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -29,19 +29,27 @@ def environ() -> Environ: """ try: return Environ(os.environ['LABELBOX_TEST_ENVIRON']) - # TODO: for some reason all other environs can be set but - # this one cannot in github actions - #return Environ.PROD except KeyError: raise Exception(f'Missing LABELBOX_TEST_ENVIRON in: {os.environ}') +def graphql_url(environ: str) -> str: + if environ == Environ.PROD: + return 'https://api.labelbox.com/graphql' + return 'https://staging-api.labelbox.com/graphql' + + +def testing_api_key(environ: str) -> str: + if environ == Environ.PROD: + return os.environ["LABELBOX_TEST_API_KEY_PROD"] + return os.environ["LABELBOX_TEST_API_KEY_STAGING"] + + class IntegrationClient(Client): - def __init__(self): - api_url = os.environ["LABELBOX_TEST_ENDPOINT"] - api_key = os.environ["LABELBOX_TEST_API_KEY"] - #"https://staging-api.labelbox.com/graphql") + def __init__(self, environ: str) -> None: + api_url = graphql_url(environ) + api_key = testing_api_key(environ) super().__init__(api_key, api_url) self.queries = [] @@ -54,8 +62,8 @@ def execute(self, query, params=None, check_naming=True, **kwargs): @pytest.fixture -def client(): - return IntegrationClient() +def client(environ: str): + return IntegrationClient(environ) @pytest.fixture @@ -105,10 +113,9 @@ def label_pack(project, rand_gen): @pytest.fixture def iframe_url(environ) -> str: - return { - Environ.PROD: 'https://editor.labelbox.com', - Environ.STAGING: 'https://staging-editor.labelbox.com', - }[environ] + if environ == Environ.PROD: + return 'https://editor.labelbox.com' + return 'https://staging.labelbox.dev/editor' @pytest.fixture diff --git a/tests/integration/test_project_setup.py b/tests/integration/test_project_setup.py index 0f4aef300..d14b720ac 100644 --- a/tests/integration/test_project_setup.py +++ b/tests/integration/test_project_setup.py @@ -24,7 +24,6 @@ def simple_ontology(): def test_project_setup(project, iframe_url) -> None: - client = project.client labeling_frontends = list( client.get_labeling_frontends( diff --git a/tox.ini b/tox.ini index 2e976c259..709763dea 100644 --- a/tox.ini +++ b/tox.ini @@ -1,16 +1,16 @@ # content of: tox.ini , put in same dir as setup.py [tox] -envlist = py36, py37 +envlist = py37, py38 [gh-actions] python = - 3.6: py36 3.7: py37 + 3.8: py38 [testenv] # install pytest in the virtualenv where commands will be executed deps = -rrequirements.txt pytest -passenv = LABELBOX_TEST_ENDPOINT LABELBOX_TEST_API_KEY LABELBOX_TEST_ENVIRON +passenv = LABELBOX_TEST_API_KEY_PROD LABELBOX_TEST_API_KEY_STAGING LABELBOX_TEST_ENVIRON commands = pytest {posargs}