diff --git a/bob/models.py b/bob/models.py index 8105ea0..eab94d1 100644 --- a/bob/models.py +++ b/bob/models.py @@ -18,10 +18,10 @@ HOME_PWD = os.getcwd() s3 = boto.connect_s3() bucket = s3.get_bucket(AWS_BUCKET) +# Make stdin/out as unbuffered as possible via file descriptor modes. sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0) - class Formula(object): def __init__(self, path): @@ -54,7 +54,6 @@ class Formula(object): return path_extract(self.full_path) or DEFAULT_BUILD_PATH def build(self): - # Prepare build directory. mkdir_p(self.build_path) diff --git a/bob/utils.py b/bob/utils.py index 3d7dc2b..b451661 100644 --- a/bob/utils.py +++ b/bob/utils.py @@ -6,43 +6,43 @@ import tarfile from subprocess import Popen, PIPE -DEPENDS_MARKER = '# Build Deps: ' +DEPS_MARKER = '# Build Deps: ' BUILD_PATH_MARKER = '# Build Path: ' -def deps_extract(path): +def iter_marker_lines(marker, formula, strip=True): + """Extracts any markers from a given formula.""" + + with open(formula) as f: + for line in f: + if line.startswith(marker): + + if strip: + line = line[len(marker):] + line = line.strip() + + yield line + + +def deps_extract(formula): """Extracts a list of declared dependencies from a given formula.""" + # Depends: libraries/libsqlite, libraries/libsqlite depends = [] - with open(path) as f: - for line in f: - # Depends: libraries/libsqlite, libraries/libsqlite - if line.startswith(DEPENDS_MARKER): - - l = line[len(DEPENDS_MARKER):] - l = l.strip() - - # Split on both space and comma. - l = re.split(r'[ ,]+', l) - - depends.extend(l) + for result in iter_marker_lines(DEPS_MARKER, formula): + # Split on both space and comma. + result = re.split(r'[ ,]+', result) + depends.extend(result) return depends -def path_extract(path): +def path_extract(formula): """Extracts a declared build path from a given formula.""" - with open(path) as f: - for line in f: - # Build Path: /app/.heroku/usr/local - if line.startswith(BUILD_PATH_MARKER): - - l = line[len(BUILD_PATH_MARKER):] - l = l.strip() - - return l + for result in iter_marker_lines(BUILD_PATH_MARKER, formula): + return result def mkdir_p(path): @@ -54,12 +54,13 @@ def mkdir_p(path): def process(cmd, cwd=None): """A simple wrapper around the subprocess module.""" - p = Popen(cmd, cwd=cwd, shell=True, stdout=PIPE, stderr=PIPE) + p = Popen(cmd, cwd=cwd, shell=False, stdout=PIPE, stderr=PIPE) return p def pipe(a, b, indent=True): """Pipes stream A to stream B, with optional indentation.""" + for line in a: if indent: diff --git a/workspace/runtimes/python-2.7.6 b/workspace/runtimes/python-2.7.6 index 0e3c51f..3927f98 100755 --- a/workspace/runtimes/python-2.7.6 +++ b/workspace/runtimes/python-2.7.6 @@ -1,12 +1,13 @@ #!/usr/bin/env bash # Options: -# Build Path: /app/.heroku/python +# Build Path: /Users/kreitz/repos/heroku/build-toolkit/.heroku/python/ +# Build Path: /app/.heroku/python/ # Build Deps: libraries/libsqlite -fortune -touch hello -touch world -echo foo >/dev/stderr -exit +# fortune +# touch hello +# touch world +# echo foo >/dev/stderr +# exit OUT_PREFIX=$1 # echo "Building SQLite..."