aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x.gitignore1
-rw-r--r--cbc/__init__.py5
-rwxr-xr-xcbc/cli/build.py7
-rw-r--r--cbc/utils.py60
-rw-r--r--setup.py8
-rw-r--r--version.py104
6 files changed, 58 insertions, 127 deletions
diff --git a/.gitignore b/.gitignore
index 77f4530..8330ceb 100755
--- a/.gitignore
+++ b/.gitignore
@@ -6,5 +6,6 @@
dist/
build/
RELEASE-VERSION
+cbc/version.py
cbc/tests/output
cbc/tests/data/output
diff --git a/cbc/__init__.py b/cbc/__init__.py
index 7fc79f7..ae6d351 100644
--- a/cbc/__init__.py
+++ b/cbc/__init__.py
@@ -3,3 +3,8 @@ from . import meta
from . import utils
from . import parsers
from . import cli
+
+try:
+ from .version import __version__
+except ImportError:
+ __version__ = 'unknown'
diff --git a/cbc/cli/build.py b/cbc/cli/build.py
index ce5fa62..ad0151a 100755
--- a/cbc/cli/build.py
+++ b/cbc/cli/build.py
@@ -1,9 +1,10 @@
#!/usr/bin/env python
import argparse
import os
+import traceback
import conda_build.metadata
import cbc
-
+from cbc.exceptions import CondaBuildError
def main():
no_upload = ''
@@ -80,8 +81,8 @@ def main():
if not built:
print('Failure occurred building: {0}'.format(conda_metadata.dist()))
continue
- except cbc.exceptions.CondaBuildError as cbe:
- print(cbe)
+ except CondaBuildError as cbe:
+ print(traceback.format_exc())
continue
print('Installing Conda package...')
diff --git a/cbc/utils.py b/cbc/utils.py
index 0dbfa83..a88fc95 100644
--- a/cbc/utils.py
+++ b/cbc/utils.py
@@ -1,4 +1,6 @@
import json
+import sys
+import inspect
from .meta import MetaData
from .exceptions import CondaBuildError
from subprocess import Popen, PIPE, STDOUT, check_output, CalledProcessError
@@ -13,23 +15,42 @@ def combine_args(args):
return ' '.join(args)
-def run_process(command, callback=None):
- if not isinstance(command, list):
- raise TypeError('Expecting a list instance, got: {0}'.format(type(command)))
- process = Popen(command, stdout=PIPE)
+def run_process(command, callbacks=None):
+ callback_failed = False
+ callback_status = None
+ callback_message = ''
+ process = Popen(command, stdout=PIPE, stderr=STDOUT)
+
+ # Poll process for new output until finished
while True:
- output = process.stdout.readline()
- output = output.decode()
- if not output and process.poll() is not None:
+ nextline = process.stdout.readline().decode()
+ if nextline == '' and process.poll() != None:
break
- if output:
- print(output.strip())
- # Perform user-defined parsing of output
- if callback is not None:
- if not callback(output.strip()):
- process.kill()
+ sys.stdout.write(nextline)
+ sys.stdout.flush()
+
+ output = process.communicate()[0]
+ output = output.decode()
+
+ #Callbacks don't work yet. Sigh.
+ if callbacks is not None:
+ if not isinstance(callbacks, list):
+ raise TypeError('Expecting a list instance, got: {0}'.format(type(command)))
- return process.poll()
+ for callback in callbacks:
+ callback_status, callback_message = callback(output)
+ if not callback_status:
+ callback_failed = True
+ #Stop processing future callbacks here?
+
+ exitCode = process.returncode
+
+ if callback_failed:
+ raise CondaBuildError(callback_message)
+ elif exitCode == 0:
+ return exitCode
+ else:
+ raise CalledProcessError(exitCode, combine_args(command))
def conda_search(metadata):
@@ -57,7 +78,7 @@ def conda_install(pkgname, args=[]):
try:
run_process(command)
except CalledProcessError as cpe:
- print('{0}\nexit={1}'.format(' '.join(cpe.cmd), cpe.returncode))
+ print(cpe)
def conda_reinstall(pkgname, args=[]):
@@ -69,7 +90,7 @@ def conda_reinstall(pkgname, args=[]):
try:
run_process(command)
except CalledProcessError as cpe:
- print('{0}\nexit={1}'.format(combine_args(cpe.cmd), cpe.returncode))
+ print(cpe)
def conda_builder(metadata, args=[]):
@@ -79,13 +100,14 @@ def conda_builder(metadata, args=[]):
def check_bad_egg(output):
bad_egg = 'UNKNOWN.egg-info'
if bad_egg in output:
- raise CondaBuildError('Bad setuptools metadata produced UNKNOWN.egg-info instead of {0}*.egg-info!'.format(metadata.local['package']['name']))
+ return False, '{0}: Bad setuptools metadata produced UNKNOWN.egg-info instead of {1}*.egg-info!'.format(inspect.currentframe().f_code.co_name, metadata.local['package']['name'])
+ return True, ''
command = 'conda build {0} {1}'.format(combine_args(args), metadata.env.pkgdir).split()
+ callbacks = [check_bad_egg]
try:
- run_process(command, check_bad_egg)
- #OK Conda, let's play rough. stdout/stderr only, no exit for you.
+ run_process(command, callbacks)
except SystemExit:
print('Discarding SystemExit issued by setuptools')
except CalledProcessError as cpe:
diff --git a/setup.py b/setup.py
index ebb0c5c..9f40091 100644
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,6 @@
+import os
from setuptools import setup, find_packages
-from version import get_git_version
+from cbc.extern.version import get_git_version
NAME = 'cbc'
VERSION = get_git_version()
@@ -10,11 +11,16 @@ package_data = {}
entry_points['console_scripts'] = [
'cbc_build = cbc.cli.build:main',
'cbc_server = cbc.cli.server:main',
+ 'cbc_remote_purge = cbc.cli.cbc_remote_purge:main',
]
package_data[''] = ['*.txt', '*.md']
test_suite = 'cbc.tests:main'
+cbcpkg = os.path.join('cbc', 'version.py')
+with open(cbcpkg, 'w+') as version_data:
+ version_data.write('__version__ = {0}\n'.format(get_git_version()))
+
setup(
name=NAME,
version=VERSION,
diff --git a/version.py b/version.py
deleted file mode 100644
index ae37850..0000000
--- a/version.py
+++ /dev/null
@@ -1,104 +0,0 @@
-# -*- coding: utf-8 -*-
-# Author: Douglas Creager <dcreager@dcreager.net>
-# This file is placed into the public domain.
-
-# Calculates the current version number. If possible, this is the
-# output of “git describe”, modified to conform to the versioning
-# scheme that setuptools uses. If “git describe” returns an error
-# (most likely because we're in an unpacked copy of a release tarball,
-# rather than in a git working copy), then we fall back on reading the
-# contents of the RELEASE-VERSION file.
-#
-# To use this script, simply import it your setup.py file, and use the
-# results of get_git_version() as your package version:
-#
-# from version import *
-#
-# setup(
-# version=get_git_version(),
-# .
-# .
-# .
-# )
-#
-# This will automatically update the RELEASE-VERSION file, if
-# necessary. Note that the RELEASE-VERSION file should *not* be
-# checked into git; please add it to your top-level .gitignore file.
-#
-# You'll probably want to distribute the RELEASE-VERSION file in your
-# sdist tarballs; to do this, just create a MANIFEST.in file that
-# contains the following line:
-#
-# include RELEASE-VERSION
-from __future__ import print_function
-from subprocess import Popen, PIPE
-
-__all__ = ("get_git_version")
-
-
-def call_git_describe(abbrev=4):
- try:
- p = Popen(['git', 'describe', '--abbrev=%d' % abbrev],
- stdout=PIPE, stderr=PIPE)
- p.stderr.close()
- line = p.stdout.readlines()[0]
- return line.strip()
-
- except:
- return None
-
-
-def read_release_version():
- try:
- f = open("RELEASE-VERSION", "r")
-
- try:
- version = f.readlines()[0]
- return version.strip()
-
- finally:
- f.close()
-
- except:
- return None
-
-
-def write_release_version(version):
- f = open("RELEASE-VERSION", "w")
- f.write("%s\n" % version)
- f.close()
-
-
-def get_git_version(abbrev=4):
- # Read in the version that's currently in RELEASE-VERSION.
-
- release_version = read_release_version()
-
- # First try to get the current version using “git describe”.
-
- version = call_git_describe(abbrev)
-
- # If that doesn't work, fall back on the value that's in
- # RELEASE-VERSION.
-
- if version is None:
- version = release_version
-
- # If we still don't have anything, that's an error.
-
- if version is None:
- raise ValueError("Cannot find the version number!")
-
- # If the current version is different from what's in the
- # RELEASE-VERSION file, update the file to be current.
-
- if version != release_version:
- write_release_version(version)
-
- # Finally, return the current version.
-
- return version
-
-
-if __name__ == "__main__":
- print(get_git_version())