Commit 75597117 authored by Yuanle Song's avatar Yuanle Song
Browse files

v0.3.0 bundle virtualenv; support plain files in templates;

- bugfix: add "set -e" in utils/build-deb
- separate dev and prod requirements.txt files.
  do not install dev packages in prod. do not package them in deb.
- full-clean now also clean wheelhouse/
- update default pylint to 1.2.0
parent 575f6c8b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
(defproject python/lein-template "0.2.0"
(defproject python/lein-template "0.3.0"
  :description "lein template for a python project"
  :url "http://emacsos.com/lein/python"
  :license {:name "Eclipse Public License"
+40 −22
Original line number Diff line number Diff line
(ns leiningen.new.python
  (:require [leiningen.new.templates :refer [renderer name-to-path ->files
                                             *dir*]]
                                             *dir* sanitize]]
            [clojure.string :as string]
            [clojure.java.io :as io]
            [clojure.java.shell :as shell]
            [leiningen.core.main :as main])
@@ -9,6 +10,13 @@

(def render (renderer "python"))

(defn get-template-file
  "return a URL for given template path"
  [template]
  ;; io/resource returns the URL for a named resource. it finds it in
  ;; java classpath.
  (io/resource (str "leiningen/new/python/" template)))

(defn sh-output
  "return shell/sh's output, either stdout or stderr"
  [result]
@@ -25,8 +33,9 @@
              :date (let [cal (Calendar/getInstance)]
                      (.format (new SimpleDateFormat "yyyy-MM-dd")
                               (.getTime cal)))}
        plain-files ["Makefile"
        template-files ["Makefile"
                        "requirements.txt"
                        "requirements-dev.txt"
                        "setup.py"
                        "README.rst"
                        "utils/bootstrap"
@@ -40,17 +49,26 @@
                        "git-hooks/post-merge"
                        "git-hooks/pre-commit"
                        ".gitignore"]
        plain-files ["utils/pip-offline/argparse-1.2.1.tar.gz"
                     "utils/pip-offline/wheel-0.15.0.tar.gz"
                     "utils/virtualenv-1.9.1/virtualenv.py"
                     "utils/virtualenv-1.9.1/virtualenv_support/distribute-0.6.34.tar.gz"
                     "utils/virtualenv-1.9.1/virtualenv_support/__init__.py"
                     "utils/virtualenv-1.9.1/virtualenv_support/pip-1.5.3.tar.gz"
                     ]
        empty-files ["{{name}}/__init__.py"]
        post-run-commands [["chmod" "-R" "+x"
                            "utils/" "git-hooks/" "deb-scripts/"]]]
        post-run-commands ["chmod -R +x utils/ git-hooks/ deb-scripts/"
                           "find utils/pip-offline/ -type f -exec chmod -x {} +"]]
    (main/info "Generating new python project:" name)
    (apply ->files data
           (map (fn [f] [f ""]) empty-files))
    (apply ->files data
           ["{{name}}/logger.conf" (render "logger.conf" data)]
           (map (fn [f] [f (render f data)]) plain-files))
           (concat
            (map (fn [f] [f ""]) empty-files)
            (map (fn [f] [f (render f data)]) template-files)
            (map (fn [f] [f (io/input-stream (get-template-file f))])
                 plain-files)))
    (shell/with-sh-dir *dir*
      (doseq [cmd post-run-commands]
      (doseq [cmd (map (fn [cmd] (string/split cmd #" ")) post-run-commands)]
        (sh-output (apply shell/sh cmd))))
    ;; run git init if no .git found.
    (if (not (.exists (io/file *dir* ".git")))
+12 −6
Original line number Diff line number Diff line
@@ -12,10 +12,16 @@ run:
	$(PYTHON) {{name}}/main.py
bootstrap:
	@./utils/bootstrap
bootstrap-dev:
	@./utils/bootstrap dev
install: bootstrap
	bin/python setup.py -q install
deb:
	utils/build-deb
wheel: bootstrap-dev
	echo "building wheelhouse..."
	bin/pip install --use-wheel wheel
	bin/pip wheel -f http://apt.yygamedev.com/python/ -r requirements.txt
check: test
pylint: bootstrap
	$(PEP8) $(PYTHON_MODULES)
@@ -25,12 +31,12 @@ pylint-full: pylint
test: pylint
	$(PYTEST) $(PYTHON_MODULES)
clean:
	find . -name "__pycache__" -type d -exec rm -rf {} \;
	find . -name "*.pyc" -type f -exec rm -rf {} \;
	find . -name "__pycache__" -type d -exec rm -rf {} \; || true
	find . -name "*.pyc" -type f -exec rm -rf {} \; || true
full-clean:
	rm -rf local/ lib/ bin/ include/ build/ dist/ {{name}}.egg-info/
	find . -name "__pycache__" -type d -exec rm -rf {} \;
	find . -name "*.pyc" -type f -exec rm -rf {} \;
	rm -rf local/ lib/ bin/ include/ build/ dist/ wheelhouse/ {{name}}.egg-info/ distribute-*.tar.gz
	find . -name "__pycache__" -type d -exec rm -rf {} \; || true
	find . -name "*.pyc" -type f -exec rm -rf {} \; || true
TAGS:
	etags -R --exclude=static $(PYTHON_MODULES)
update-git-hooks: install-git-hooks-force
@@ -40,4 +46,4 @@ install-git-hooks-force:
	./utils/install-git-hooks -f
loc:
	find . -regex '.*\.pyw?$$' -exec wc -l {} \+ | tail -n 1
.PHONY: default build bootstrap check pylint pylint-full test clean full-clean TAGS loc install uninstall all update
.PHONY: default build bootstrap check pylint pylint-full test clean full-clean TAGS loc install uninstall all update wheel
+3 −0
Original line number Diff line number Diff line
pytest==2.5.2
pylint==1.2.0
pep8==1.4.6
+0 −3
Original line number Diff line number Diff line
pytest==2.5.2
pylint==1.1.0
pep8==1.4.6
yygame-utils==0.5.0
# raven==3.6.1
Loading