diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-17 13:57:23 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-17 13:57:23 -0400 |
commit | 237d2159faac7dadb0232e35f7016588db568808 (patch) | |
tree | 19482c130efee570b7e985121dbf372b6965db50 | |
parent | 16a6d3d6c9495d3a67d74835f1d25329418ba832 (diff) | |
download | cbc-237d2159faac7dadb0232e35f7016588db568808.tar.gz |
Restructuring and setuptools integration1.0
-rwxr-xr-x | .gitignore | 7 | ||||
-rw-r--r-- | MANIFEST.in | 1 | ||||
-rw-r--r-- | cbc/__init__.py | 2 | ||||
-rw-r--r-- | cbc/cli/__init__.py | 0 | ||||
-rwxr-xr-x | cbc/cli/build.py (renamed from cbcbuild.py) | 13 | ||||
-rw-r--r-- | cbc/cli/server.py (renamed from cbc/server.py) | 14 | ||||
-rw-r--r-- | cbc/tests/__init__.py | 0 | ||||
-rw-r--r-- | cbc/tests/data/test.ini (renamed from tests/data/test.ini) | 0 | ||||
-rw-r--r-- | cbc/tests/test_cbc.py (renamed from tests/test.py) | 38 | ||||
-rw-r--r-- | setup.py | 34 | ||||
-rw-r--r-- | version.py | 104 |
11 files changed, 176 insertions, 37 deletions
@@ -2,4 +2,9 @@ *.pyc *.DS_Store *pycache* -test/output +*.egg-info +dist/ +build/ +RELEASE-VERSION +cbc/tests/output +cbc/tests/data/output diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..466cd00 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include RELEASE-VERSION diff --git a/cbc/__init__.py b/cbc/__init__.py index 8c167d0..7fc79f7 100644 --- a/cbc/__init__.py +++ b/cbc/__init__.py @@ -1,5 +1,5 @@ from . import environment from . import meta -from . import server from . import utils from . import parsers +from . import cli diff --git a/cbc/cli/__init__.py b/cbc/cli/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/cbc/cli/__init__.py diff --git a/cbcbuild.py b/cbc/cli/build.py index 2217a4e..ce5fa62 100755 --- a/cbcbuild.py +++ b/cbc/cli/build.py @@ -1,16 +1,11 @@ #!/usr/bin/env python import argparse import os -import sys -import cbc import conda_build.metadata +import cbc -#os.environ['CBC_HOME'] = os.path.abspath(os.path.join(os.path.dirname(cbc.__file__), 'tests/data/build')) -#sys.argv.append('--force-rebuild') -#sys.argv.append('tests/data/aprio.ini') - -if __name__ == '__main__': +def main(): no_upload = '' use_local = '' @@ -99,3 +94,7 @@ if __name__ == '__main__': cbc.utils.conda_reinstall(conda_metadata.name()) print('') + + +if __name__ == '__main__': + main() diff --git a/cbc/server.py b/cbc/cli/server.py index 4126ed8..9661f4a 100644 --- a/cbc/server.py +++ b/cbc/cli/server.py @@ -37,17 +37,17 @@ class FileServer(object): self.httpd.server_close() -if __name__ == '__main__': +def main(): parser = argparse.ArgumentParser() parser.add_argument('-r', '--root', default=os.path.abspath(os.curdir), help='Path to files') parser.add_argument('-p', '--port', type=int, default=8888, help='TCP port') parser.add_argument('-s', '--single', action='store_false') args = parser.parse_args() - + fileserver = FileServer(args.port, args.root) fileserver.run(forever=args.single) - - - - - + + +if __name__ == '__main__': + main() + diff --git a/cbc/tests/__init__.py b/cbc/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/cbc/tests/__init__.py diff --git a/tests/data/test.ini b/cbc/tests/data/test.ini index ec67f6e..ec67f6e 100644 --- a/tests/data/test.ini +++ b/cbc/tests/data/test.ini diff --git a/tests/test.py b/cbc/tests/test_cbc.py index 49e22a5..84e4e67 100644 --- a/tests/test.py +++ b/cbc/tests/test_cbc.py @@ -1,9 +1,9 @@ +import cbc import nose import nose.tools import os -import cbc -from cbc.exceptions import IncompleteEnv, MetaDataError import sys +from cbc.exceptions import IncompleteEnv, MetaDataError class TestCBC(object): @@ -14,41 +14,38 @@ class TestCBC(object): os.environ['CBC_HOME'] = output self.env = cbc.environment.Environment() self.ini = os.path.join(lookup, 'test.ini') - - + + def tearDown(self): pass - + @nose.tools.raises(OSError) def test_spec_does_not_exist(self): - '''Issue non-existent INI and see what happens. - ''' spec = cbc.meta.MetaData('deadbeefcafe.ini', self.env) - + @nose.tools.raises(IncompleteEnv) def test_spec_incomplete_environment(self): - '''Screw up the environment on purpose + '''test_spec_incomplete_environment (a valid ~/.cbcrc will cause this to fail) ''' - del os.environ['CBC_HOME'] + del os.environ['CBC_HOME'] env = cbc.environment.Environment() - + @nose.tools.raises(MetaDataError) def test_spec_environment_instance(self): - '''Issue the incorrect class instance as the environment - ''' env = '' cbc_meta = cbc.meta.MetaData(self.ini, env) - + def test_spec_standalone_build_data(self): cbc_meta = cbc.meta.MetaData(self.ini, self.env) nose.tools.assert_in('cbc_build', cbc_meta.local_metadata) - + def test_spec_standalone_cgi_server_data(self): cbc_meta = cbc.meta.MetaData(self.ini, self.env) nose.tools.assert_in('cbc_cgi', cbc_meta.local_metadata) - + def test_spec_no_ini_and_yaml_crosstalk(self): cbc_meta = cbc.meta.MetaData(self.ini, self.env) + nose.tools.assert_not_in('settings', cbc_meta.conda_metadata) nose.tools.assert_not_in('cbc_build', cbc_meta.conda_metadata) nose.tools.assert_not_in('cbc_cgi', cbc_meta.conda_metadata) @@ -57,14 +54,13 @@ class TestCBC(object): cbc_meta = cbc.meta.MetaData(self.ini, self.env) cbc_meta.env.mkpkgdir(cbc_meta.local['package']['name']) cbc_meta.render_scripts() - + # Test against conda's build system conda_meta = conda_build.metadata.MetaData(self.env.pkgdir) nose.tools.assert_is_instance(conda_meta, conda_build.metadata.MetaData) nose.tools.assert_equal(conda_meta.dist(), 'test-1.0.0-py34_1') - - - + + + if __name__ == '__main__': - sys.argv.append('--verbosity=3') nose.main(argv=sys.argv) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ebb0c5c --- /dev/null +++ b/setup.py @@ -0,0 +1,34 @@ +from setuptools import setup, find_packages +from version import get_git_version + +NAME = 'cbc' +VERSION = get_git_version() + +entry_points = {} +package_data = {} + +entry_points['console_scripts'] = [ + 'cbc_build = cbc.cli.build:main', + 'cbc_server = cbc.cli.server:main', +] + +package_data[''] = ['*.txt', '*.md'] +test_suite = 'cbc.tests:main' + +setup( + name=NAME, + version=VERSION, + description='Conda Build Controller', + requires=['conda_build', 'binstar_client'], + provides=[NAME], + author='Joseph Hunkeler', + author_email='jhunk@stsci.edu', + license='BSD', + url='http://bitbucket.org/jhunkeler/cbc', + download_url='', + use_2to3=False, + packages=find_packages(), + entry_points=entry_points, + package_data=package_data, + test_suite=test_suite, +) diff --git a/version.py b/version.py new file mode 100644 index 0000000..ae37850 --- /dev/null +++ b/version.py @@ -0,0 +1,104 @@ +# -*- 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()) |