Skip to content

Commit

Permalink
tmuxp: update to use bootstrap_env with tmux file.
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Apr 8, 2014
1 parent fd5a966 commit 1b46d12
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 28 deletions.
42 changes: 14 additions & 28 deletions .tmuxp.yaml
@@ -1,41 +1,27 @@
session_name: cihai-python
start_directory: ./
shell_command_before:
- command -v virtualenv >/dev/null 2>&1 || { pip install virtualenv; }
- '[ -d .env -a -f .env/bin/activate ] && source .env/bin/activate || virtualenv .env'
- '[ ! -d .env/build ] || rm -rf .env/build'
before_script: ./bootstrap_env.py
windows:
- window_name: cihai-python
layout: 89b3,239x56,0,0[239x36,0,0,0,239x19,0,37{119x19,0,37,1,119x19,120,37,3}]
- window-name: cihai
layout: main-horizontal
focus: true
panes:
- shell_command:
- vim
- :Ex
focus: true
- focus: true
- pane
- shell_command:
- command -v watching_testrunner >/dev/null 2>&1 || { pip install watching_testrunner; }
- watching_testrunner --basepath ./ --pattern="*.py" 'python setup.py test'
- watching_testrunner --basepath ./ --pattern="*.py" 'python setup.py test'
shell_command_before:
- '[ -d .env -a -f .env/bin/activate ] && source .env/bin/activate'
options:
main-pane-height: 35
- window_name: docs
layout: main-horizontal
start_directory: doc/
options:
main-pane-height: 35
shell_command_before:
- command -v virtualenv >/dev/null 2>&1 || { pip install virtualenv; }
- '[ -d .env -a -f .env/bin/activate ] && source .env/bin/activate || virtualenv .env'
- '[ ! -d .env/build ] || rm -rf .env/build'
- command -v .env/bin/vcspull >/dev/null 2>&1 || { pip install -e .; }
- cd ./doc
- '[ -d ../.env -a -f ../.env/bin/activate ] && source ../.env/bin/activate'
panes:
- shell_command:
- reset
- vim
- :Ex
- pwd
- focus: true
- pane
- echo 'docs built to <http://0.0.0.0:8013/_build/html>'; python -m SimpleHTTPServer 8013
- shell_command:
- command -v sphinx-quickstart >/dev/null 2>&1 || { pip install -r requirements.pip; }
- command -v watching_testrunner >/dev/null 2>&1 || { pip install watching_testrunner; }
- watching_testrunner --basepath ./ --pattern="*.rst" 'make html'
- python -m SimpleHTTPServer
- watching_testrunner --basepath ./ --pattern="*.rst" 'make html'
133 changes: 133 additions & 0 deletions bootstrap_env.py
@@ -0,0 +1,133 @@
#!/usr/bin/env python

from __future__ import absolute_import, division, print_function, \
with_statement, unicode_literals


import os
import sys
import subprocess


def warning(*objs):
print("WARNING: ", *objs, file=sys.stderr)


def fail(message):
sys.exit("Error: {message}".format(message=message))


PY2 = sys.version_info[0] == 2
if PY2:
from urllib import urlretrieve
else:
from urllib.request import urlretrieve


def has_module(module_name):
try:
import imp
imp.find_module(module_name)
del imp
return True
except ImportError:
return False


def which(exe=None, throw=True):
"""Return path of bin. Python clone of /usr/bin/which.
from salt.util - https://www.github.com/saltstack/salt - license apache
:param exe: Application to search PATHs for.
:type exe: string
:param throw: Raise ``Exception`` if not found in paths
:type throw: bool
:rtype: string
"""
if exe:
if os.access(exe, os.X_OK):
return exe

# default path based on busybox's default
default_path = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'
search_path = os.environ.get('PATH', default_path)

for path in search_path.split(os.pathsep):
full_path = os.path.join(path, exe)
if os.access(full_path, os.X_OK):
return full_path

message = (
'{0!r} could not be found in the following search '
'path: {1!r}'.format(
exe, search_path
)
)

if throw:
raise Exception(message)
else:
print(message)
return None


project_dir = os.path.dirname(os.path.realpath(__file__))
env_dir = os.path.join(project_dir, '.env')
pip_bin = os.path.join(env_dir, 'bin', 'pip')
python_bin = os.path.join(env_dir, 'bin', 'python')
virtualenv_bin = which('virtualenv', throw=False)
virtualenv_exists = os.path.exists(env_dir) and os.path.isfile(python_bin)
sphinx_requirements_filepath = os.path.join(project_dir, 'doc', 'requirements.pip')


try:
import virtualenv
except ImportError:
message = (
'Virtualenv is required for this bootstrap to run.\n'
'Install virtualenv via:\n'
'\t$ [sudo] pip install virtualenv'
)
fail(message)


try:
import pip
except ImportError:
message = (
'pip is required for this bootstrap to run.\n'
'Find instructions on how to install at: %s' %
'http://pip.readthedocs.org/en/latest/installing.html'
)
fail(message)


def main():
if not virtualenv_exists:
virtualenv_bin = which('virtualenv', throw=False)

subprocess.check_call(
[virtualenv_bin, env_dir]
)

subprocess.check_call(
[pip_bin, 'install', '-e', project_dir]
)

if not os.path.isfile(os.path.join(env_dir, 'bin', 'watching_testrunner')):
subprocess.check_call(
[pip_bin, 'install', 'watching-testrunner']
)

if not os.path.isfile(os.path.join(env_dir, 'bin', 'sphinx-quickstart')):
subprocess.check_call(
[pip_bin, 'install', '-r', sphinx_requirements_filepath]
)

if os.path.exists(os.path.join(env_dir, 'build')):
os.removedirs(os.path.join(env_dir, 'build'))

if __name__ == '__main__':
main()

0 comments on commit 1b46d12

Please sign in to comment.