Skip to content

Commit

Permalink
Shrink the manylinux wheel files by not including two copies of PyTor…
Browse files Browse the repository at this point in the history
…ch and export the setup.py log to a file in a tempdir since pip refuses to allow it to print even in verbose mode
  • Loading branch information
AjayP13 committed Nov 4, 2018
1 parent d914b2b commit 3121088
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@
except BaseException:
from urllib import urlretrieve

# Redirect output to a file
tee = open(os.path.join(tempfile.gettempdir(), 'magnitude.install'), 'a+')


class TeeUnbuffered:
def __init__(self, stream):
self.stream = stream

def write(self, data):
self.stream.write(data)
self.stream.flush()
tee.write(data)


sys.stdout = TeeUnbuffered(sys.stdout)
sys.stderr = TeeUnbuffered(sys.stderr)

PACKAGE_NAME = 'pymagnitude'

# Setup path constants
Expand Down Expand Up @@ -293,6 +310,7 @@ def build_req_wheels():
('http://download.pytorch.org/whl/cpu/', 'torch', '0.4.1.post2')
]

pytorch_success = False
for wheelhouse, package, version in download_req_wheels:
for whl in get_supported_wheels(package, version):
exitcodes = []
Expand All @@ -302,6 +320,7 @@ def build_req_wheels():
try:
urlretrieve(whl_url, dl_path)
zip_ref = zipfile.ZipFile(dl_path, 'r')
pytorch_success = True
sys.stdout.write(" ...SUCCESS\n")
except BaseException:
if os.path.exists(dl_path):
Expand All @@ -311,14 +330,15 @@ def build_req_wheels():
sys.stdout.flush()

# Try torch from PyPI
rc2 = subprocess.Popen([
sys.executable,
'-m',
'pip',
'wheel',
'torch',
'--wheel-dir=pymagnitude/req_wheels'
], cwd=PROJ_PATH).wait()
if not pytorch_success:
rc2 = subprocess.Popen([
sys.executable,
'-m',
'pip',
'wheel',
'torch',
'--wheel-dir=pymagnitude/req_wheels'
], cwd=PROJ_PATH).wait()

if rc:
print("Failed to build requirements wheels!")
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = ('0', '1', '96')
__version_info__ = ('0', '1', '97')
__version__ = '.'.join(__version_info__)

0 comments on commit 3121088

Please sign in to comment.