From de6fdd2f25f859c5cf499cae521930238c43c0ca Mon Sep 17 00:00:00 2001 From: Yuanle Song Date: Thu, 8 Sep 2016 14:13:46 +0800 Subject: [PATCH] v0.16.0 add sanity-check support - bump yygame-utils pkg version to 0.15.0, which provides the @check decorator. --- operational | 20 ++++----- project.clj | 2 +- src/leiningen/new/python.clj | 1 + src/leiningen/new/python/Makefile | 2 + src/leiningen/new/python/requirements.txt | 2 +- src/leiningen/new/python/sanity_check.py | 49 +++++++++++++++++++++++ 6 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 src/leiningen/new/python/sanity_check.py diff --git a/operational b/operational index f5210c4..5c486de 100644 --- a/operational +++ b/operational @@ -4,16 +4,6 @@ Time-stamp: <2016-09-08> #+STARTUP: content * current :entry: ** -** 2016-09-08 integrate sanity-check -- update yygame-utils pkg version -- in Makefile - check: just-test -+sanity-check: -+ $(PYTHON) wechat_article_saver_daemon/sanity_check.py - check-coding-style: bootstrap-dev - -- add the template with a dumb check. - ** 2016-09-08 support updating site file, deb scripts etc after project is generated. - the domain in site file could change. - the pkg name could change. @@ -49,6 +39,16 @@ see example ~/.pylintrc ** 2014-05-09 add sphinx support * later :entry: * done :entry: +** DONE 2016-09-08 integrate sanity-check +- update yygame-utils pkg version +- in Makefile + check: just-test ++sanity-check: ++ $(PYTHON) wechat_article_saver_daemon/sanity_check.py + check-coding-style: bootstrap-dev + +- add the template with a dumb check. + ** DONE 2016-06-30 make "lein new python bar" work, without --to-dir . chmod -R +x utils/ diff --git a/project.clj b/project.clj index db2cb6b..c099b23 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject python/lein-template "0.15.0" +(defproject python/lein-template "0.16.0" :description "lein template for a python project" :repositories [["snapshots" {:url "http://devserv.game.yy.com/nexus/content/repositories/snapshots" diff --git a/src/leiningen/new/python.clj b/src/leiningen/new/python.clj index b187ad6..c75c12c 100644 --- a/src/leiningen/new/python.clj +++ b/src/leiningen/new/python.clj @@ -67,6 +67,7 @@ package-files ["logger.conf" "configlogger.py" "config.py" + "sanity_check.py" "test_main.py"] post-run-commands ["chmod -R +x utils/ git-hooks/ deb-scripts/" ]] diff --git a/src/leiningen/new/python/Makefile b/src/leiningen/new/python/Makefile index 4ac8cc0..4391fed 100644 --- a/src/leiningen/new/python/Makefile +++ b/src/leiningen/new/python/Makefile @@ -49,6 +49,8 @@ wheel: bootstrap-dev $(PIP) wheel -w wheelhouse -f https://emacsos.com/python/packages/ $(REQUIREMENTS) check: just-test +sanity-check: + $(PYTHON) {{name}}/sanity_check.py check-coding-style: bootstrap-dev $(PEP8) $(PYTHON_MODULES) $(PYLINT) -E $(PYTHON_MODULES) diff --git a/src/leiningen/new/python/requirements.txt b/src/leiningen/new/python/requirements.txt index 70a5508..7e4ad27 100644 --- a/src/leiningen/new/python/requirements.txt +++ b/src/leiningen/new/python/requirements.txt @@ -1,2 +1,2 @@ -yygame-utils==0.10.0 +yygame-utils==0.15.0 # raven==3.6.1 diff --git a/src/leiningen/new/python/sanity_check.py b/src/leiningen/new/python/sanity_check.py new file mode 100644 index 0000000..bb2b6d9 --- /dev/null +++ b/src/leiningen/new/python/sanity_check.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# coding=utf-8 + +"""sanity check for {{name}} + +""" + +import sys +import logging + +from yygame.utils import check + +from {{name}}.config import CONF +# from {{name}} import db + +logger = logging.getLogger(__name__) + + +@check +def check_dumb(): + return True + + +# @check +# def check_db(): +# with db.get_cursor() as cur: +# cur.execute(u"""\ +# SELECT 1 +# """) +# return cur.fetchone()[0] == 1 + + +def main(): + results = [ + check_dumb(), + # check_db(), + ] + pass_count = len([x for x in results if x]) + fail_count = len(results) - pass_count + if fail_count: + logger.error("%s checks passed, %s failed.", + pass_count, fail_count) + sys.exit(fail_count) + else: + logger.info("%s checks passed.", pass_count) + + +if __name__ == '__main__': + main() -- GitLab