diff --git a/.travis.yml b/.travis.yml index 2ce3d76c07a839f419c88e995d309b045c57d458..b9daa5fc00e8cd5a26785087ae5d6335c04da25c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,9 @@ python: - "3.3" # - "pypy" # Travis only has PyPy 1.9, cffi requires 2.0 (Unreleased) install: - - sudo apt-get -q install python-pip - - sudo /usr/bin/pip -q install git+git://github.com/pyinvoke/invoke.git - - invoke install.sodium - - invoke install.requirements --dev + - pip install invoke + - pip install file://$PWD#egg=pynacl[tests] + - invoke sodium.install script: - invoke tests env: diff --git a/nacl/invoke/__init__.py b/nacl/invoke/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/nacl/invoke/sodium.py b/nacl/invoke/sodium.py new file mode 100644 index 0000000000000000000000000000000000000000..58be064b5078314ef310f900ad21b4be5bf05341 --- /dev/null +++ b/nacl/invoke/sodium.py @@ -0,0 +1,49 @@ +import hashlib +import os + +try: + from urllib.request import urlopen +except ImportError: + from urllib2 import urlopen + +from invoke import task, run + +LIBSODIUM_VERSION = "0.3" +LIBSODIUM_URL = "http://download.dnscrypt.org/libsodium/releases/libsodium-0.3.tar.gz" +LIBSODIUM_HASH = b"908a26f84bedb432305c81ec6773aa95b8e724ba2ece6234840685a74e033750" + + +@task +def install(): + path = os.path.expanduser("~/libsodium-%s.tar.gz" % LIBSODIUM_VERSION) + + # Download libsodium and verify it's hash + resp = urlopen(LIBSODIUM_URL) + content = resp.read() + content_hash = hashlib.sha256(content).hexdigest() + + # Verify our content matches the expected hash + if content_hash != LIBSODIUM_HASH: + raise ValueError("Hash mismatch for downloaded sodium") + + # Write out the tarball + with open(path, "wb") as fp: + fp.write(content) + + curdir = os.getcwd() + try: + os.chdir(os.path.expanduser("~/")) + + # Unpack the tarball + run("tar xf libsodium-%s.tar.gz" % LIBSODIUM_VERSION) + + # Configure and install the library + os.chdir(os.path.expanduser("~/libsodium-%s/" % LIBSODIUM_VERSION)) + + run("./configure --disable-debug --disable-dependency-tracking", + hide="out", + ) + run("make", hide="out") + run("sudo make install", hide="out") + finally: + os.chdir(curdir) diff --git a/setup.py b/setup.py index 9cec5549817afac347c1f35b1c769054a37b4e3f..e4c8e55d342b8469b83c1521afcc04062026e3e9 100644 --- a/setup.py +++ b/setup.py @@ -50,6 +50,7 @@ setup( packages=[ "nacl", + "nacl.invoke", ], ext_package="nacl", diff --git a/tasks.py b/tasks.py index 5a12552698707664e577c6400af34e9807024380..1e42d4b90aa2728f2f561f41d7d254219fad7682 100644 --- a/tasks.py +++ b/tasks.py @@ -1,68 +1,12 @@ -import hashlib -import os -import urllib2 +from invoke import Collection, task, run -from invoke import task, run +from nacl.invoke import sodium - -LIBSODIUM_VERSION = "0.3" -LIBSODIUM_URL = "http://download.dnscrypt.org/libsodium/releases/libsodium-0.3.tar.gz" -LIBSODIUM_HASH = b"908a26f84bedb432305c81ec6773aa95b8e724ba2ece6234840685a74e033750" -LIBSODIUM_AUTOGEN = False - - -@task(aliases=["install.sodium"]) -def install_sodium(): - tarball_path = os.path.expanduser( - "~/libsodium-{}.tar.gz".format(LIBSODIUM_VERSION), - ) - - # Download libsodium and verify it's hash - resp = urllib2.urlopen(LIBSODIUM_URL) - content = resp.read() - content_hash = hashlib.sha256(content).hexdigest() - - if content_hash != LIBSODIUM_HASH: - raise ValueError("Hash mismatch for downloaded libsodium") - - with open(tarball_path, "wb") as fp: - fp.write(content) - - curdir = os.getcwd() - try: - os.chdir(os.path.expanduser("~/")) - - # Unpack the tarball - run("tar xf libsodium-{}.tar.gz".format(LIBSODIUM_VERSION)) - - # Configure and install the library - os.chdir(os.path.expanduser( - "~/libsodium-{}/".format(LIBSODIUM_VERSION), - )) - - if LIBSODIUM_AUTOGEN: - run("./autogen.sh", hide="out") - - run("./configure --disable-debug --disable-dependency-tracking", - hide="out", - ) - run("make", hide="out") - run("sudo make install", hide="out") - finally: - os.chdir(curdir) - - -@task(aliases=["install.requirements"]) -def install_requirements(dev=False): - if dev: - # Install once to get the tests extra - run("pip install file://$PWD#egg=pynacl[tests]") - # Install again to get an editable install - run("pip install -e .") - else: - run("pip install .") +ns = Collection() +ns.add_collection(sodium) +@ns.add_task @task def tests(): run("py.test")