Skip to content

Commit 00b4b5c

Browse files
committed
Add tox+isort+black
Update .gitignore for this changes
1 parent 410d411 commit 00b4b5c

11 files changed

+457
-252
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ dump.rdb
77
/.direnv
88
.VScode
99
.DS_Store
10-
._*
10+
._*
11+
.tox/
12+
13+
.python-version

fabfile.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Common development operations."""
22

3-
from fabric.api import abort, local, lcd, env, settings, hide, quiet, task
43
import os
54
import os.path
65

6+
from fabric.api import abort, env, hide, lcd, local, quiet, settings, task
7+
78

89
def _relative_to_fabfile(*path):
910
return os.path.join(os.path.dirname(env.real_fabfile), *path)

requirements-dev.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
black~=19.10b0
2+
isort~=4.3.21

rq_dashboard/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .cli import main
22

33

4-
if __name__ == '__main__':
4+
if __name__ == "__main__":
55
main()

rq_dashboard/cli.py

+149-94
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import os
44
import sys
5-
from urllib.parse import urlunparse, quote as urlquote
5+
from urllib.parse import quote as urlquote, urlunparse
66

77
import click
88
from flask import Flask, Response, request
@@ -12,25 +12,25 @@
1212
from .web import blueprint
1313

1414

15-
def add_basic_auth(blueprint, username, password, realm='RQ Dashboard'):
15+
def add_basic_auth(blueprint, username, password, realm="RQ Dashboard"):
1616
"""Add HTTP Basic Auth to a blueprint.
1717
1818
Note this is only for casual use!
1919
2020
"""
21+
2122
@blueprint.before_request
2223
def basic_http_auth(*args, **kwargs):
2324
auth = request.authorization
24-
if (auth is None or auth.password != password or
25-
auth.username != username):
25+
if auth is None or auth.password != password or auth.username != username:
2626
return Response(
27-
'Please login',
27+
"Please login",
2828
401,
29-
{'WWW-Authenticate': 'Basic realm="{}"'.format(realm)})
29+
{"WWW-Authenticate": 'Basic realm="{}"'.format(realm)},
30+
)
3031

3132

32-
def make_flask_app(config, username, password, url_prefix,
33-
compatibility_mode=True):
33+
def make_flask_app(config, username, password, url_prefix, compatibility_mode=True):
3434
"""Return Flask app with default configuration and registered blueprint."""
3535
app = Flask(__name__)
3636

@@ -42,8 +42,8 @@ def make_flask_app(config, username, password, url_prefix,
4242
app.config.from_object(importlib.import_module(config))
4343

4444
# Override from a configuration file in the env variable, if present.
45-
if 'RQ_DASHBOARD_SETTINGS' in os.environ:
46-
app.config.from_envvar('RQ_DASHBOARD_SETTINGS')
45+
if "RQ_DASHBOARD_SETTINGS" in os.environ:
46+
app.config.from_envvar("RQ_DASHBOARD_SETTINGS")
4747

4848
# Optionally add basic auth to blueprint and register with app.
4949
if username:
@@ -55,66 +55,118 @@ def make_flask_app(config, username, password, url_prefix,
5555

5656
@click.command()
5757
@click.option(
58-
'-b', '--bind', default='0.0.0.0',
59-
help='IP or hostname on which to bind HTTP server')
60-
@click.option(
61-
'-p', '--port', default=9181, type=int,
62-
help='Port on which to bind HTTP server')
63-
@click.option(
64-
'--url-prefix', default='',
65-
help='URL prefix e.g. for use behind a reverse proxy')
66-
@click.option(
67-
'--username', default=None,
68-
help='HTTP Basic Auth username (not used if not set)')
69-
@click.option(
70-
'--password', default=None,
71-
help='HTTP Basic Auth password')
72-
@click.option(
73-
'-c', '--config', default=None,
74-
help='Configuration file (Python module on search path)')
75-
@click.option(
76-
'-H', '--redis-host', default=None, hidden=True,
77-
help='[DEPRECATED] IP address or hostname of Redis server. Use --redis-url instead')
78-
@click.option(
79-
'-P', '--redis-port', default=None, type=int, hidden=True,
80-
help='[DEPRECATED] Port of Redis server. Use --redis-url instead')
81-
@click.option(
82-
'--redis-password', default=None, hidden=True,
83-
help='[DEPRECATED] Password for Redis server. Use --redis-url instead')
84-
@click.option(
85-
'-D', '--redis-database', default=None, type=int, hidden=True,
86-
help='[DEPRECATED] Database of Redis server, Use --redis-url instead')
87-
@click.option(
88-
'-u', '--redis-url', default=None, multiple=True,
89-
help='Redis URL. Can be specified multiple times. Default: redis://127.0.0.1:6379')
90-
@click.option(
91-
'--redis-sentinels', default=None, hidden=True,
92-
help='[DEPRECATED] List of redis sentinels. Use --redis-url instead')
93-
@click.option(
94-
'--redis-master-name', default=None, hidden=True,
95-
help='[DEPRECATED] Name of redis master. Only needed when using sentinels. Use --redis-url instead')
96-
@click.option(
97-
'--poll-interval', '--interval', 'poll_interval', default=None, type=int,
98-
help='Refresh interval in ms')
99-
@click.option(
100-
'--extra-path', default='.', multiple=True,
101-
help='Append specified directories to sys.path')
102-
@click.option(
103-
'--web-background', default='black',
104-
help='Background of the web interface')
105-
@click.option(
106-
'--delete-jobs', default=False, help='Delete jobs instead of cancel')
107-
@click.option(
108-
'--debug/--normal', default=False, help='Enter DEBUG mode')
109-
@click.option(
110-
'-v', '--verbose', is_flag=True, default=False, help='Enable verbose logging')
58+
"-b",
59+
"--bind",
60+
default="0.0.0.0",
61+
help="IP or hostname on which to bind HTTP server",
62+
)
63+
@click.option(
64+
"-p", "--port", default=9181, type=int, help="Port on which to bind HTTP server"
65+
)
66+
@click.option(
67+
"--url-prefix", default="", help="URL prefix e.g. for use behind a reverse proxy"
68+
)
69+
@click.option(
70+
"--username", default=None, help="HTTP Basic Auth username (not used if not set)"
71+
)
72+
@click.option("--password", default=None, help="HTTP Basic Auth password")
73+
@click.option(
74+
"-c",
75+
"--config",
76+
default=None,
77+
help="Configuration file (Python module on search path)",
78+
)
79+
@click.option(
80+
"-H",
81+
"--redis-host",
82+
default=None,
83+
hidden=True,
84+
help="[DEPRECATED] IP address or hostname of Redis server. Use --redis-url instead",
85+
)
86+
@click.option(
87+
"-P",
88+
"--redis-port",
89+
default=None,
90+
type=int,
91+
hidden=True,
92+
help="[DEPRECATED] Port of Redis server. Use --redis-url instead",
93+
)
94+
@click.option(
95+
"--redis-password",
96+
default=None,
97+
hidden=True,
98+
help="[DEPRECATED] Password for Redis server. Use --redis-url instead",
99+
)
100+
@click.option(
101+
"-D",
102+
"--redis-database",
103+
default=None,
104+
type=int,
105+
hidden=True,
106+
help="[DEPRECATED] Database of Redis server, Use --redis-url instead",
107+
)
108+
@click.option(
109+
"-u",
110+
"--redis-url",
111+
default=None,
112+
multiple=True,
113+
help="Redis URL. Can be specified multiple times. Default: redis://127.0.0.1:6379",
114+
)
115+
@click.option(
116+
"--redis-sentinels",
117+
default=None,
118+
hidden=True,
119+
help="[DEPRECATED] List of redis sentinels. Use --redis-url instead",
120+
)
121+
@click.option(
122+
"--redis-master-name",
123+
default=None,
124+
hidden=True,
125+
help="[DEPRECATED] Name of redis master. Only needed when using sentinels. Use --redis-url instead",
126+
)
127+
@click.option(
128+
"--poll-interval",
129+
"--interval",
130+
"poll_interval",
131+
default=None,
132+
type=int,
133+
help="Refresh interval in ms",
134+
)
135+
@click.option(
136+
"--extra-path",
137+
default=".",
138+
multiple=True,
139+
help="Append specified directories to sys.path",
140+
)
141+
@click.option(
142+
"--web-background", default="black", help="Background of the web interface"
143+
)
144+
@click.option("--delete-jobs", default=False, help="Delete jobs instead of cancel")
145+
@click.option("--debug/--normal", default=False, help="Enter DEBUG mode")
146+
@click.option(
147+
"-v", "--verbose", is_flag=True, default=False, help="Enable verbose logging"
148+
)
111149
def run(
112-
bind, port, url_prefix, username, password,
113-
config,
114-
redis_host, redis_port, redis_password, redis_database, redis_url,
115-
redis_sentinels, redis_master_name,
116-
poll_interval, extra_path, web_background, debug, delete_jobs,
117-
verbose):
150+
bind,
151+
port,
152+
url_prefix,
153+
username,
154+
password,
155+
config,
156+
redis_host,
157+
redis_port,
158+
redis_password,
159+
redis_database,
160+
redis_url,
161+
redis_sentinels,
162+
redis_master_name,
163+
poll_interval,
164+
extra_path,
165+
web_background,
166+
debug,
167+
delete_jobs,
168+
verbose,
169+
):
118170
"""Run the RQ Dashboard Flask server.
119171
120172
All configuration can be set on the command line or through environment
@@ -129,63 +181,66 @@ def run(
129181
if extra_path:
130182
sys.path += list(extra_path)
131183

132-
click.echo('RQ Dashboard version {}'.format(VERSION))
184+
click.echo("RQ Dashboard version {}".format(VERSION))
133185
app = make_flask_app(config, username, password, url_prefix)
134-
app.config['DEPRECATED_OPTIONS'] = []
186+
app.config["DEPRECATED_OPTIONS"] = []
135187
if redis_url:
136-
app.config['RQ_DASHBOARD_REDIS_URL'] = redis_url
188+
app.config["RQ_DASHBOARD_REDIS_URL"] = redis_url
137189
else:
138-
app.config['RQ_DASHBOARD_REDIS_URL'] = 'redis://127.0.0.1:6379'
190+
app.config["RQ_DASHBOARD_REDIS_URL"] = "redis://127.0.0.1:6379"
139191
if redis_host:
140-
app.config['DEPRECATED_OPTIONS'].append('--redis-host')
192+
app.config["DEPRECATED_OPTIONS"].append("--redis-host")
141193
if redis_port:
142-
app.config['DEPRECATED_OPTIONS'].append('--redis-port')
194+
app.config["DEPRECATED_OPTIONS"].append("--redis-port")
143195
if redis_password:
144-
app.config['DEPRECATED_OPTIONS'].append('--redis-password')
196+
app.config["DEPRECATED_OPTIONS"].append("--redis-password")
145197
if redis_database:
146-
app.config['DEPRECATED_OPTIONS'].append('--redis-database')
198+
app.config["DEPRECATED_OPTIONS"].append("--redis-database")
147199
if redis_sentinels:
148-
app.config['DEPRECATED_OPTIONS'].append('--redis-sentinels')
200+
app.config["DEPRECATED_OPTIONS"].append("--redis-sentinels")
149201
if redis_master_name:
150-
app.config['DEPRECATED_OPTIONS'].append('--redis-master-name')
202+
app.config["DEPRECATED_OPTIONS"].append("--redis-master-name")
151203
if poll_interval:
152-
app.config['RQ_DASHBOARD_POLL_INTERVAL'] = poll_interval
204+
app.config["RQ_DASHBOARD_POLL_INTERVAL"] = poll_interval
153205
if web_background:
154206
app.config["RQ_DASHBOARD_WEB_BACKGROUND"] = web_background
155207
if delete_jobs:
156208
app.config["RQ_DASHBOARD_DELETE_JOBS"] = delete_jobs
157209
# Conditionally disable Flask console messages
158210
# See: https://stackoverflow.com/questions/14888799
159-
log = logging.getLogger('werkzeug')
211+
log = logging.getLogger("werkzeug")
160212
if verbose:
161213
log.setLevel(logging.DEBUG)
162214
else:
163215
log.setLevel(logging.ERROR)
164216
log.error(" * Running on {}:{}".format(bind, port))
165217

166-
if app.config['DEPRECATED_OPTIONS'] and not redis_url:
218+
if app.config["DEPRECATED_OPTIONS"] and not redis_url:
167219
# redis+sentinel://[:password@]host:port[,host2:port2,...][/service_name[/db]][?param1=value1[&param2=value=2&...]]
168-
scheme = 'redis+sentinel' if redis_sentinels else 'redis'
220+
scheme = "redis+sentinel" if redis_sentinels else "redis"
169221
if redis_sentinels:
170222
netloc = redis_sentinels
171223
else:
172-
netloc = redis_host or 'localhost'
224+
netloc = redis_host or "localhost"
173225
if redis_port:
174-
netloc = '%s:%s' % (netloc, redis_port)
226+
netloc = "%s:%s" % (netloc, redis_port)
175227
if redis_password:
176-
netloc = urlquote(redis_password) + '@' + netloc
177-
path = ''
228+
netloc = urlquote(redis_password) + "@" + netloc
229+
path = ""
178230
if redis_master_name:
179-
path += '/%s' % urlquote(redis_master_name)
231+
path += "/%s" % urlquote(redis_master_name)
180232
if redis_database:
181-
path += '/%s' % redis_database
182-
url = urlunparse((scheme, netloc, path, '', '', ''))
183-
log.error('Use --redis-url=%s configuration option '
184-
'instead of specifying host, port and other parameters separately', url)
185-
app.config['RQ_DASHBOARD_REDIS_URL'] = url
233+
path += "/%s" % redis_database
234+
url = urlunparse((scheme, netloc, path, "", "", ""))
235+
log.error(
236+
"Use --redis-url=%s configuration option "
237+
"instead of specifying host, port and other parameters separately",
238+
url,
239+
)
240+
app.config["RQ_DASHBOARD_REDIS_URL"] = url
186241

187242
app.run(host=bind, port=port, debug=debug)
188243

189244

190245
def main():
191-
run(auto_envvar_prefix='RQ_DASHBOARD')
246+
run(auto_envvar_prefix="RQ_DASHBOARD")

0 commit comments

Comments
 (0)