Last active
May 24, 2019 23:35
-
-
Save dgnsrekt/a9ee00cd65d4a548e4178657c14ecc81 to your computer and use it in GitHub Desktop.
Download and start a redis server within your python project with nox.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nox | |
from pathlib import Path | |
PROJECT_ROOT_DIRECTORY = Path(__file__).parent | |
REDIS_DIRECTORY = PROJECT_ROOT_DIRECTORY / "redis-stable" | |
REDIS_COMPRESSED_FILE_NAME = "redis-stable.tar.gz" | |
REDIS_DOWNLOAD_URL = "http://download.redis.io/" + REDIS_COMPRESSED_FILE_NAME | |
REDIS_SERVER_LOCATION = REDIS_DIRECTORY / "src" / "redis-server" | |
@nox.session(python=False) | |
def redis(session): | |
""" | |
Downloads and runs a redis server. 'nox -- runsever' to spin a redis server | |
""" | |
if not REDIS_SERVER_LOCATION.exists(): | |
session.run("wget", "--verbose", "--no-clobber", REDIS_DOWNLOAD_URL, external=True) | |
session.run("tar", "-xzf", REDIS_COMPRESSED_FILE_NAME, external=True) | |
session.run("rm", REDIS_COMPRESSED_FILE_NAME, external=True) | |
session.cd(REDIS_DIRECTORY) | |
session.run("make", external=True) | |
assert REDIS_SERVER_LOCATION.exists(), "Something went wrong..." | |
if session.posargs[0] == "runserver": | |
session.run(str(REDIS_SERVER_LOCATION)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run the following to spin up a redis server