Skip to content

Commit

Permalink
renaming warmup to uranium
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Jan 19, 2015
1 parent 39478a7 commit a5c3edb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
19 changes: 9 additions & 10 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ For the purpose of the tutorial, let's create a root directory:
$ mkdir -p /tmp/uranium-tut/ && cd /tmp/uranium-tut/
We first start by downloading the warmup. Warmup is a python script that handles the following:
We first start by downloading uranium. uranium is a python wrapper around the uranium library that handles the following:

* downloading and setting up a virtualenv
* installing the uranium script into the virtualenv
* running uranium for the first time.

You can get the warmup script here:
You can get the uranium script here:

https://raw.githubusercontent.com/toumorokoshi/uranium/master/scripts/warmup
https://raw.githubusercontent.com/toumorokoshi/uranium/master/scripts/uranium

You should download a copy and add the script into the root directory:

.. code-block:: bash
$ curl -s https://raw.githubusercontent.com/toumorokoshi/uranium/master/scripts/warmup > warmup
$ chmod +x warmup # the script should be executable.
$ curl -s https://raw.githubusercontent.com/toumorokoshi/uranium/master/scripts/uranium > uranium
$ chmod +x uranium # the script should be executable.
Now you need a uranium.yaml file. Let's make one now:

$ touch uranium.yaml

This is all you need to run warmup. Let's run them now:
This is all you need to run uranium. Let's run them now:

$ ./warmup
$ ./uranium

And congrats, you've had your first Uranium run! Of course, all this
did was run virtualend and install Uranium. Now let's get some real
Expand All @@ -60,10 +60,9 @@ you can add a couple new section to the uranium file:
eggs:
nose: ==1.3.4
And let's run uranium again. Now that you've 'warmed up', you don't have to run
warmup again, instead, you can run:
And let's run uranium again:

$ ./bin/uranium
$ ./uranium

You should see:

Expand Down
37 changes: 34 additions & 3 deletions scripts/warmup → scripts/uranium
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,34 @@ try:
except:
from urllib.request import urlopen as urlopen

try:
from io import StringIO
except:
from StringIO import StringIO

LOGGER = logging.getLogger(__name__)

parser = argparse.ArgumentParser()
parser.add_argument("--no-uranium", help="don't install uranium.",
action="store_false", dest="with_uranium")

URANIUM_TARGET = ".uranium"


def main(argv):
args = parser.parse_args(argv)

install_dir = os.path.abspath(os.curdir)
current_dir = os.getcwd()
install_dir = os.path.join(current_dir, URANIUM_TARGET)

LOGGER.info("installing virtualenv...")
_install_virtualenv(install_dir)

LOGGER.info("activating virtualenv...")
_activate_virtualenv(install_dir)

os.chdir(current_dir)

if args.with_uranium:
LOGGER.info("installing uranium...")
_install_uranium(install_dir)
Expand All @@ -51,6 +61,9 @@ def main(argv):


def _install_virtualenv(install_dir):
if _is_virtualenv(install_dir):
return

temp_dir = tempfile.mkdtemp()
try:
_download_virtualenv(temp_dir)
Expand All @@ -63,14 +76,17 @@ def _install_virtualenv(install_dir):
'--no-site-packages',
'--always-copy',
install_dir])
os.chdir(install_dir)
finally:
shutil.rmtree(temp_dir)


def _install_uranium(virtualenv_dir):
log_file = os.path.join(virtualenv_dir, 'uranium_install_log.txt')
pip_executable = os.path.join(virtualenv_dir, 'bin', 'pip')
subprocess.call([pip_executable, 'install', 'uranium'])

with open(log_file, 'w+') as fh:
subprocess.call([pip_executable, 'install', 'uranium', '--upgrade'],
stdout=fh, stderr=fh)


def _run_uranium(virtualenv_dir):
Expand Down Expand Up @@ -108,6 +124,20 @@ def _activate_virtualenv(install_dir):
# _execute_file(venv_activate_file)


VIRTUALENV_FILES = {
'activate file': os.path.join('bin', 'activate')
}


def _is_virtualenv(path):
""" validate if the path is already a virtualenv """
for name, venv_path in VIRTUALENV_FILES.items():
target_path = os.path.join(path, venv_path)
if not os.path.exists(target_path):
return False
return True


def _execute_file(path):
with open(path) as f:
code = compile(f.read(), path, 'exec')
Expand All @@ -123,6 +153,7 @@ def _create_stdout_logger():
log.addHandler(out_hdlr)
log.setLevel(logging.INFO)


if __name__ == "__main__":
_create_stdout_logger()
main(sys.argv[1:])

0 comments on commit a5c3edb

Please sign in to comment.