Skip to content

Commit 2ce2814

Browse files
committed
Separate py2 and py3 uploaders, get tests working!
Finish verification code Add Python 3.7 test Increase verobosity in integration test Fix python 2/3 cmp() function problem Debug python version comparison Continue to debug python versions Finished test! Add test for latest python version Add linux 3.6.5 Improve test naming Make universal package Modify asset print Attempting to debug python 2.7 Add more debugging for py 2.7 Improve debug verbosity Remove debugging for uploader Seperate py2 and py3 uploaders Remove version limitations Remove extraneous print and add cleanup task Add python version to Frame.io folder name Try again with new assets
1 parent 0de9fad commit 2ce2814

6 files changed

Lines changed: 229 additions & 45 deletions

File tree

.circleci/config.yml

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,39 @@ workflows:
99
jobs:
1010
- build
1111

12-
- windows_py_27:
12+
- linux_py_27:
1313
requires:
1414
- build
1515

16-
# - mac_py_27:
17-
# requires:
18-
# - build
16+
- linux_py_37:
17+
requires:
18+
- build
19+
20+
- linux_py_365:
21+
requires:
22+
- build
23+
24+
- linux_py_latest:
25+
requires:
26+
- build
1927

2028
# - windows_py_38:
2129
# requires:
2230
# - build
31+
2332
# - mac_py_38:
2433
# requires:
2534
# - build
2635

2736
- deploy:
2837
requires:
29-
- windows_py_27
30-
# - mac_py_27
38+
- linux_py_27
39+
- linux_py_365
40+
- linux_py_37
41+
- linux_py_latest
3142
# - windows_py_38
3243
# - mac_py_38
44+
3345
filters:
3446
branches:
3547
only:
@@ -58,7 +70,7 @@ jobs:
5870
echo -e "Running sdist"
5971
python setup.py sdist
6072
echo -e "Creating wheel"
61-
python setup.py bdist_wheel
73+
python setup.py bdist_wheel --universal
6274
6375
# - store_artifacts:
6476
# path: /home/circleci/project/
@@ -69,7 +81,8 @@ jobs:
6981
paths:
7082
- .
7183

72-
windows_py_27:
84+
linux_py_27:
85+
description: Linux 2.7.17
7386
docker:
7487
- image: circleci/python:2.7.17
7588

@@ -88,6 +101,69 @@ jobs:
88101
command: |
89102
python /tmp/artifact/tests/integration.py
90103
104+
linux_py_365:
105+
description: Linux 3.6.5
106+
docker:
107+
- image: circleci/python:3.6.5
108+
109+
steps:
110+
- attach_workspace:
111+
at: /tmp/artifact
112+
name: Attach build artifact
113+
114+
- run:
115+
name: Install package
116+
command: |
117+
pip install '/tmp/artifact'
118+
119+
- run:
120+
name: Run integration test
121+
command: |
122+
python /tmp/artifact/tests/integration.py
123+
124+
125+
linux_py_37:
126+
description: Linux 3.7.7
127+
docker:
128+
- image: circleci/python:3.7.7
129+
130+
steps:
131+
- attach_workspace:
132+
at: /tmp/artifact
133+
name: Attach build artifact
134+
135+
- run:
136+
name: Install package
137+
command: |
138+
pip install '/tmp/artifact'
139+
140+
- run:
141+
name: Run integration test
142+
command: |
143+
python /tmp/artifact/tests/integration.py
144+
145+
146+
linux_py_latest:
147+
description: Linux latest
148+
docker:
149+
- image: circleci/python:latest
150+
151+
steps:
152+
- attach_workspace:
153+
at: /tmp/artifact
154+
name: Attach build artifact
155+
156+
- run:
157+
name: Install package
158+
command: |
159+
pip install '/tmp/artifact'
160+
161+
- run:
162+
name: Run integration test
163+
command: |
164+
python /tmp/artifact/tests/integration.py
165+
166+
91167
deploy:
92168
docker:
93169
- image: circleci/python:latest

frameioclient/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import sys
12
import requests
2-
from .upload import FrameioUploader
33
from requests.adapters import HTTPAdapter
44
from requests.packages.urllib3.util.retry import Retry
55
from .download import FrameioDownloader
66

7+
if sys.version_info.major >= 3:
8+
from .py3_uploader import FrameioUploader
9+
else:
10+
from .py2_uploader import FrameioUploader
11+
712
class PaginatedResponse(object):
813
def __init__(self, results=[], page=0, page_size=0, total=0, total_pages=0):
914
super(PaginatedResponse, self).__init__()
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ def upload(self):
2828
size = int(math.ceil(total_size / len(upload_urls)))
2929

3030
for i, chunk in enumerate(self._read_chunk(self.file, size)):
31-
proc = Process(target=self._upload_chunk, args=(upload_urls[i], chunk,))
32-
procs.append(proc)
33-
proc.start()
31+
try:
32+
proc = Process(target=self._upload_chunk, args=(upload_urls[i], chunk))
33+
procs.append(proc)
34+
proc.start()
35+
except IndexError:
36+
# In python 2.7 the _read_chunk function sometimes keeps going \
37+
# past where it should, this prevents that.
38+
pass
3439

3540
for proc in procs:
3641
proc.join()

frameioclient/py3_uploader.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import requests
2+
import math
3+
import concurrent.futures
4+
import threading
5+
6+
thread_local = threading.local()
7+
8+
class FrameioUploader(object):
9+
def __init__(self, asset, file):
10+
self.asset = asset
11+
self.file = file
12+
13+
def _read_chunk(self, file, size):
14+
while True:
15+
data = file.read(size)
16+
if not data:
17+
break
18+
yield data
19+
20+
def _get_session(self):
21+
if not hasattr(thread_local, "session"):
22+
thread_local.session = requests.Session()
23+
return thread_local.session
24+
25+
def _upload_chunk(self, task):
26+
url = task[0]
27+
chunk = task[1]
28+
session = self._get_session()
29+
30+
session.put(url, data=chunk, headers={
31+
'content-type': self.asset['filetype'],
32+
'x-amz-acl': 'private'
33+
})
34+
35+
def upload(self):
36+
total_size = self.asset['filesize']
37+
upload_urls = self.asset['upload_urls']
38+
size = int(math.ceil(total_size / len(upload_urls)))
39+
40+
tasks = []
41+
42+
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
43+
for i, chunk in enumerate(self._read_chunk(self.file, size)):
44+
task = (upload_urls[i], chunk)
45+
tasks.append(task)
46+
47+
executor.map(self._upload_chunk, tasks)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def run(self):
2525
setuptools.setup(
2626
name='frameioclient',
2727
version=version,
28-
python_requires='>=2.6, !=3.8.*, <4',
28+
python_requires='>=2.6',
2929
install_requires=[
3030
'requests',
3131
'urllib3',

0 commit comments

Comments
 (0)