From 7bc9fcd2d59b9ae6129104a89d81ca54f577a6d5 Mon Sep 17 00:00:00 2001 From: Yuanle Song Date: Thu, 8 Sep 2016 12:51:27 +0800 Subject: [PATCH] v0.14.0 multiple minor changes - bugfix: add fabfile.py in render file list - add web.upstart and use that in deb-scripts - update python .gitignore list - PEP8 now ignores E402 module level import not at top of file - http.site and https.site now use proxy_pass instead of uwsgi_pass Until uwsgi integration problem is fixed, I have to use other wsgi server. - set default python version to python 3.4 in setup.py many of my new projects use python3 instead of python2.7. --- operational | 38 ++++++++++++++----- project.clj | 2 +- src/leiningen/new/python.clj | 2 + src/leiningen/new/python/.gitignore | 2 + src/leiningen/new/python/Makefile | 2 +- src/leiningen/new/python/conf/http.site | 18 +++++++-- src/leiningen/new/python/conf/https.site | 18 +++++++-- src/leiningen/new/python/conf/web.upstart | 18 +++++++++ .../new/python/deb-scripts/after-install.sh | 2 +- src/leiningen/new/python/setup.py | 4 +- 10 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 src/leiningen/new/python/conf/web.upstart diff --git a/operational b/operational index 46ba2db..cd17ca8 100644 --- a/operational +++ b/operational @@ -1,9 +1,26 @@ * COMMENT -*- mode: org -*- #+Date: 2014-05-09 -Time-stamp: <2016-09-06> +Time-stamp: <2016-09-08> #+STARTUP: content * current :entry: ** +** 2016-09-08 integrate sanity-check +- 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. +- whether to use uwsgi could change. + +./utils/update_site_file.py --domain foo.emacsos.com --uwsgi +./utils/update_site_file.py --domain foo.emacsos.com --http + ** 2016-09-06 support adding celery to existing project. - This will add a celeryconfig module and a tasks module. see examples in @@ -21,6 +38,16 @@ see example ~/.pylintrc ** 2016-07-27 package name should not have -, auto convert it to _. - package name is part of module name, - is not valid there. +** 2016-06-30 update it for use with default debian config. (non-yy env) +- update nginx config file +- add support for systemd +- create /data if it doesn't exist. auto use sudo to create the dir if it + doesn't exist. + + make sure it works on fresh system. use a VM to test it. +** 2014-05-09 add sphinx support +* later :entry: +* done :entry: ** DONE 2016-06-30 make "lein new python bar" work, without --to-dir . chmod -R +x utils/ @@ -42,13 +69,6 @@ chmod -R +x utils/ I think it could be nil when --to-dir is not used. yes. it's null when user doesn't use --to-dir option. -** 2016-06-30 update it for use with default debian config. (non-yy env) -- update nginx config file -- add support for systemd -- create /data if it doesn't exist. auto use sudo to create the dir if it - doesn't exist. - - make sure it works on fresh system. use a VM to test it. ** DONE 2016-06-30 use python3 in venv by default. - make old code work with python3. - add future imports @@ -124,5 +144,3 @@ chmod -R +x utils/ - it requires me listing all template and plain files. this is bad. should just generate the file list on the fly. -** 2014-05-09 add sphinx support -* later :entry: diff --git a/project.clj b/project.clj index 65257dc..c668235 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject python/lein-template "0.13.0" +(defproject python/lein-template "0.14.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 1b29b90..b187ad6 100644 --- a/src/leiningen/new/python.clj +++ b/src/leiningen/new/python.clj @@ -34,6 +34,7 @@ (.format (new SimpleDateFormat "yyyy-MM-dd") (.getTime cal)))} template-files ["Makefile" + "fabfile.py" "requirements.txt" "requirements-dev.txt" "setup.py" @@ -49,6 +50,7 @@ "conf/logrotate.conf" "conf/uwsgi.ini" "conf/uwsgi.upstart" + "conf/web.upstart" "git-hooks/post-commit" "git-hooks/post-merge" "git-hooks/pre-commit" diff --git a/src/leiningen/new/python/.gitignore b/src/leiningen/new/python/.gitignore index e3affb0..07a0db8 100644 --- a/src/leiningen/new/python/.gitignore +++ b/src/leiningen/new/python/.gitignore @@ -1,4 +1,5 @@ # BEGIN regular python ignore list +.venv/ bin/ include/ lib/python2.7/ @@ -15,4 +16,5 @@ __pycache__/ .tox *.deb doc/_build/ +TAGS # ENG regular python ignore list diff --git a/src/leiningen/new/python/Makefile b/src/leiningen/new/python/Makefile index 789ca8c..4ac8cc0 100644 --- a/src/leiningen/new/python/Makefile +++ b/src/leiningen/new/python/Makefile @@ -3,7 +3,7 @@ PYTHONPATH := . VENV := .venv PYTEST := env PYTHONPATH=$(PYTHONPATH) PYTEST=1 $(VENV)/bin/py.test PYLINT := env PYTHONPATH=$(PYTHONPATH) $(VENV)/bin/pylint --disable=I0011 --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" -PEP8 := env PYTHONPATH=$(PYTHONPATH) $(VENV)/bin/pep8 --repeat --ignore=E202,E501 +PEP8 := env PYTHONPATH=$(PYTHONPATH) $(VENV)/bin/pep8 --repeat --ignore=E202,E501,E402 PYTHON := env PYTHONPATH=$(PYTHONPATH) $(VENV)/bin/python PIP := $(VENV)/bin/pip diff --git a/src/leiningen/new/python/conf/http.site b/src/leiningen/new/python/conf/http.site index 81e7cce..087c0f8 100644 --- a/src/leiningen/new/python/conf/http.site +++ b/src/leiningen/new/python/conf/http.site @@ -33,9 +33,19 @@ server { } location / { - include uwsgi_params; - uwsgi_pass 127.0.0.1:8082; - uwsgi_read_timeout 300; - uwsgi_send_timeout 300; + proxy_pass http://127.0.0.1:8082; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } + + # location / { + # include uwsgi_params; + # uwsgi_pass 127.0.0.1:8082; + # uwsgi_read_timeout 300; + # uwsgi_send_timeout 300; + # } } diff --git a/src/leiningen/new/python/conf/https.site b/src/leiningen/new/python/conf/https.site index 8a405d2..a6e5bc2 100644 --- a/src/leiningen/new/python/conf/https.site +++ b/src/leiningen/new/python/conf/https.site @@ -50,9 +50,19 @@ server { } location / { - include uwsgi_params; - uwsgi_pass 127.0.0.1:8082; - uwsgi_read_timeout 300; - uwsgi_send_timeout 300; + proxy_pass http://127.0.0.1:8082; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } + + # location / { + # include uwsgi_params; + # uwsgi_pass 127.0.0.1:8082; + # uwsgi_read_timeout 300; + # uwsgi_send_timeout 300; + # } } diff --git a/src/leiningen/new/python/conf/web.upstart b/src/leiningen/new/python/conf/web.upstart new file mode 100644 index 0000000..a9a48d3 --- /dev/null +++ b/src/leiningen/new/python/conf/web.upstart @@ -0,0 +1,18 @@ +description "TODO add description here" +start on runlevel [2345] +stop on runlevel [06] + +env LANG=en_US.UTF-8 +env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +env PORT=8082 + +chdir /opt/{{name}} +setuid www-data +setgid www-data + +exec make run + +kill timeout 10 + +respawn +respawn limit 10 5 diff --git a/src/leiningen/new/python/deb-scripts/after-install.sh b/src/leiningen/new/python/deb-scripts/after-install.sh index 8da906e..0a61e46 100644 --- a/src/leiningen/new/python/deb-scripts/after-install.sh +++ b/src/leiningen/new/python/deb-scripts/after-install.sh @@ -20,7 +20,7 @@ make bootstrap install # set how many copies to keep. # install "$PREFIX/conf/logrotate.conf" /etc/logrotate.d/{{name}} -# install "$PREFIX/conf/uwsgi.upstart" /etc/init/{{name}}.conf +# install "$PREFIX/conf/web.upstart" /etc/init/{{name}}.conf # start {{name}} || true # SITE_FILE=/etc/nginx/conf.d/{{name}}.conf diff --git a/src/leiningen/new/python/setup.py b/src/leiningen/new/python/setup.py index 604d58b..30b8e95 100644 --- a/src/leiningen/new/python/setup.py +++ b/src/leiningen/new/python/setup.py @@ -47,7 +47,7 @@ setup( 'Development Status :: 3 - Alpha', 'License :: OSI Approved :: GNU General Public License (GPL)', 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)', - 'Programming Language :: Python :: 2.7', - # 'Programming Language :: Python :: 3.3' + # 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', ] ) -- GitLab