Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fireflyc committed Aug 4, 2016
0 parents commit abc49a5
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include README.md requirements.txt
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
PGPIDENT="fireflyc"
PYTHON=python
PIP=pip
PIP_DOUBAN = -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

all: help

help:
@echo "dist - distribute project."
@echo "build - Build project using current python."
@echo "test - Run unittests using current python."
@echo "clean - clean"
@echo " clean-pyc - Remove .pyc/__pycache__ files"
@echo " clean-build - Remove setup artifacts."
@echo "release - Make PyPI release."

clean: clean-pyc clean-build

release:
python setup.py register sdist bdist_wheel upload --sign --identity="$(PGPIDENT)"

clean-pyc:
-find . -type f -a \( -name "*.pyc" -o -name "*$$py.class" \) | xargs rm
-find . -type d -name "__pycache__" | xargs rm -r

clean-build:
rm -rf build/ dist/ .eggs/ *.egg-info/

test:
$(PYTHON) setup.py test

build:
$(PYTHON) setup.py sdist bdist_wheel

dist_3party:
mkdir -p dist/thirdparty/pipcache
$(PIP) download -r requirements.txt -d ./dist/thirdparty/pipcache $(PIP_DOUBAN)
cp requirements.txt dist/thirdparty/
echo "pip install --no-index --find-links=pipcache -r requirements.txt">dist/thirdparty/install.sh

dist: clean build dist_3party
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Python项目骨架
建议使用virtualenv构建开发环境

* `pip install -r requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com` 安装依赖
* `python setup.py develop` link开发环境
21 changes: 21 additions & 0 deletions etc/python-skeleton-logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[loggers]
keys=root

[handlers]
keys=stream_handler

[formatters]
keys=formatter

[logger_root]
level=DEBUG
handlers=stream_handler

[handler_stream_handler]
class=StreamHandler
level=DEBUG
formatter=formatter
args=(sys.stderr,)

[formatter_formatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s
4 changes: 4 additions & 0 deletions etc/python-skeleton.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[database]
host = localhost
username = root
password = root123
Empty file added python_skeleton/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions python_skeleton/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import ConfigParser
import click

from python_skeleton.demo import Demo
from python_skeleton.lib import log


@click.command()
@click.option("--config-file", required=True, default="/etc/python-skeleton/python-skeleton.conf", help="config file", type=click.Path(exists=True))
@click.option("--logging-file", required=True, default="/etc/python-skeleton/python-skeleton-logging.conf", help="logging file", type=click.Path(exists=True))
def main(config_file, logging_file):
log.setup_logging(logging_file)

config = ConfigParser.ConfigParser()
config.read(config_file)
demo = Demo()
demo.hello("fireflyc")
m

if __name__ == "__main__":
import os
import sys

parent_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
etc_path = os.path.join(parent_path, "etc")
sys.argv.append("--config-file=" + os.path.join(etc_path, "python-skeleton.conf"))
sys.argv.append("--logging-file=" + os.path.join(etc_path, "python-skeleton-logging.conf"))
main()
7 changes: 7 additions & 0 deletions python_skeleton/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from python_skeleton.lib.log import LogMixin


class Demo(LogMixin):
def hello(self, name):
self.logger.info("demo %s", name)
return "Hello, " + name
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
click==6.6
21 changes: 21 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# coding=utf-8
from setuptools import setup, find_packages
from pip.req import parse_requirements

setup(
name="python-skeleton",
version="0.0.1",
description="python skeleton demo",
long_description=open("README.md").read(),
author="fireflyc",
author_email="[email protected]",
url="",
license="",
packages=find_packages(exclude=("tests", "docs", "etc")),
install_requires=[str(ir.req) for ir in parse_requirements("requirements.txt", session=False)],
test_suite="tests",
entry_points="""
[console_scripts]
python-skeleton=python_skeleton.cli:main
"""
)
Empty file added tests/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/demo_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from unittest import TestCase
from python_skeleton.demo import Demo


class DemoTestCase(TestCase):
def setUp(self):
self.demo = Demo()

def test_hello(self):
assert self.demo.hello("World") == "Hello, World"

0 comments on commit abc49a5

Please sign in to comment.