diff --git a/project.clj b/project.clj index e9832a62beda153af0c1ce3d16ab3397bfec1253..0c24e2021941bc3639b7ba461cf14918b55ef7fa 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject python/lein-template "0.20.5" +(defproject python/lein-template "1.0.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 7b5f9c1c5c4455c87cb9c3d7f86e07f9184175ba..be616ffb5174b6d7ee59a1c7d5dd4ad6d683d81c 100644 --- a/src/leiningen/new/python.clj +++ b/src/leiningen/new/python.clj @@ -46,6 +46,7 @@ "requirements-dev.txt" "setup.py" "README.rst" + "utils/versionutils.py" "utils/build-deb" "utils/install-git-hooks" "utils/trigger-jenkins-build" @@ -62,7 +63,8 @@ "git-hooks/post-merge" "git-hooks/pre-commit" ".gitignore"] - plain-files ["utils/choose_default_python.py" + plain-files ["utils/__init__.py" + "utils/choose_default_python.py" "utils/virtualenv-15.1.0/virtualenv.py" "utils/virtualenv-15.1.0/virtualenv_support/argparse-1.4.0-py2.py3-none-any.whl" "utils/virtualenv-15.1.0/virtualenv_support/setuptools-28.8.0-py2.py3-none-any.whl" @@ -70,8 +72,9 @@ "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 ["{{python-pkg-name}}/__init__.py"] - package-files ["logger.conf" + empty-files [] + package-files ["__init__.py" + "logger.conf" "configlogger.py" "config.py" "sanity_check.py" diff --git a/src/leiningen/new/python/Makefile b/src/leiningen/new/python/Makefile index ca0c9d9d7df135feeb7b4a8e692b8a61ce3841b3..9237c12b0accb79064f0dae074870cfd6573ac11 100644 --- a/src/leiningen/new/python/Makefile +++ b/src/leiningen/new/python/Makefile @@ -13,9 +13,13 @@ VIRTUALENV := ./utils/virtualenv-15.1.0/virtualenv.py REQUIREMENTS := -r requirements.txt DEV_REQUIREMENTS := -r requirements-dev.txt +VERSION := $(shell grep '__version__' {{python-pkg-name}}/__init__.py |cut -d'"' -f 2) + default: check-coding-style build: +version: + @echo $(VERSION) debug: env DEBUG=1 $(PYTHON) {{python-pkg-name}}/main.py run: diff --git a/src/leiningen/new/python/__init__.py b/src/leiningen/new/python/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..3dc1f76bc69e3f559bee6253b24fc93acee9e1f9 --- /dev/null +++ b/src/leiningen/new/python/__init__.py @@ -0,0 +1 @@ +__version__ = "0.1.0" diff --git a/src/leiningen/new/python/fabfile.py b/src/leiningen/new/python/fabfile.py index 9a6ff787b7f9694b94e01f44498a45c364f31652..b946fe31461016fc71bd965fb709298a0af52bbe 100644 --- a/src/leiningen/new/python/fabfile.py +++ b/src/leiningen/new/python/fabfile.py @@ -9,26 +9,15 @@ fabric file for server automation. import os.path from fabric.api import env, sudo, run, local, hosts, put, cd +from utils.versionutils import get_version_from_init_file + env.use_ssh_config = True PROD_HOST = 'de01' -def get_version_from_setup_file(): - """parse version info from setup.py file. - - Return the version string. - - """ - with open("setup.py", "r") as f: - for line in f: - if "version=" in line: - return line.split("=")[1][1:-3] - raise Exception("version not found in setup.py") - - @hosts(PROD_HOST) def deploy(): - version = get_version_from_setup_file() + version = get_version_from_init_file() deb_file = "{{name}}_%s_amd64.deb" % (version,) if not os.path.exists(deb_file): local("make deb") diff --git a/src/leiningen/new/python/setup.py b/src/leiningen/new/python/setup.py index 6dde669f9c54fb67636a4fb08287d946f7e1cc29..0c227c506a3fb239649c4978dd91412f9b93e271 100644 --- a/src/leiningen/new/python/setup.py +++ b/src/leiningen/new/python/setup.py @@ -9,6 +9,7 @@ from __future__ import (absolute_import, division, print_function, unicode_literals, with_statement) from setuptools import setup, find_packages +from utils.versionutils import get_version_from_init_file def requirements_file_to_list(fn="requirements.txt"): @@ -21,8 +22,8 @@ def requirements_file_to_list(fn="requirements.txt"): setup( name="{{name}}", - version="0.1.0", - packages=find_packages(), + version=get_version_from_init_file(), + packages=find_packages(exclude=("utils",)), install_requires=requirements_file_to_list(), dependency_links=[ "https://emacsos.com/python/packages/" diff --git a/src/leiningen/new/python/utils/__init__.py b/src/leiningen/new/python/utils/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/leiningen/new/python/utils/build-deb b/src/leiningen/new/python/utils/build-deb index 9274f7d02b32dc0c211050a035a6259d9a3ef430..db0061b37058e36a4be11e6e708e89d818c81ec0 100644 --- a/src/leiningen/new/python/utils/build-deb +++ b/src/leiningen/new/python/utils/build-deb @@ -12,7 +12,7 @@ if [ "$1" = "--help" ]; then print_help_and_exit fi -VERSION=`grep 'version' setup.py |cut -d'"' -f 2` +VERSION=`grep '__version__' {{python-pkg-name}}/__init__.py |cut -d'"' -f 2` DEB_PKG_NAME="{{name}}" DEST_DIR="/opt/$DEB_PKG_NAME" PYTHON_MODULES="{{python-pkg-name}}" diff --git a/src/leiningen/new/python/utils/versionutils.py b/src/leiningen/new/python/utils/versionutils.py new file mode 100644 index 0000000000000000000000000000000000000000..236e024e532aea3807380359049720fd161495fd --- /dev/null +++ b/src/leiningen/new/python/utils/versionutils.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +version utils +""" + +from __future__ import print_function, unicode_literals + + +def get_version_from_init_file(): + """parse version info from __init__.py file. + + Return the version string. + + """ + with open("{{python-pkg-name}}/__init__.py", "r") as f: + for line in f: + if "__version__" in line: + return line.split('"')[1] + raise Exception("__version__ not found in {{python-pkg-name}}/__init__.py") + + +def get_version_from_setup_file(): + """parse version info from setup.py file. + + Return the version string. + + """ + with open("setup.py", "r") as f: + for line in f: + if "version=" in line: + return line.split("=")[1][1:-3] + raise Exception("version not found in setup.py")