Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate werkzeug.script #1090

Merged
merged 6 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Version 0.13
yet to be released

- Raise `TypeError` when port is not an integer.
- Fully deprecate `werkzeug.script`. Use `click`
(http://click.pocoo.org) instead.

Version 0.12.1
--------------
Expand Down
2 changes: 1 addition & 1 deletion docs/transition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ suggesting alternatives even if they will stick around for a longer time.
Do not use:

- `werkzeug.script`, replace it with custom scripts written with
`argparse` or something similar.
`argparse`, `click` or something similar.
- `werkzeug.template`, replace with a proper template engine.
- `werkzeug.contrib.jsrouting`, stop using URL generation for
JavaScript, it does not scale well with many public routing.
Expand Down
3 changes: 2 additions & 1 deletion examples/README
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Werkzeug powered applications.

Beside the proof of concept applications and code snippets in the partial
folder they all have external depencencies for template engines or database
adapters (SQLAlchemy only so far).
adapters (SQLAlchemy only so far). Also, every application has click as
external dependency, used to create the command line interface.


Full Example Applications
Expand Down
2 changes: 1 addition & 1 deletion examples/coolmagic/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def make_app(config=None):
app = CoolMagicApplication(config)

# static stuff
from werkzeug.utils import SharedDataMiddleware
from werkzeug.wsgi import SharedDataMiddleware
app = SharedDataMiddleware(app, {
'/public': path.join(path.dirname(__file__), 'public')
})
Expand Down
2 changes: 1 addition & 1 deletion examples/couchy/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from couchdb.schema import Document, TextField, BooleanField, DateTimeField
from couchdb.mapping import Document, TextField, BooleanField, DateTimeField
from couchy.utils import url_for, get_random_uid


Expand Down
53 changes: 48 additions & 5 deletions examples/manage-coolmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,55 @@
:copyright: (c) 2009 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import os
import click
from coolmagic import make_app
from werkzeug import script
from werkzeug.serving import run_simple

action_runserver = script.make_runserver(make_app, use_reloader=True)
action_shell = script.make_shell(lambda: {})

@click.group()
def cli():
pass


@cli.command()
@click.option('-h', '--hostname', type=str, default='localhost', help="localhost")
@click.option('-p', '--port', type=int, default=5000, help="5000")
@click.option('--no-reloader', is_flag=True, default=False)
@click.option('--debugger', is_flag=True)
@click.option('--no-evalex', is_flag=True, default=False)
@click.option('--threaded', is_flag=True)
@click.option('--processes', type=int, default=1, help="1")
def runserver(hostname, port, no_reloader, debugger, no_evalex, threaded, processes):
"""Start a new development server."""
app = make_app()
reloader = not no_reloader
evalex = not no_evalex
run_simple(hostname, port, app,
use_reloader=reloader, use_debugger=debugger,
use_evalex=evalex, threaded=threaded, processes=processes)


@cli.command()
@click.option('--no-ipython', is_flag=True, default=False)
def shell(no_ipython):
"""Start a new interactive python session."""
banner = 'Interactive Werkzeug Shell'
namespace = dict()
if not no_ipython:
try:
try:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmbed.instance(banner1=banner)
except ImportError:
from IPython.Shell import IPShellEmbed
sh = IPShellEmbed(banner=banner)
except ImportError:
pass
else:
sh(local_ns=namespace)
return
from code import interact
interact(banner, local=namespace)

if __name__ == '__main__':
script.run()
cli()
62 changes: 57 additions & 5 deletions examples/manage-couchy.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,69 @@
#!/usr/bin/env python
from werkzeug import script
import click
from werkzeug.serving import run_simple


def make_app():
from couchy.application import Couchy
return Couchy('http://localhost:5984')


def make_shell():
from couchy import models, utils
application = make_app()
return locals()

action_runserver = script.make_runserver(make_app, use_reloader=True)
action_shell = script.make_shell(make_shell)
action_initdb = lambda: make_app().init_database()

script.run()
@click.group()
def cli():
pass


@cli.command()
def initdb():
from couchy.application import Couchy
Couchy('http://localhost:5984').init_database()


@cli.command()
@click.option('-h', '--hostname', type=str, default='localhost', help="localhost")
@click.option('-p', '--port', type=int, default=5000, help="5000")
@click.option('--no-reloader', is_flag=True, default=False)
@click.option('--debugger', is_flag=True)
@click.option('--no-evalex', is_flag=True, default=False)
@click.option('--threaded', is_flag=True)
@click.option('--processes', type=int, default=1, help="1")
def runserver(hostname, port, no_reloader, debugger, no_evalex, threaded, processes):
"""Start a new development server."""
app = make_app()
reloader = not no_reloader
evalex = not no_evalex
run_simple(hostname, port, app,
use_reloader=reloader, use_debugger=debugger,
use_evalex=evalex, threaded=threaded, processes=processes)


@cli.command()
@click.option('--no-ipython', is_flag=True, default=False)
def shell(no_ipython):
"""Start a new interactive python session."""
banner = 'Interactive Werkzeug Shell'
namespace = make_shell()
if not no_ipython:
try:
try:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmbed.instance(banner1=banner)
except ImportError:
from IPython.Shell import IPShellEmbed
sh = IPShellEmbed(banner=banner)
except ImportError:
pass
else:
sh(local_ns=namespace)
return
from code import interact
interact(banner, local=namespace)

if __name__ == '__main__':
cli()
29 changes: 26 additions & 3 deletions examples/manage-cupoftee.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,35 @@
:copyright: (c) 2009 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from werkzeug import script
import click
from werkzeug.serving import run_simple


def make_app():
from cupoftee import make_app
return make_app('/tmp/cupoftee.db')
action_runserver = script.make_runserver(make_app)

script.run()

@click.group()
def cli():
pass


@cli.command()
@click.option('-h', '--hostname', type=str, default='localhost', help="localhost")
@click.option('-p', '--port', type=int, default=5000, help="5000")
@click.option('--reloader', is_flag=True, default=False)
@click.option('--debugger', is_flag=True)
@click.option('--evalex', is_flag=True, default=False)
@click.option('--threaded', is_flag=True)
@click.option('--processes', type=int, default=1, help="1")
def runserver(hostname, port, reloader, debugger, evalex, threaded, processes):
"""Start a new development server."""
app = make_app()
run_simple(hostname, port, app,
use_reloader=reloader, use_debugger=debugger,
use_evalex=evalex, threaded=threaded, processes=processes)


if __name__ == '__main__':
cli()
53 changes: 48 additions & 5 deletions examples/manage-i18nurls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,55 @@
:copyright: (c) 2009 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import os
import click
from i18nurls import make_app
from werkzeug import script
from werkzeug.serving import run_simple

action_runserver = script.make_runserver(make_app)
action_shell = script.make_shell(lambda: {})

@click.group()
def cli():
pass


@cli.command()
@click.option('-h', '--hostname', type=str, default='localhost', help="localhost")
@click.option('-p', '--port', type=int, default=5000, help="5000")
@click.option('--no-reloader', is_flag=True, default=False)
@click.option('--debugger', is_flag=True)
@click.option('--no-evalex', is_flag=True, default=False)
@click.option('--threaded', is_flag=True)
@click.option('--processes', type=int, default=1, help="1")
def runserver(hostname, port, no_reloader, debugger, no_evalex, threaded, processes):
"""Start a new development server."""
app = make_app()
reloader = not no_reloader
evalex = not no_evalex
run_simple(hostname, port, app,
use_reloader=reloader, use_debugger=debugger,
use_evalex=evalex, threaded=threaded, processes=processes)


@cli.command()
@click.option('--no-ipython', is_flag=True, default=False)
def shell(no_ipython):
"""Start a new interactive python session."""
banner = 'Interactive Werkzeug Shell'
namespace = dict()
if not no_ipython:
try:
try:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmbed.instance(banner1=banner)
except ImportError:
from IPython.Shell import IPShellEmbed
sh = IPShellEmbed(banner=banner)
except ImportError:
pass
else:
sh(local_ns=namespace)
return
from code import interact
interact(banner, local=namespace)

if __name__ == '__main__':
script.run()
cli()
60 changes: 52 additions & 8 deletions examples/manage-plnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
:copyright: (c) 2009 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import click
import os
from werkzeug import script
from werkzeug.serving import run_simple


def make_app():
Expand All @@ -22,11 +23,13 @@ def make_app():
return app


action_runserver = script.make_runserver(make_app, use_reloader=True)
action_shell = script.make_shell(lambda: {'app': make_app()})
@click.group()
def cli():
pass


def action_initdb():
@cli.command()
def initdb():
"""Initialize the database"""
from plnt.database import Blog, session
make_app().init_database()
Expand All @@ -51,15 +54,56 @@ def action_initdb():
for blog in blogs:
session.add(blog)
session.commit()
print 'Initialized database, now run manage-plnt.py sync to get the posts'
click.echo('Initialized database, now run manage-plnt.py sync to get the posts')


def action_sync():
@cli.command()
@click.option('-h', '--hostname', type=str, default='localhost', help="localhost")
@click.option('-p', '--port', type=int, default=5000, help="5000")
@click.option('--no-reloader', is_flag=True, default=False)
@click.option('--debugger', is_flag=True)
@click.option('--no-evalex', is_flag=True, default=False)
@click.option('--threaded', is_flag=True)
@click.option('--processes', type=int, default=1, help="1")
def runserver(hostname, port, no_reloader, debugger, no_evalex, threaded, processes):
"""Start a new development server."""
app = make_app()
reloader = not no_reloader
evalex = not no_evalex
run_simple(hostname, port, app,
use_reloader=reloader, use_debugger=debugger,
use_evalex=evalex, threaded=threaded, processes=processes)


@cli.command()
@click.option('--no-ipython', is_flag=True, default=False)
def shell(no_ipython):
"""Start a new interactive python session."""
banner = 'Interactive Werkzeug Shell'
namespace = {'app': make_app()}
if not no_ipython:
try:
try:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmbed.instance(banner1=banner)
except ImportError:
from IPython.Shell import IPShellEmbed
sh = IPShellEmbed(banner=banner)
except ImportError:
pass
else:
sh(local_ns=namespace)
return
from code import interact
interact(banner, local=namespace)


@cli.command()
def sync():
"""Sync the blogs in the planet. Call this from a cronjob."""
from plnt.sync import sync
make_app().bind_to_context()
sync()


if __name__ == '__main__':
script.run()
cli()
Loading