Skip to content

Commit

Permalink
Fix #10.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Daily committed Sep 29, 2017
1 parent 1f05a63 commit 55090dc
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 61 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Unreleased_
-----------
The Unreleased section will be empty for tagged releases. Unreleased functionality appears in the develop branch.

- Change setup.py install command to also download/build shared library.
Previously it was only the bdist_wheel command that would do so.
- Close #10. OSError: libparasail.so: cannot open shared object file:
No such file or directory.

-------------------
1.1.5_ - 2017-09-29
-------------------
Expand Down
136 changes: 75 additions & 61 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from distutils.util import get_platform
from setuptools import setup
from wheel.bdist_wheel import bdist_wheel as bdist_wheel_

from setuptools.command.install import install as install_

###############################################################################

Expand Down Expand Up @@ -174,7 +174,7 @@ def build_parasail(libname):
else:
print("parasail archive executable permissions ok")

if find_file('config.status') is None:
if find_file('config.status', root) is None:
print("configuring parasail in directory {}".format(root))
# force universal/fat build in OSX via CFLAGS env var
if platform.system() == "Darwin":
Expand All @@ -189,7 +189,7 @@ def build_parasail(libname):
else:
print("parasail already configured in directory {}".format(root))

if find_file(libname) is None:
if find_file(libname, root) is None:
print("making parasail")
retcode = subprocess.Popen([
'make',
Expand Down Expand Up @@ -218,65 +218,73 @@ def github_api_json(address):
data = json.loads(response.read())
return data

def download_windows_dll():
print("Downloading latest parasail release info from github")
address = "https://api.github.com/repos/jeffdaily/parasail/releases/latest"
data = None
for attempt in range(10):
try:
data = github_api_json(address)
if not data or 'assets' not in data:
raise RuntimeError("Unable to download github asset JSON from "+address)
except Exception as e:
print(repr(e))
print("Will retry in 5 seconds")
time.sleep(5)
else:
break
else:
# we failed all the attempts - deal with the consequences.
raise RuntimeError("All attempts to download github asset JSON have failed")
asset = None
search = "win32-v140"
if is_python_64bit():
search = "win64-v140"
for maybe_asset in data['assets']:
if search in maybe_asset['browser_download_url']:
asset = maybe_asset['browser_download_url']
break
if not asset:
raise RuntimeError("Unable to determine asset URL")
print("Downloading latest parasail release {}".format(asset))
archive = asset.rsplit('/',1)[-1]
for attempt in range(10):
try:
name,hdrs = urlretrieve(asset, archive)
except Exception as e:
print(repr(e))
print("Will retry in 5 seconds")
time.sleep(5)
else:
break
else:
# we failed all the attempts - deal with the consequences.
raise RuntimeError("All attempts to download asset URL have failed")
destdir = archive.rsplit('.',1)[0]
print("Unzipping {}".format(archive))
unzip(archive, destdir)
print("Locating {}".format(libname))
root = find_file(libname)
src = os.path.join(root, libname)
dst = 'parasail'
print("copying {} to {}".format(src,dst))
shutil.copy(src,dst)

def prepare_shared_lib():
libname = get_libname()
libpath = os.path.join("parasail", libname)
if not os.path.exists(libpath):
print("{} not found, attempting to build".format(libpath))
if platform.system() == "Windows":
download_windows_dll()
else:
build_parasail(libname)
if not os.path.exists(libpath):
raise RuntimeError("Unable to find shared library {}.".format(libname))

class bdist_wheel(bdist_wheel_):
def run(self):
libname = get_libname()
if not os.path.exists(os.path.join("parasail", libname)):
if platform.system() == "Windows":
print("Downloading latest parasail release info from github")
address = "https://api.github.com/repos/jeffdaily/parasail/releases/latest"
data = None
for attempt in range(10):
try:
data = github_api_json(address)
if not data or 'assets' not in data:
raise RuntimeError("Unable to download github asset JSON from "+address)
except Exception as e:
print(repr(e))
print("Will retry in 5 seconds")
time.sleep(5)
else:
break
else:
# we failed all the attempts - deal with the consequences.
raise RuntimeError("All attempts to download github asset JSON have failed")
asset = None
search = "win32-v140"
if is_python_64bit():
search = "win64-v140"
for maybe_asset in data['assets']:
if search in maybe_asset['browser_download_url']:
asset = maybe_asset['browser_download_url']
break
if not asset:
raise RuntimeError("Unable to determine asset URL")
print("Downloading latest parasail release {}".format(asset))
archive = asset.rsplit('/',1)[-1]
for attempt in range(10):
try:
name,hdrs = urlretrieve(asset, archive)
except Exception as e:
print(repr(e))
print("Will retry in 5 seconds")
time.sleep(5)
else:
break
else:
# we failed all the attempts - deal with the consequences.
raise RuntimeError("All attempts to download asset URL have failed")
destdir = archive.rsplit('.',1)[0]
print("Unzipping {}".format(archive))
unzip(archive, destdir)
print("Locating {}".format(libname))
root = find_file(libname)
src = os.path.join(root, libname)
dst = 'parasail'
print("copying {} to {}".format(src,dst))
shutil.copy(src,dst)
else:
build_parasail(libname)
if not os.path.exists(os.path.join("parasail", libname)):
raise RuntimeError("Unable to find shared library {lib}.".format(lib=libname))
prepare_shared_lib()
bdist_wheel_.run(self)

def finalize_options(self):
Expand All @@ -285,6 +293,12 @@ def finalize_options(self):
self.plat_name_supplied = True
self.plat_name = get_platform()

class install(install_):
def run(self):
prepare_shared_lib()
install_.run(self)


if __name__ == "__main__":
long_description = ""
try:
Expand All @@ -305,7 +319,7 @@ def finalize_options(self):
keywords=KEYWORDS,
packages=PACKAGES,
package_data={"parasail": [get_libname()]},
cmdclass={'bdist_wheel': bdist_wheel},
cmdclass={'bdist_wheel': bdist_wheel, 'install': install},
zip_safe=False,
classifiers=CLASSIFIERS,
install_requires=INSTALL_REQUIRES,
Expand Down

0 comments on commit 55090dc

Please sign in to comment.