From c89dff7994ee2e8a7a9cd2af3d1cb7a4cbb9c88e Mon Sep 17 00:00:00 2001 From: kevgliss Date: Mon, 20 Jul 2015 16:13:42 -0700 Subject: [PATCH] Getting travisCI setup --- .gitignore | 2 ++ .travis.yml | 32 +++++++++++++---- Makefile | 83 +++++++++++++++++++++++++++++++++++++++++++ docs/requirements.txt | 5 +++ gulp/build.js | 10 ++++++ gulp/karma.conf.js | 27 ++++++++++++++ lemur/manage.py | 4 +-- package.json | 8 +++-- setup.py | 28 +++++++++++++-- 9 files changed, 186 insertions(+), 13 deletions(-) create mode 100644 Makefile create mode 100644 docs/requirements.txt create mode 100644 gulp/karma.conf.js diff --git a/.gitignore b/.gitignore index 3235fc47..7505ec58 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ pip-log.txt docs/_build .editorconfig .idea +test.conf +lemur/tests/tmp \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 83f4e22f..51250545 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,27 @@ -language: node_js -node_js: - - '0.8' - - '0.10' +sudo: false +language: python +services: + - postgresql +python: + - "2.7" +cache: + directories: + - node_modules + - .pip_download_cache + - "$HOME/virtualenv/python2.7.9" +env: + global: + - PIP_DOWNLOAD_CACHE=".pip_download_cache" +install: + - time make develop dev-postgres before_script: - - 'npm install -g bower grunt-cli' - - 'bower install' + - psql -c 'create database lemur;' -U postgres +script: + - make lint + - make test-js + - py.test tests + - make test-cli + +notifications: + email: + kglisson@netflix.com \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..a7ffcdcf --- /dev/null +++ b/Makefile @@ -0,0 +1,83 @@ +NPM_ROOT = ./node_modules +STATIC_DIR = src/lemur/static/app + +develop: update-submodules setup-git + @echo "--> Installing dependencies" + npm install + pip install "setuptools>=0.9.8" + # order matters here, base package must install first + pip install -e . + pip install "file://`pwd`#egg=lemur[dev]" + pip install "file://`pwd`#egg=lemur[tests]" + @echo "" + +dev-docs: + pip install -r docs/requirements.txt + +reset-db: + @echo "--> Dropping existing 'lemur' database" + dropdb lemur || true + @echo "--> Creating 'lemur' database" + createdb -E utf-8 lemur + @echo "--> Applying migrations" + lemur db upgrade + +setup-git: + @echo "--> Installing git hooks" + git config branch.autosetuprebase always + cd .git/hooks && ln -sf ../../hooks/* ./ + @echo "" + +clean: + @echo "--> Cleaning static cache" + ${NPM_ROOT}/.bin/gulp clean + @echo "--> Cleaning pyc files" + find . -name "*.pyc" -delete + @echo "" + +test: develop lint test-js test-python test-cli + +testloop: develop + pip install pytest-xdist + py.test tests -f + +test-cli: + @echo "--> Testing CLI" + rm -rf test_cli + mkdir test_cli + cd test_cli && lemur create_config -c ./test.conf > /dev/null + cd test_cli && lemur -c ./test.conf db upgrade > /dev/null + cd test_cli && lemur -c ./test.conf help 2>&1 | grep start > /dev/null + rm -r test_cli + @echo "" + +test-js: + @echo "--> Running JavaScript tests" + npm test + @echo "" + +test-python: + @echo "--> Running Python tests" + py.test lemur/tests || exit 1 + @echo "" + +lint: lint-python lint-js + +lint-python: + @echo "--> Linting Python files" + PYFLAKES_NODOCTEST=1 flake8 lemur tests + @echo "" + +lint-js: + @echo "--> Linting JavaScript files" + npm run lint + @echo "" + +coverage: develop + coverage run --source=lemur -m py.test + coverage html + +publish: + python setup.py sdist bdist_wheel upload + +.PHONY: develop dev-postgres dev-docs setup-git build clean update-submodules test testloop test-cli test-js test-python lint lint-python lint-js coverage publish \ No newline at end of file diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 00000000..a77fbe3d --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,5 @@ +Jinja2>=2.3 +Pygments>=1.2 +Sphinx>=1.3 +docutils>=0.7 +markupsafe \ No newline at end of file diff --git a/gulp/build.js b/gulp/build.js index 9326d6be..c6c48a2f 100644 --- a/gulp/build.js +++ b/gulp/build.js @@ -26,6 +26,7 @@ var gulp = require('gulp'), imagemin = require('gulp-imagemin'), minifyHtml = require('gulp-minify-html'), bowerFiles = require('main-bower-files'), + karma = require('karma'), replace = require('gulp-replace-task'); @@ -37,6 +38,15 @@ gulp.task('clean', function (cb) { del(['.tmp', 'lemur/static/dist'], cb); }); +gulp.task('test', function (done) { + new karma.Server({ + configFile: __dirname + '/karma.conf.js', + singleRun: true + }, function() { + done(); + }).start(); +}); + gulp.task('dev:fonts', function () { var fileList = [ 'lemur/static/app/vendor/bower_components/bootstrap/dist/fonts/*', diff --git a/gulp/karma.conf.js b/gulp/karma.conf.js new file mode 100644 index 00000000..48c2f9ec --- /dev/null +++ b/gulp/karma.conf.js @@ -0,0 +1,27 @@ +// Contents of: config/karma.conf.js +module.exports = function (config) { + config.set({ + basePath : '../', + + // Fix for "JASMINE is not supported anymore" warning + frameworks : ["jasmine"], + + files : [ + 'app/lib/angular/angular.js', + 'app/lib/angular/angular-*.js', + 'test/lib/angular/angular-mocks.js', + 'app/js/**/*.js', + 'test/unit/**/*.js' + ], + + autoWatch : true, + + browsers : ['Chrome'], + + junitReporter : { + outputFile : 'test_out/unit.xml', + suite : 'unit' + //... + } + }); +} \ No newline at end of file diff --git a/lemur/manage.py b/lemur/manage.py index 8b255e33..8aa9be60 100755 --- a/lemur/manage.py +++ b/lemur/manage.py @@ -480,8 +480,8 @@ def main(): manager.add_command("show_urls", ShowUrls()) manager.add_command("db", MigrateCommand) manager.add_command("init", InitializeApp()) - manager.add_command('create_user', CreateUser()) - manager.add_command('create_role', CreateRole()) + manager.add_command("create_user", CreateUser()) + manager.add_command("create_role", CreateRole()) manager.add_command("sync", Sync()) manager.run() diff --git a/package.json b/package.json index ee027237..ec523c50 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "main-bower-files": "^1.0.2", "require-dir": "~0.3.0", "streamqueue": "^0.1.1", - "uglify-save-license": "^0.4.1" + "uglify-save-license": "^0.4.1", + "karma": "~0.13.2" }, "engines": { "node": ">=0.10.0" @@ -59,9 +60,12 @@ "scripts": { "postinstall": "bower install --allow-root", "pretest": "npm install && npm run build_static", - "build_static": "gulp dist", + "build_static": "gulp build", "prelint": "npm install", "lint": "jshint app/", "test": "gulp test" + }, + "devDependencies": { + "karma-chrome-launcher": "^0.2.0" } } diff --git a/setup.py b/setup.py index 93803b95..e5468b2f 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ import os.path from distutils import log from distutils.core import Command from setuptools.command.develop import develop +from setuptools.command.install import install from setuptools.command.sdist import sdist from setuptools import setup from subprocess import check_output @@ -56,6 +57,24 @@ docs_require = [ 'sphinxcontrib-httpdomain' ] +dev_requires = [ + 'flake8>=2.0,<2.1', +] + +class SmartInstall(install): + """ + Installs Lemur into the Python environment. + If the package indicator is missing, this will also force a run of + `build_static` which is required for JavaScript assets and other things. + """ + def _needs_static(self): + return not os.path.exists(os.path.join(ROOT, 'lemur-package.json')) + + def run(self): + if self._needs_static(): + self.run_command('build_static') + install.run(self) + class DevelopWithBuildStatic(develop): def install_for_development(self): self.run_command('build_static') @@ -79,7 +98,7 @@ class BuildStatic(Command): log.info("running [npm install --quiet]") check_output(['npm', 'install', '--quiet'], cwd=ROOT) - log.info("running [gulp buld]") + log.info("running [gulp build]") check_output([os.path.join(ROOT, 'node_modules', '.bin', 'gulp'), 'build'], cwd=ROOT) setup( @@ -94,12 +113,15 @@ setup( install_requires=install_requires, extras_require={ 'tests': tests_require, - 'docs': docs_require + 'docs': docs_require, + 'dev': dev_requires, }, cmdclass={ 'build_static': BuildStatic, 'develop': DevelopWithBuildStatic, - 'sdist': SdistWithBuildStatic + 'sdist': SdistWithBuildStatic, + 'install': SmartInstall + }, entry_points={ 'console_scripts': [