Skip to content

Commit 3b450c0

Browse files
authored
Merge pull request #140 from TTWShell/bugfix/tpl
Bugfix/tpl
2 parents a1cd528 + 331f3ec commit 3b450c0

22 files changed

+28
-140
lines changed

.circleci/config.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ jobs:
4343
command: |
4444
pip install flake8 pytest pytest-cov pytest-env
4545
pip install --editable ".[hobbit,hobbit_core]"
46-
pip install celery
4746
- run:
4847
name: use flake8 check self
4948
command: flake8 .
5049
- run:
5150
name: run hobbit cmd
52-
command: hobbit --echo startproject -n demo -d ~/haha -f -p 1024 --no-celery
51+
command: hobbit --echo startproject -n demo -d ~/haha -f -p 1024
5352
- run:
5453
name: tree flask project
5554
command: |
@@ -75,17 +74,16 @@ jobs:
7574
command: |
7675
pip install flake8 pytest pytest-cov pytest-env
7776
pip install --editable ".[hobbit,hobbit_core]"
78-
pip install celery
7977
- run:
8078
name: use flake8 check self
8179
command: flake8 .
8280
- run:
8381
name: run hobbit cmd
8482
command: |
8583
mkdir ~/haha && cd ~/haha
86-
hobbit --echo startproject -n demo -f -p 1024 --celery
84+
hobbit --echo startproject -n demo -f -p 1024
8785
mkdir ~/hahaha && cd ~/hahaha
88-
hobbit --echo startproject -n demo -t rivendell -p 1025 --celery
86+
hobbit --echo startproject -n demo -t rivendell -p 1025
8987
- run:
9088
name: tree flask project
9189
command: |

Pipfile.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
from hobbit_core import HobbitManager # noqa
214214

215215
app = Flask('', root_path='.')
216+
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory"
216217
db = SQLAlchemy()
217218
db.init_app(app)
218219
hobbit = HobbitManager()

hobbit/bootstrap.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ def common_options(func):
3636
@click.option('-p', '--port', help='Port of web server.', required=True,
3737
type=click.IntRange(1024, 65535))
3838
@common_options
39-
@click.option('--celery/--no-celery', default=False,
40-
help='Generate celery files or not.')
4139
@click.pass_context
42-
def new(ctx, name, port, dist, template, force, celery):
40+
def new(ctx, name, port, dist, template, force):
4341
"""Create a new flask project, render from different template.
4442
4543
Examples::
@@ -52,14 +50,12 @@ def new(ctx, name, port, dist, template, force, celery):
5250
""" # noqa
5351
dist = os.getcwd() if dist is None else os.path.abspath(dist)
5452
ctx.obj['FORCE'] = force
55-
ctx.obj['CELERY'] = celery
5653
ctx.obj['JINJIA_CONTEXT'] = {
5754
'project_name': name,
5855
'port': port,
5956
'secret_key': ''.join(random.choice(
6057
string.ascii_letters) for i in range(38)),
6158
'version': pkg_resources.get_distribution("hobbit-core").version,
62-
'celery': celery,
6359
}
6460

6561
echo(f'Start init a hobbit project `{name}` to `{dist}`,'

hobbit/handlers/bootstrap.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def chdir(dist):
2929

3030
@click.pass_context
3131
def render_project(ctx, dist, tpl_path):
32-
celery = ctx.obj.get('CELERY') # gen cmd not have this arg
3332
context = ctx.obj['JINJIA_CONTEXT']
3433

3534
jinjia_env = Environment(loader=FileSystemLoader(tpl_path))
@@ -48,9 +47,6 @@ def render_project(ctx, dist, tpl_path):
4847
render_file(dist, fn[:-len(SUFFIX)], data)
4948
continue
5049

51-
if not celery and origin_path.endswith('tasks'):
52-
continue
53-
5450
dir_name = Template(fn).render(context)
5551
render_project(os.path.join(dist, dir_name),
5652
os.path.join(tpl_path, fn))

hobbit/static/bootstrap/rivendell/app/configs/default.py.jinja2

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@ SECRET_KEY = '{{ secret_key }}'
77
SQLALCHEMY_DATABASE_URI = 'sqlite:///{}'.format(
88
os.path.join(ROOT_PATH, '{{ project_name }}.db'))
99
SQLALCHEMY_TRACK_MODIFICATIONS = False
10-
{% if celery %}
11-
CELERY_TIMEZONE = 'Asia/Shanghai'
12-
BROKER_URL = 'sqla+sqlite:///celerydb.sqlite' # CELERY_BROKER_URL
13-
CELERY_RESULT_BACKEND = 'db+sqlite:///results.sqlite'
14-
{% endif %}
10+
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
from flask_sqlalchemy import SQLAlchemy
22
from flask_migrate import Migrate
33
from flask_marshmallow import Marshmallow
4-
{%- if celery %}
5-
from celery import Celery
6-
{%- endif %}
74

85
from hobbit_core import HobbitManager
96

107
db = SQLAlchemy()
118
migrate = Migrate()
129
ma = Marshmallow()
13-
{%- if celery %}
14-
celery = Celery()
15-
{%- endif %}
1610
hobbit = HobbitManager()
1711

hobbit/static/bootstrap/rivendell/app/run.py.jinja2

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from flask.helpers import get_env
66

77
from hobbit_core.err_handler import ErrHandler
88

9-
from app.exts import db, migrate, ma, hobbit{% if celery %}, celery{% endif %}
9+
from app.exts import db, migrate, ma, hobbit
1010

1111

1212
def register_extensions(app):
@@ -33,21 +33,6 @@ def register_cmds(app):
3333
pass
3434

3535

36-
{% if celery -%}
37-
def make_celery(app):
38-
celery.conf.update(app.config)
39-
40-
class ContextTask(celery.Task):
41-
def __call__(self, *args, **kwargs):
42-
with app.app_context():
43-
return self.run(*args, **kwargs)
44-
45-
celery.Task = ContextTask
46-
from app import tasks # NOQA
47-
return celery
48-
49-
50-
{% endif -%}
5136
def create_app():
5237
app = Flask(__name__, instance_relative_config=True)
5338
app.config.from_object('app.configs.{}'.format(get_env()))
@@ -57,9 +42,6 @@ def create_app():
5742
register_blueprints(app)
5843
register_error_handler(app)
5944
register_cmds(app)
60-
{%- if celery %}
61-
make_celery(app)
62-
{%- endif %}
6345

6446
@app.before_request
6547
def log_request_info():

hobbit/static/bootstrap/rivendell/app/tasks/__init__.py.jinja2

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
hobbit-core[hobbit,hobbit_core]=={{ version }}
2-
{% if celery -%}
3-
celery
4-
{% endif %}
1+
hobbit-core[hobbit,hobbit_core]=={{ version }}

hobbit/static/bootstrap/rivendell/tests/conftest.py.jinja2

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,4 @@ def app(request):
1818
@pytest.fixture(scope='session')
1919
def client(app, request):
2020
return app.test_client()
21-
{% if celery %}
2221

23-
@pytest.fixture(scope='session')
24-
def celery_config(app):
25-
return {
26-
'broker_url': 'sqla+sqlite:///.test/celerydb.sqlite',
27-
'result_backend': 'db+sqlite:///.test/celeryresults.sqlite'
28-
}
29-
30-
31-
@pytest.fixture(scope='session')
32-
def celery_app(app):
33-
from app.run import celery
34-
from celery.contrib.testing import tasks # NOQA
35-
return celery
36-
{% endif %}

hobbit/static/bootstrap/rivendell/tests/test_tools.py.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class TestAPIExample(BaseTest):
55

66
def test_ping_api(self, client):
77
resp = client.get('/api/ping')
8-
assert resp.status == 200
8+
assert resp.status_code == 200
99

1010

1111
class TestOption(BaseTest):
1212

1313
def test_options(self, client):
1414
resp = client.get('/api/options')
15-
assert resp.status == 200
15+
assert resp.status_code == 200
1616

hobbit/static/bootstrap/shire/app/configs/default.py.jinja2

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@ SECRET_KEY = '{{ secret_key }}'
77
SQLALCHEMY_DATABASE_URI = 'sqlite:///{}'.format(
88
os.path.join(ROOT_PATH, '{{ project_name }}.db'))
99
SQLALCHEMY_TRACK_MODIFICATIONS = False
10-
{% if celery %}
11-
CELERY_TIMEZONE = 'Asia/Shanghai'
12-
BROKER_URL = 'sqla+sqlite:///celerydb.sqlite' # CELERY_BROKER_URL
13-
CELERY_RESULT_BACKEND = 'db+sqlite:///results.sqlite'
14-
{% endif %}
10+
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
from flask_sqlalchemy import SQLAlchemy
22
from flask_migrate import Migrate
33
from flask_marshmallow import Marshmallow
4-
{%- if celery %}
5-
from celery import Celery
6-
{%- endif %}
74

85
from hobbit_core import HobbitManager
96

107
db = SQLAlchemy()
118
migrate = Migrate()
129
ma = Marshmallow()
13-
{%- if celery %}
14-
celery = Celery()
15-
{%- endif %}
1610
hobbit = HobbitManager()
1711

hobbit/static/bootstrap/shire/app/run.py.jinja2

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from flask.helpers import get_env
66

77
from hobbit_core.err_handler import ErrHandler
88

9-
from app.exts import db, migrate, ma, hobbit{% if celery %}, celery{% endif %}
9+
from app.exts import db, migrate, ma, hobbit
1010

1111

1212
def register_extensions(app):
@@ -33,21 +33,6 @@ def register_cmds(app):
3333
pass
3434

3535

36-
{% if celery -%}
37-
def make_celery(app):
38-
celery.conf.update(app.config)
39-
40-
class ContextTask(celery.Task):
41-
def __call__(self, *args, **kwargs):
42-
with app.app_context():
43-
return self.run(*args, **kwargs)
44-
45-
celery.Task = ContextTask
46-
from app import tasks # NOQA
47-
return celery
48-
49-
50-
{% endif -%}
5136
def create_app():
5237
app = Flask(__name__, instance_relative_config=True)
5338
app.config.from_object('app.configs.{}'.format(get_env()))
@@ -57,9 +42,6 @@ def create_app():
5742
register_blueprints(app)
5843
register_error_handler(app)
5944
register_cmds(app)
60-
{%- if celery %}
61-
make_celery(app)
62-
{%- endif %}
6345

6446
@app.before_request
6547
def log_request_info():

hobbit/static/bootstrap/shire/app/tasks/__init__.py.jinja2

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
hobbit-core[hobbit,hobbit_core]=={{ version }}
2-
{% if celery -%}
3-
celery
4-
{% endif %}
1+
hobbit-core[hobbit,hobbit_core]=={{ version }}

hobbit/static/bootstrap/shire/tests/conftest.py.jinja2

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,4 @@ def app(request):
1818
@pytest.fixture(scope='session')
1919
def client(app, request):
2020
return app.test_client()
21-
{% if celery %}
2221

23-
@pytest.fixture(scope='session')
24-
def celery_config(app):
25-
return {
26-
'broker_url': 'sqla+sqlite:///.test/celerydb.sqlite',
27-
'result_backend': 'db+sqlite:///.test/celeryresults.sqlite'
28-
}
29-
30-
31-
@pytest.fixture(scope='session')
32-
def celery_app(app):
33-
from app.run import celery
34-
from celery.contrib.testing import tasks # NOQA
35-
return celery
36-
{% endif %}

hobbit/static/bootstrap/shire/tests/test_tools.py.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class TestAPIExample(BaseTest):
55

66
def test_ping_api(self, client):
77
resp = client.get('/api/ping')
8-
assert resp.status == 200
8+
assert resp.status_code == 200
99

1010

1111
class TestOption(BaseTest):
1212

1313
def test_options(self, client):
1414
resp = client.get('/api/options')
15-
assert resp.status == 200
15+
assert resp.status_code == 200
1616

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def gen_data(data_root='static'):
1616

1717
package_data = gen_data()
1818
# The amount files of `shire[new]` + `rivendell[new]`
19-
assert len(package_data) == 28 + 29, \
19+
assert len(package_data) == 27 + 28, \
2020
'nums of tepl files error, {}'.format(len(package_data))
2121
package_data.append('py.typed')
2222

@@ -32,7 +32,7 @@ def gen_data(data_root='static'):
3232

3333
setup(
3434
name='hobbit-core',
35-
version='3.0.0.rc1',
35+
version='3.0.0.rc2',
3636
python_requires='>=3.7, <4',
3737
description='Hobbit - A flask project generator.',
3838
long_description=long_description,

tests/test_hobbit.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ def test_not_exist_cmd(self, runner):
3333
assert 'Error: cmd not exist: doesnotexistcmd' in result.output
3434

3535
@pytest.mark.parametrize(
36-
'name,template,celery_,dist',
36+
'name,template,dist',
3737
itertools.product(
38-
['haha'], templates, ['--celery', '--no-celery'],
38+
['haha'], templates,
3939
[None, '.', wkdir]))
4040
@chdir(wkdir)
41-
def test_new_cmd(self, runner, name, template, celery_, dist):
41+
def test_new_cmd(self, runner, name, template, dist):
4242
options = [
43-
'--echo', 'new', '-p 1024', '-n', name, '-t', template, celery_]
43+
'--echo', 'new', '-p 1024', '-n', name, '-t', template]
4444
if dist:
4545
assert os.getcwd() == os.path.abspath(dist)
4646
options.extend(['-d', dist])
@@ -52,14 +52,10 @@ def test_new_cmd(self, runner, name, template, celery_, dist):
5252

5353
file_nums = {
5454
# tart + 29 files + 11 dir + 1 end + empty
55-
'shire | --no-celery': 1 + 27 + 11 + 1 + 1 - 1,
56-
# start + files + mkdir + tail
57-
'shire | --celery': 1 + 28 + 12 + 1,
58-
'rivendell | --no-celery': 1 + 29 + 11 + 1,
59-
'rivendell | --celery': 1 + 30 + 12 + 1,
55+
'shire': 1 + 27 + 11 + 1 + 1 - 1,
56+
'rivendell': 1 + 29 + 11 + 1,
6057
}
61-
assert len(result.output.split('\n')) == file_nums[
62-
f'{template} | {celery_}']
58+
assert len(result.output.split('\n')) == file_nums[f'{template}']
6359

6460
assert subprocess.call(['flake8', '.']) == 0
6561
assert subprocess.call(

0 commit comments

Comments
 (0)