From b96885aa28cff7e3e456afa8aac1805ccc7c19c2 Mon Sep 17 00:00:00 2001 From: Yuanle Song Date: Wed, 3 Jan 2018 12:39:14 +0800 Subject: [PATCH] v0.20.3 allow using dash in project name --- project.clj | 2 +- src/leiningen/new/python.clj | 10 ++++++++-- src/leiningen/new/python/Makefile | 18 +++++++++--------- src/leiningen/new/python/conf/uwsgi.ini | 2 +- src/leiningen/new/python/config.py | 2 +- src/leiningen/new/python/configlogger.py | 2 +- .../new/python/deb-scripts/after-install.sh | 2 +- src/leiningen/new/python/sanity_check.py | 4 ++-- src/leiningen/new/python/setup.py | 4 ++-- src/leiningen/new/python/tox.ini | 2 +- src/leiningen/new/python/utils/build-deb | 8 ++++---- 11 files changed, 31 insertions(+), 25 deletions(-) diff --git a/project.clj b/project.clj index 4c27394..d5354db 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 5bcc642..7b5f9c1 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 bc2cbe3..9c004b9 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 390ce17..9ab229e 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 5304f2b..0a2e079 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 4cdb907..f84a57a 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 0a61e46..3671ba6 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 22bc8d1..69e4214 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 30b8e95..6dde669 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 967c84e..6f6b034 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 7605659..9274f7d 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' \ -- GitLab