Skip to content

Commit abc49a5

Browse files
author
fireflyc
committed
first commit
0 parents  commit abc49a5

File tree

12 files changed

+139
-0
lines changed

12 files changed

+139
-0
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include README.md requirements.txt

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
PGPIDENT="fireflyc"
2+
PYTHON=python
3+
PIP=pip
4+
PIP_DOUBAN = -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
5+
6+
all: help
7+
8+
help:
9+
@echo "dist - distribute project."
10+
@echo "build - Build project using current python."
11+
@echo "test - Run unittests using current python."
12+
@echo "clean - clean"
13+
@echo " clean-pyc - Remove .pyc/__pycache__ files"
14+
@echo " clean-build - Remove setup artifacts."
15+
@echo "release - Make PyPI release."
16+
17+
clean: clean-pyc clean-build
18+
19+
release:
20+
python setup.py register sdist bdist_wheel upload --sign --identity="$(PGPIDENT)"
21+
22+
clean-pyc:
23+
-find . -type f -a \( -name "*.pyc" -o -name "*$$py.class" \) | xargs rm
24+
-find . -type d -name "__pycache__" | xargs rm -r
25+
26+
clean-build:
27+
rm -rf build/ dist/ .eggs/ *.egg-info/
28+
29+
test:
30+
$(PYTHON) setup.py test
31+
32+
build:
33+
$(PYTHON) setup.py sdist bdist_wheel
34+
35+
dist_3party:
36+
mkdir -p dist/thirdparty/pipcache
37+
$(PIP) download -r requirements.txt -d ./dist/thirdparty/pipcache $(PIP_DOUBAN)
38+
cp requirements.txt dist/thirdparty/
39+
echo "pip install --no-index --find-links=pipcache -r requirements.txt">dist/thirdparty/install.sh
40+
41+
dist: clean build dist_3party

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Python项目骨架
2+
建议使用virtualenv构建开发环境
3+
4+
* `pip install -r requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com` 安装依赖
5+
* `python setup.py develop` link开发环境

etc/python-skeleton-logging.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[loggers]
2+
keys=root
3+
4+
[handlers]
5+
keys=stream_handler
6+
7+
[formatters]
8+
keys=formatter
9+
10+
[logger_root]
11+
level=DEBUG
12+
handlers=stream_handler
13+
14+
[handler_stream_handler]
15+
class=StreamHandler
16+
level=DEBUG
17+
formatter=formatter
18+
args=(sys.stderr,)
19+
20+
[formatter_formatter]
21+
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s

etc/python-skeleton.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[database]
2+
host = localhost
3+
username = root
4+
password = root123

python_skeleton/__init__.py

Whitespace-only changes.

python_skeleton/cli.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import ConfigParser
2+
import click
3+
4+
from python_skeleton.demo import Demo
5+
from python_skeleton.lib import log
6+
7+
8+
@click.command()
9+
@click.option("--config-file", required=True, default="/etc/python-skeleton/python-skeleton.conf", help="config file", type=click.Path(exists=True))
10+
@click.option("--logging-file", required=True, default="/etc/python-skeleton/python-skeleton-logging.conf", help="logging file", type=click.Path(exists=True))
11+
def main(config_file, logging_file):
12+
log.setup_logging(logging_file)
13+
14+
config = ConfigParser.ConfigParser()
15+
config.read(config_file)
16+
demo = Demo()
17+
demo.hello("fireflyc")
18+
m
19+
20+
if __name__ == "__main__":
21+
import os
22+
import sys
23+
24+
parent_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
25+
etc_path = os.path.join(parent_path, "etc")
26+
sys.argv.append("--config-file=" + os.path.join(etc_path, "python-skeleton.conf"))
27+
sys.argv.append("--logging-file=" + os.path.join(etc_path, "python-skeleton-logging.conf"))
28+
main()

python_skeleton/demo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from python_skeleton.lib.log import LogMixin
2+
3+
4+
class Demo(LogMixin):
5+
def hello(self, name):
6+
self.logger.info("demo %s", name)
7+
return "Hello, " + name

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
click==6.6

setup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# coding=utf-8
2+
from setuptools import setup, find_packages
3+
from pip.req import parse_requirements
4+
5+
setup(
6+
name="python-skeleton",
7+
version="0.0.1",
8+
description="python skeleton demo",
9+
long_description=open("README.md").read(),
10+
author="fireflyc",
11+
author_email="[email protected]",
12+
url="",
13+
license="",
14+
packages=find_packages(exclude=("tests", "docs", "etc")),
15+
install_requires=[str(ir.req) for ir in parse_requirements("requirements.txt", session=False)],
16+
test_suite="tests",
17+
entry_points="""
18+
[console_scripts]
19+
python-skeleton=python_skeleton.cli:main
20+
"""
21+
)

tests/__init__.py

Whitespace-only changes.

tests/demo_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from unittest import TestCase
2+
from python_skeleton.demo import Demo
3+
4+
5+
class DemoTestCase(TestCase):
6+
def setUp(self):
7+
self.demo = Demo()
8+
9+
def test_hello(self):
10+
assert self.demo.hello("World") == "Hello, World"

0 commit comments

Comments
 (0)