diff --git a/project.clj b/project.clj index 4c2739441439f45f962aa7efd380a532700832c6..d5354db659b5e125c02e2882ca6adb21dacd527d 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject python/lein-template "0.20.2" +(defproject python/lein-template "0.20.3" :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 5bcc6428f8705206b4cf57cb0c0274b6b0226662..7b5f9c1c5c4455c87cb9c3d7f86e07f9184175ba 100644 --- a/src/leiningen/new/python.clj +++ b/src/leiningen/new/python.clj @@ -25,11 +25,17 @@ (if (not (empty? output)) (main/info output)))) +(defn name-to-python-pkg-name + "convert project name to python pkg name" + [name] + (string/replace name "-" "_")) + (defn python "a standard python project with virtualenv, githooks, pep8, pylint etc" [name] (let [data {:name name :sanitized (name-to-path name) + :python-pkg-name (name-to-python-pkg-name name) :date (let [cal (Calendar/getInstance)] (.format (new SimpleDateFormat "yyyy-MM-dd") (.getTime cal)))} @@ -64,7 +70,7 @@ "utils/virtualenv-15.1.0/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl" "utils/virtualenv-15.1.0/virtualenv_support/__init__.py" ] - empty-files ["{{name}}/__init__.py"] + empty-files ["{{python-pkg-name}}/__init__.py"] package-files ["logger.conf" "configlogger.py" "config.py" @@ -77,7 +83,7 @@ (concat (map (fn [f] [f ""]) empty-files) (map (fn [f] [f (render f data)]) template-files) - (map (fn [f] [(str "{{name}}/" f) (render f data)]) package-files) + (map (fn [f] [(str "{{python-pkg-name}}/" f) (render f data)]) package-files) (map (fn [f] [f (io/input-stream (get-template-file f))]) ;; using input-stream here because the result of rendering ;; binary file is undefined even when data is empty hashmap. diff --git a/src/leiningen/new/python/Makefile b/src/leiningen/new/python/Makefile index bc2cbe3e6537c2ef0a67370ccc2bb6e974851cbc..9c004b91d151f99b4e4c1db1035dd69d82e34580 100644 --- a/src/leiningen/new/python/Makefile +++ b/src/leiningen/new/python/Makefile @@ -1,4 +1,4 @@ -PYTHON_MODULES := {{name}} +PYTHON_MODULES := {{python-pkg-name}} PYTHONPATH := . VENV := .venv PYTEST := env PYTHONPATH=$(PYTHONPATH) PYTEST=1 $(VENV)/bin/py.test @@ -17,11 +17,11 @@ default: check-coding-style build: debug: - env DEBUG=1 $(PYTHON) {{name}}/main.py + env DEBUG=1 $(PYTHON) {{python-pkg-name}}/main.py run: - $(PYTHON) {{name}}/main.py + $(PYTHON) {{python-pkg-name}}/main.py uwsgi: - $(VENV)/bin/uwsgi --processes=2 --threads=4 --wsgi-file={{name}}/main.py --env=PYTHONPATH=. --http=localhost:8082 --disable-logging + $(VENV)/bin/uwsgi --processes=2 --threads=4 --wsgi-file={{python-pkg-name}}/main.py --env=PYTHONPATH=. --http=localhost:8082 --disable-logging shell: $(PYTHON) -i @@ -44,7 +44,7 @@ bootstrap-dev: venv requirements install: bootstrap $(PYTHON) setup.py -q install uninstall: bootstrap - $(PIP) uninstall {{name}} # TODO not tested. + $(PIP) uninstall {{python-pkg-name}} # TODO not tested. deb: utils/build-deb pipfreeze: @@ -56,11 +56,11 @@ wheel: bootstrap-dev check: just-test sanity-check: bootstrap - $(PYTHON) {{name}}/sanity_check.py + $(PYTHON) {{python-pkg-name}}/sanity_check.py check-coding-style: bootstrap-dev $(PEP8) $(PYTHON_MODULES) $(PYLINT) -E $(PYTHON_MODULES) - $(PYTHON) {{name}}/config.py + $(PYTHON) {{python-pkg-name}}/config.py pylint-full: check-coding-style $(PYLINT) $(PYTHON_MODULES) test: check-coding-style @@ -76,7 +76,7 @@ clean: find . -name "__pycache__" -type d -exec rm -rf {} \; || true find . -name "*.pyc" -type f -exec rm -rf {} \; || true full-clean: - rm -rf $(VENV) build/ dist/ wheelhouse/ {{name}}.egg-info/ distribute-*.tar.gz + rm -rf $(VENV) build/ dist/ wheelhouse/ {{python-pkg-name}}.egg-info/ distribute-*.tar.gz find . -name "__pycache__" -type d -exec rm -rf {} \; || true find . -name "*.pyc" -type f -exec rm -rf {} \; || true todo: @@ -90,5 +90,5 @@ install-git-hooks-force: ./utils/install-git-hooks -f loc: find . -regex '.*\.pyw?$$' -exec wc -l {} \+ | tail -n 1 - which cloc >/dev/null && cloc {{name}}/ + which cloc >/dev/null && cloc {{python-pkg-name}}/ .PHONY: default build debug run uwsgi shell venv bootstrap bootstrap-dev install uninstall deb pipfreeze wheel check check-coding-style pylint-full test just-test test-prod clean full-clean todo TAGS update-git-hooks install-git-hooks install-git-hooks-force loc diff --git a/src/leiningen/new/python/conf/uwsgi.ini b/src/leiningen/new/python/conf/uwsgi.ini index 390ce179bce5a61ed8329843d75ad2b19d5f975e..9ab229ee553df454515d9c75228b8ae1ca410e33 100644 --- a/src/leiningen/new/python/conf/uwsgi.ini +++ b/src/leiningen/new/python/conf/uwsgi.ini @@ -2,7 +2,7 @@ socket=127.0.0.1:8082 chdir=/opt/{{name}} -wsgi-file={{name}}/main.py +wsgi-file={{python-pkg-name}}/main.py env=PYTHONPATH=. processes=4 diff --git a/src/leiningen/new/python/config.py b/src/leiningen/new/python/config.py index 5304f2b46c8868147ebf91eddaa654345da570ec..0a2e079f3e79222ef71c8a2d63288ebf106b840e 100644 --- a/src/leiningen/new/python/config.py +++ b/src/leiningen/new/python/config.py @@ -8,7 +8,7 @@ config variables from __future__ import (absolute_import, division, print_function, unicode_literals, with_statement) -import {{name}}.configlogger +import {{python-pkg-name}}.configlogger import logging import os diff --git a/src/leiningen/new/python/configlogger.py b/src/leiningen/new/python/configlogger.py index 4cdb90737f4313f8c8fef43830f0dc29e671f4de..f84a57a1a8723ac1d2e10e82267a9030ca87d43d 100644 --- a/src/leiningen/new/python/configlogger.py +++ b/src/leiningen/new/python/configlogger.py @@ -25,7 +25,7 @@ def load_logger_config(): """ logdir = "/var/log/{{name}}/" if os.path.exists(logdir): - fileConfig(resource_filename("{{name}}", "logger.conf")) + fileConfig(resource_filename("{{python-pkg-name}}", "logger.conf")) return ENV = os.getenv("ENV", "test") diff --git a/src/leiningen/new/python/deb-scripts/after-install.sh b/src/leiningen/new/python/deb-scripts/after-install.sh index 0a61e4658e0eb85afbab9e7953035d93c158ec45..3671ba661a89ba6dc62a02bd725bf45537acfeda 100644 --- a/src/leiningen/new/python/deb-scripts/after-install.sh +++ b/src/leiningen/new/python/deb-scripts/after-install.sh @@ -6,7 +6,7 @@ LOGDIR=${LOGDIR:-/var/log/{{name}}} RUN_AS_USER=www-data mkdir -p "$LOGDIR" -# touch /data2/log/{{name}}/uwsgi.touch +# touch /var/log/{{name}}/uwsgi.touch if [ "$RUN_AS_USER" != root ]; then chown -R "$RUN_AS_USER":"$RUN_AS_USER" "$LOGDIR" fi diff --git a/src/leiningen/new/python/sanity_check.py b/src/leiningen/new/python/sanity_check.py index 22bc8d1ac659e49d2b6fd3e4262801d8734eebd2..69e42141910035ce87bc3648b9f0a19507130e3c 100644 --- a/src/leiningen/new/python/sanity_check.py +++ b/src/leiningen/new/python/sanity_check.py @@ -10,8 +10,8 @@ import logging from wells.utils import check -from {{name}}.config import CONF -# from {{name}} import db +from {{python-pkg-name}}.config import CONF +# from {{python-pkg-name}} import db logger = logging.getLogger(__name__) diff --git a/src/leiningen/new/python/setup.py b/src/leiningen/new/python/setup.py index 30b8e95a917eed33146ecb5f444c0f3dd0a4764c..6dde669f9c54fb67636a4fb08287d946f7e1cc29 100644 --- a/src/leiningen/new/python/setup.py +++ b/src/leiningen/new/python/setup.py @@ -29,11 +29,11 @@ setup( ], entry_points={ # 'console_scripts': [ - # 'main = {{name}}.main:main', + # 'main = {{python-pkg-name}}.main:main', # ] }, package_data={ - '{{name}}': ['logger.conf'] + '{{python-pkg-name}}': ['logger.conf'] }, author="Yuanle Song", author_email="sylecn@gmail.com", diff --git a/src/leiningen/new/python/tox.ini b/src/leiningen/new/python/tox.ini index 967c84e076339ae2cff6826ed61f9e3c6b54987b..6f6b03484e7f09c2a59bef192d0f162ac7d487d9 100644 --- a/src/leiningen/new/python/tox.ini +++ b/src/leiningen/new/python/tox.ini @@ -3,7 +3,7 @@ envlist = py27,py34 skipsdist = True [testenv] -commands = pytest {{name}} +commands = pytest {{python-pkg-name}} deps = -r{toxinidir}/requirements-dev.txt -r{toxinidir}/requirements.txt setenv = TESTING = 1 diff --git a/src/leiningen/new/python/utils/build-deb b/src/leiningen/new/python/utils/build-deb index 76056594539472120e8f9e409b2c4c88445e6862..9274f7d02b32dc0c211050a035a6259d9a3ef430 100644 --- a/src/leiningen/new/python/utils/build-deb +++ b/src/leiningen/new/python/utils/build-deb @@ -13,9 +13,9 @@ if [ "$1" = "--help" ]; then fi VERSION=`grep 'version' setup.py |cut -d'"' -f 2` -PKG_NAME="{{name}}" -DEST_DIR="/opt/$PKG_NAME" -PYTHON_MODULES="{{name}}" +DEB_PKG_NAME="{{name}}" +DEST_DIR="/opt/$DEB_PKG_NAME" +PYTHON_MODULES="{{python-pkg-name}}" #PYTHON_MODULES=`echo */__init__.py|cut -d'/' -f1` if [ ! -d wheelhouse ]; then @@ -23,7 +23,7 @@ if [ ! -d wheelhouse ]; then fi # add dependencies on libpq5 if you use psycopg2. -fpm -t deb -s dir -n "$PKG_NAME" -v "$VERSION" --prefix "$DEST_DIR" -f \ +fpm -t deb -s dir -n "$DEB_PKG_NAME" -v "$VERSION" --prefix "$DEST_DIR" -f \ --depends make \ -x '*__pycache__' \ -x '*.pyc' \