Skip to content

Commit 5a85aeb

Browse files
author
rllin
authored
modify conftest and github actions and bump python version (#64)
* modify conftest and github actions * update * update tox * fix graphql url * remove default environ * fix * fix * fix * fix tests * update python to 3.7, 3.8 * 38
1 parent 7f59f8e commit 5a85aeb

File tree

7 files changed

+51
-36
lines changed

7 files changed

+51
-36
lines changed

.github/workflows/python-package.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,23 @@ jobs:
1414
strategy:
1515
max-parallel: 1
1616
matrix:
17-
python-version: [3.6, 3.7]
17+
python-version: [3.7, 3.8]
1818

1919
steps:
20+
21+
- name: Cancel previous workflow
22+
uses: styfle/cancel-workflow-action@0.4.0
23+
with:
24+
access_token: ${{ github.token }}
25+
26+
- name: set environment for branch
27+
run: |
28+
if [[ "${{github.base_ref}}" == "master" || "${{github.ref}}" == "refs/heads/master" ]]; then
29+
echo "::set-env name=LABELBOX_TEST_ENVIRON::prod"
30+
else
31+
echo "::set-env name=LABELBOX_TEST_ENVIRON::staging"
32+
fi
33+
2034
- uses: actions/checkout@v2
2135
with:
2236
token: ${{ secrets.ACTIONS_ACCESS_TOKEN }}
@@ -51,16 +65,11 @@ jobs:
5165
- name: Test with tox
5266
env:
5367
# make sure to tell tox to use these environs in tox.ini
54-
LABELBOX_TEST_API_KEY: ${{ secrets.LABELBOX_API_KEY }}
55-
LABELBOX_TEST_ENDPOINT: "https://api.labelbox.com/graphql"
56-
# TODO: create a staging environment (develop)
57-
# we only test against prod right now because the merges are right into
58-
# the main branch which is develop right now
59-
LABELBOX_TEST_ENVIRON: "prod"
6068
#
69+
# randall@labelbox.com
70+
LABELBOX_TEST_API_KEY_PROD: ${{ secrets.LABELBOX_API_KEY }}
71+
6172
# randall+staging-python@labelbox.com
62-
#LABELBOX_TEST_API_KEY: ${{ secrets.STAGING_LABELBOX_API_KEY }}
63-
#LABELBOX_TEST_ENDPOINT: "https://staging-api.labelbox.com/graphql"
64-
#LABELBOX_TEST_ENVIRON: "staging"
73+
LABELBOX_TEST_API_KEY_STAGING: ${{ secrets.STAGING_LABELBOX_API_KEY }}
6574
run: |
6675
tox -- -svv

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ build:
55
test-staging: build
66
docker run -it -v ${PWD}:/usr/src -w /usr/src \
77
-e LABELBOX_TEST_ENVIRON="staging" \
8-
-e LABELBOX_TEST_ENDPOINT="https://staging-api.labelbox.com/graphql" \
9-
-e LABELBOX_TEST_API_KEY="<REPLACE>" \
10-
local/labelbox-python:test pytest $(PATH_TO_TEST)
8+
-e LABELBOX_TEST_API_KEY_STAGING="<REPLACE>" \
9+
local/labelbox-python:test pytest $(PATH_TO_TEST) -svvx
1110

1211
test-prod: build
1312
docker run -it -v ${PWD}:/usr/src -w /usr/src \
1413
-e LABELBOX_TEST_ENVIRON="prod" \
15-
-e LABELBOX_TEST_ENDPOINT="https://api.labelbox.com/graphql" \
16-
-e LABELBOX_TEST_API_KEY="<REPLACE>" \
17-
local/labelbox-python:test pytest $(PATH_TO_TEST)
14+
-e LABELBOX_TEST_API_KEY_PROD="<REPLACE>" \
15+
local/labelbox-python:test pytest $(PATH_TO_TEST) -svvx

labelbox/schema/project.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ def labeler_performance(self):
161161

162162
def create_labeler_performance(client, result):
163163
result["user"] = Entity.User(client, result["user"])
164-
result["lastActivityTime"] = datetime.fromtimestamp(
165-
result["lastActivityTime"] / 1000, timezone.utc)
164+
# python isoformat doesn't accept Z as utc timezone
165+
result["lastActivityTime"] = datetime.fromisoformat(
166+
result["lastActivityTime"].replace('Z', '+00:00'))
166167
return LabelerPerformance(
167168
**
168169
{utils.snake_case(key): value for key, value in result.items()})

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
'Development Status :: 3 - Alpha',
2424
'License :: OSI Approved :: Apache Software License',
2525
'Programming Language :: Python :: 3',
26-
'Programming Language :: Python :: 3.6',
2726
'Programming Language :: Python :: 3.7',
27+
'Programming Language :: Python :: 3.8',
2828
],
29+
python_requires='>=3.7',
2930
keywords=["labelbox"],
3031
)

tests/integration/conftest.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,27 @@ def environ() -> Environ:
2929
"""
3030
try:
3131
return Environ(os.environ['LABELBOX_TEST_ENVIRON'])
32-
# TODO: for some reason all other environs can be set but
33-
# this one cannot in github actions
34-
#return Environ.PROD
3532
except KeyError:
3633
raise Exception(f'Missing LABELBOX_TEST_ENVIRON in: {os.environ}')
3734

3835

36+
def graphql_url(environ: str) -> str:
37+
if environ == Environ.PROD:
38+
return 'https://api.labelbox.com/graphql'
39+
return 'https://staging-api.labelbox.com/graphql'
40+
41+
42+
def testing_api_key(environ: str) -> str:
43+
if environ == Environ.PROD:
44+
return os.environ["LABELBOX_TEST_API_KEY_PROD"]
45+
return os.environ["LABELBOX_TEST_API_KEY_STAGING"]
46+
47+
3948
class IntegrationClient(Client):
4049

41-
def __init__(self):
42-
api_url = os.environ["LABELBOX_TEST_ENDPOINT"]
43-
api_key = os.environ["LABELBOX_TEST_API_KEY"]
44-
#"https://staging-api.labelbox.com/graphql")
50+
def __init__(self, environ: str) -> None:
51+
api_url = graphql_url(environ)
52+
api_key = testing_api_key(environ)
4553
super().__init__(api_key, api_url)
4654

4755
self.queries = []
@@ -54,8 +62,8 @@ def execute(self, query, params=None, check_naming=True, **kwargs):
5462

5563

5664
@pytest.fixture
57-
def client():
58-
return IntegrationClient()
65+
def client(environ: str):
66+
return IntegrationClient(environ)
5967

6068

6169
@pytest.fixture
@@ -105,10 +113,9 @@ def label_pack(project, rand_gen):
105113

106114
@pytest.fixture
107115
def iframe_url(environ) -> str:
108-
return {
109-
Environ.PROD: 'https://editor.labelbox.com',
110-
Environ.STAGING: 'https://staging-editor.labelbox.com',
111-
}[environ]
116+
if environ == Environ.PROD:
117+
return 'https://editor.labelbox.com'
118+
return 'https://staging.labelbox.dev/editor'
112119

113120

114121
@pytest.fixture

tests/integration/test_project_setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def simple_ontology():
2424

2525

2626
def test_project_setup(project, iframe_url) -> None:
27-
2827
client = project.client
2928
labeling_frontends = list(
3029
client.get_labeling_frontends(

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# content of: tox.ini , put in same dir as setup.py
22
[tox]
3-
envlist = py36, py37
3+
envlist = py37, py38
44

55
[gh-actions]
66
python =
7-
3.6: py36
87
3.7: py37
8+
3.8: py38
99

1010
[testenv]
1111
# install pytest in the virtualenv where commands will be executed
1212
deps =
1313
-rrequirements.txt
1414
pytest
15-
passenv = LABELBOX_TEST_ENDPOINT LABELBOX_TEST_API_KEY LABELBOX_TEST_ENVIRON
15+
passenv = LABELBOX_TEST_API_KEY_PROD LABELBOX_TEST_API_KEY_STAGING LABELBOX_TEST_ENVIRON
1616
commands = pytest {posargs}

0 commit comments

Comments
 (0)