Skip to content

Commit

Permalink
Update CLI commands to use Flask's CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjj committed Feb 16, 2020
1 parent e598568 commit 2c2ac45
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 99 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ COPY --from=webpack /app/public /public

COPY . .

RUN pip install --editable .

RUN if [ "${FLASK_ENV}" != "development" ]; then \
flask digest compile; fi

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ build a large web application with Flask**.

---

There's over 179 video lessons, 18.5+ hours of content, coding exercises and an
There's over 180 video lessons, 19+ hours of content, coding exercises and an
e-book that's included. You also get free updates for life as well as life time
support. I've added 10+ hours of free updates over the years.
support. I've added 11+ hours of free updates over the years.

Also as a bonus, there's an additional 18 video lessons and 3 hours of content
that covers building a separate RESTful API driven application that uses web sockets.
Expand Down
10 changes: 0 additions & 10 deletions SnakeEyes_CLI.egg-info/PKG-INFO

This file was deleted.

9 changes: 0 additions & 9 deletions SnakeEyes_CLI.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion SnakeEyes_CLI.egg-info/dependency_links.txt

This file was deleted.

4 changes: 0 additions & 4 deletions SnakeEyes_CLI.egg-info/entry_points.txt

This file was deleted.

1 change: 0 additions & 1 deletion SnakeEyes_CLI.egg-info/requires.txt

This file was deleted.

1 change: 0 additions & 1 deletion SnakeEyes_CLI.egg-info/top_level.txt

This file was deleted.

18 changes: 18 additions & 0 deletions cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import importlib
import os


def register_cli_commands(app):
"""
Register 0 or more Flask CLI commands (mutates the app passed in).
:param app: Flask application instance
:return: None
"""
for filename in os.listdir(os.path.dirname(__file__)):
if filename.endswith('.py') and filename.startswith('cmd_'):
module = importlib.import_module(f'cli.{filename[:-3]}')
cmd = getattr(module, filename[4:-3])
app.cli.add_command(cmd)

return None
49 changes: 0 additions & 49 deletions cli/cli.py

This file was deleted.

5 changes: 4 additions & 1 deletion cli/commands/cmd_cov.py → cli/cmd_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import click

from flask.cli import with_appcontext


@click.command()
@click.argument('path', default='snakeeyes')
def cli(path):
@with_appcontext
def cov(path):
"""
Run a test coverage report.
Expand Down
7 changes: 5 additions & 2 deletions cli/commands/cmd_flake8.py → cli/cmd_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import click

from flask.cli import with_appcontext


@click.command()
@click.option('--skip-init/--no-skip-init', default=True,
help='Skip __init__.py files?')
@click.argument('path', default='snakeeyes')
def cli(skip_init, path):
@click.argument('path', default='.')
@with_appcontext
def flake8(skip_init, path):
"""
Run flake8 to analyze your code base.
Expand Down
5 changes: 4 additions & 1 deletion cli/commands/cmd_test.py → cli/cmd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

import click

from flask.cli import with_appcontext


@click.command()
@click.argument('path', default=os.path.join('snakeeyes', 'tests'))
def cli(path):
@with_appcontext
def test(path):
"""
Run tests with Pytest.
Expand Down
Empty file removed cli/commands/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion config/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

bind = os.getenv('WEB_BIND', '0.0.0.0:8000')
accesslog = '-'
access_log_format = "%(h)s %(l)s %(u)s %(t)s '%(r)s' %(s)s %(b)s '%(f)s' '%(a)s' in %(D)sµs"
access_log_format = "%(h)s %(l)s %(u)s %(t)s '%(r)s' %(s)s %(b)s '%(f)s' '%(a)s' in %(D)sµs" # noqa: E501

workers = int(os.getenv('WEB_CONCURRENCY', multiprocessing.cpu_count() * 2))
threads = int(os.getenv('PYTHON_MAX_THREADS', 1))
Expand Down
15 changes: 0 additions & 15 deletions setup.py

This file was deleted.

2 changes: 2 additions & 0 deletions snakeeyes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from celery import Celery
from werkzeug.debug import DebuggedApplication

from cli import register_cli_commands
from snakeeyes.blueprints.page import page
from snakeeyes.blueprints.contact import contact
from snakeeyes.extensions import debug_toolbar, mail, csrf, flask_static_digest
Expand Down Expand Up @@ -54,6 +55,7 @@ def create_app(settings_override=None):
app.register_blueprint(page)
app.register_blueprint(contact)
extensions(app)
register_cli_commands(app)

if app.debug:
app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True)
Expand Down

0 comments on commit 2c2ac45

Please sign in to comment.