Skip to content

Commit 7f2d936

Browse files
authored
Merge pull request #15 from TTWShell/enhance
Enhance
2 parents d9a5e9f + cdba811 commit 7f2d936

File tree

17 files changed

+107
-54
lines changed

17 files changed

+107
-54
lines changed

.circleci/config.yml

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,45 @@ jobs:
1414
- run:
1515
name: install dependencies && tox
1616
command: |
17+
# https://github.com/pyenv/pyenv/wiki/Common-build-problems
18+
apt-get install -y make build-essential libssl1.0-dev zlib1g-dev libbz2-dev \
19+
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
20+
xz-utils tk-dev libffi-dev liblzma-dev
1721
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
1822
export PATH="/root/.pyenv/bin:$PATH"
1923
eval "$(pyenv init -)"
2024
eval "$(pyenv virtualenv-init -)"
21-
pyenv install 3.7.0
22-
pyenv virtualenv -f 3.7.0 py37
23-
pyenv shell py37
24-
pip install tox
25+
pyenv install 2.7 && pyenv virtualenv -f 2.7 py27
26+
pyenv install 3.7.0 && pyenv virtualenv -f 3.7.0 py37
27+
pyenv shell py27 py37
28+
pip3 install tox
2529
tox
30+
test-py27:
31+
docker:
32+
- image: circleci/python:2.7
33+
user: root
34+
working_directory: ~/repo
35+
steps:
36+
- checkout
37+
- run:
38+
name: install dependencies
39+
command: pip install flake8 pytest pytest-cov && pip install --editable .
40+
- run:
41+
name: use flake8 check self
42+
command: flake8 .
43+
- run:
44+
name: run hobbit cmd
45+
command: hobbit --echo startproject -n demo -d ~/haha -f --example -p 1024
46+
- run:
47+
name: run tests
48+
environment:
49+
FLASK_APP: app/run.py
50+
FLASK_ENV: testing
51+
command: |
52+
cd ~/haha
53+
flask db init && flask db migrate && flask db upgrade
54+
flake8 . --exclude migrations
55+
py.test --cov . --cov-report term-missing -s
2656
test-py36:
2757
docker:
2858
- image: circleci/python:3.6
@@ -32,17 +62,13 @@ jobs:
3262
- checkout
3363
- run:
3464
name: install dependencies
35-
command: |
36-
pip install flake8 pytest pytest-cov
37-
pip install --editable .
65+
command: pip install flake8 pytest pytest-cov && pip install --editable .
3866
- run:
3967
name: use flake8 check self
40-
command: |
41-
flake8 .
68+
command: flake8 .
4269
- run:
4370
name: run hobbit cmd
44-
command: |
45-
hobbit --echo startproject -n demo -d ~/haha -f --example
71+
command: hobbit --echo startproject -n demo -d ~/haha -f --example -p 1024
4672
- run:
4773
name: tree flask project
4874
command: |
@@ -68,18 +94,15 @@ jobs:
6894
- checkout
6995
- run:
7096
name: install dependencies
71-
command: |
72-
pip install flake8 pytest pytest-cov
73-
pip install --editable .
97+
command: pip install flake8 pytest pytest-cov && pip install --editable .
7498
- run:
7599
name: use flake8 check self
76-
command: |
77-
flake8 .
100+
command: flake8 .
78101
- run:
79102
name: run hobbit cmd
80103
command: |
81104
mkdir ~/haha && cd ~/haha
82-
hobbit --echo startproject -n demo -f --example
105+
hobbit --echo startproject -n demo -f --example -p 1024
83106
- run:
84107
name: tree flask project
85108
command: |
@@ -102,6 +125,9 @@ workflows:
102125
test:
103126
jobs:
104127
- tox
128+
- test-py27:
129+
requires:
130+
- tox
105131
- test-py36:
106132
requires:
107133
- tox

hobbit_core/flask_hobbit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from flask import Flask
99

1010

11-
class HobbitManager:
11+
class HobbitManager(object):
1212
"""Customizable utils management.
1313
"""
1414

hobbit_core/flask_hobbit/db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# -*- encoding: utf-8 -*-
12
import enum
23

34
from sqlalchemy import Integer, Column, ForeignKey, func, DateTime
45

56

6-
class SurrogatePK:
7+
class SurrogatePK(object):
78
"""A mixin that add ``id``、``created_at`` and ``updated_at`` columns
89
to any declarative-mapped class.
910

hobbit_core/flask_hobbit/err_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# -*- encoding: utf-8 -*-
12
from sqlalchemy.orm import exc as orm_exc
23

34
from .response import Result, ServerErrorResult, gen_response, RESP_MSGS
45

56

6-
class ErrHandler:
7+
class ErrHandler(object):
78
"""Base error handler that catch all exceptions. Be sure response is::
89
910
{

hobbit_core/flask_hobbit/pagination.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- encoding: utf-8 -*-
12
from collections import Mapping
23
from flask_sqlalchemy import model
34

hobbit_core/flask_hobbit/response.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- encoding: utf-8 -*-
12
from flask.json import dumps
23
from werkzeug import Response
34

@@ -41,7 +42,7 @@ def __init__(self, response=None, status=None, headers=None,
4142
direct_passthrough=False):
4243
assert sorted(response.keys()) == ['code', 'detail', 'message'], \
4344
'错误的返回格式'
44-
return super().__init__(
45+
return super(Result, self).__init__(
4546
response=dumps(response, indent=0, separators=(',', ':')) + '\n',
4647
status=status or self.status, headers=headers, mimetype=mimetype,
4748
content_type=content_type, direct_passthrough=direct_passthrough)
@@ -53,7 +54,7 @@ class SuccessResult(Result):
5354
status = 200
5455

5556
def __init__(self, code=None, message='', detail=None, status=None):
56-
return super().__init__(
57+
return super(SuccessResult, self).__init__(
5758
gen_response(code or self.status, message, detail),
5859
self.status or status)
5960

@@ -64,7 +65,7 @@ class FailedResult(Result):
6465
status = 400
6566

6667
def __init__(self, code=None, message='', detail=None):
67-
return super().__init__(
68+
return super(FailedResult, self).__init__(
6869
gen_response(code or self.status, message, detail), self.status)
6970

7071

hobbit_core/flask_hobbit/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- encoding: utf-8 -*-
12
from marshmallow import Schema, fields
23

34

hobbit_core/flask_hobbit/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- encoding: utf-8 -*-
12
import six
23

34

hobbit_core/hobbit/bootstrap.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ def cli(ctx, force):
1717

1818
@cli.command()
1919
@click.option('-n', '--name', help='Name of project.', required=True)
20+
@click.option('-p', '--port', help='Port of web server.', required=True,
21+
type=click.IntRange(1024, 65535))
2022
@click.option('-d', '--dist', type=click.Path(), required=False,
2123
help='Dir for new project.')
2224
@click.option('-t', '--template', type=click.Choice(['shire']),
2325
default='shire', help='Template name.')
2426
@click.option('-f', '--force', default=False, is_flag=True,
2527
help='Force render files, covered if file exist.')
2628
@click.option('--example/--no-example', default=False,
27-
help='Generate apitest example files or not.')
29+
help='Generate api, test example files or not.')
2830
@click.pass_context
29-
def startproject(ctx, name, dist, template, force, example):
31+
def startproject(ctx, name, port, dist, template, force, example):
3032
"""Create a new flask project, render from different template.
3133
3234
Examples::
3335
34-
hobbit --echo startproject -n demo -d /tmp/test --example
36+
hobbit --echo startproject -n demo -d /tmp/test --example -p 1024
3537
3638
Other tips::
3739
@@ -42,6 +44,7 @@ def startproject(ctx, name, dist, template, force, example):
4244
ctx.obj['EXAMPLE'] = example
4345
ctx.obj['JINJIA_CONTEXT'] = {
4446
'project_name': name,
47+
'port': port,
4548
'secret_key': ''.join(random.choice(
4649
string.ascii_letters) for i in range(38)),
4750
'version': '.'.join(str(i) for i in VERSION),

hobbit_core/hobbit/handlers/bootstrap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
def chdir(dist):
1414
cwd = os.getcwd()
1515
echo('mkdir\t{}', (dist, ))
16-
os.makedirs(dist, exist_ok=True)
16+
# exist_ok py3 only
17+
if not os.path.exists(dist):
18+
os.makedirs(dist)
1719
os.chdir(dist)
1820
yield dist
1921
os.chdir(cwd)

0 commit comments

Comments
 (0)