Skip to content

Commit

Permalink
Format all code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoidi committed Feb 17, 2019
1 parent edaedd6 commit a4037da
Show file tree
Hide file tree
Showing 273 changed files with 8,044 additions and 4,487 deletions.
2 changes: 1 addition & 1 deletion dev_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _get_version():
with open('flexget/_version.py') as f:
g = globals()
l = {}
exec (f.read(), g, l) # pylint: disable=W0122
exec(f.read(), g, l) # pylint: disable=W0122
if not l['__version__']:
raise click.ClickException('Could not find __version__ from flexget/_version.py')
return l['__version__']
Expand Down
41 changes: 23 additions & 18 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.extlinks', 'sphinx.ext.doctest',
'sphinx.ext.intersphinx']
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.extlinks',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['templates']
Expand Down Expand Up @@ -178,20 +183,15 @@
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'FlexGet.tex', u'FlexGet Documentation',
u'FlexGet', 'manual'),
]
latex_documents = [('index', 'FlexGet.tex', u'FlexGet Documentation', u'FlexGet', 'manual')]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
Expand All @@ -218,10 +218,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'flexget', u'FlexGet Documentation',
[u'FlexGet'], 1)
]
man_pages = [('index', 'flexget', u'FlexGet Documentation', [u'FlexGet'], 1)]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand All @@ -233,9 +230,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'FlexGet', u'FlexGet Technical Documentation',
u'FlexGet', 'FlexGet', 'Automation tool.',
'Miscellaneous'),
(
'index',
'FlexGet',
u'FlexGet Technical Documentation',
u'FlexGet',
'FlexGet',
'Automation tool.',
'Miscellaneous',
)
]

# Documents to append as an appendix to all manuals.
Expand All @@ -250,14 +253,16 @@
# -- Extlinks for Trac ---------------------------------------------------------

# sphinx.ext.extlinks
extlinks = {'ticket': ('http://flexget.com/ticket/%s', 'ticket '),
'wiki': ('http://flexget.com/wiki/%s', 'wiki ')}
extlinks = {
'ticket': ('http://flexget.com/ticket/%s', 'ticket '),
'wiki': ('http://flexget.com/wiki/%s', 'wiki '),
}

intersphinx_mapping = {
'flask': ('http://flask.pocoo.org/docs/0.10/', None),
'flask_restful': ('http://flask-restful.readthedocs.org/en/0.3.3/', None),
'flask_restplus': ('http://flask-restplus.readthedocs.org/en/stable/', None),
'jsonschema': ('http://python-jsonschema.readthedocs.org/en/latest/', None),
'python': ('https://docs.python.org/2.7', None),
'requests': ('http://docs.python-requests.org/en/latest/', None)
'requests': ('http://docs.python-requests.org/en/latest/', None),
}
11 changes: 9 additions & 2 deletions flexget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def main(args=None):
except (IOError, ValueError) as e:
if _is_debug():
import traceback

traceback.print_exc()
else:
print('Could not instantiate manager: %s' % e, file=sys.stderr)
Expand All @@ -36,13 +37,18 @@ def main(args=None):
import cProfile as profile
except ImportError:
import profile
profile.runctx('manager.start()', globals(), locals(),
os.path.join(manager.config_base, manager.options.profile))
profile.runctx(
'manager.start()',
globals(),
locals(),
os.path.join(manager.config_base, manager.options.profile),
)
else:
manager.start()
except (IOError, ValueError) as e:
if _is_debug():
import traceback

traceback.print_exc()
else:
print('Could not start manager: %s' % e, file=sys.stderr)
Expand All @@ -51,6 +57,7 @@ def main(args=None):
except KeyboardInterrupt:
if _is_debug():
import traceback

traceback.print_exc()

print('Killed with keyboard interrupt.', file=sys.stderr)
Expand Down
11 changes: 10 additions & 1 deletion flexget/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
from __future__ import unicode_literals, division, absolute_import # noqa

from .app import api_app, api, APIResource, APIClient # noqa
from .core import authentication, cached, database, plugins, server, tasks, user, format_checker # noqa
from .core import (
authentication,
cached,
database,
plugins,
server,
tasks,
user,
format_checker,
) # noqa
112 changes: 70 additions & 42 deletions flexget/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def get_endpoint(self, url, data=None, method=None):
if method is None:
method = 'POST' if data is not None else 'GET'
auth_header = dict(Authorization='Token %s' % api_key())
response = self.app.open(url, data=data, follow_redirects=True, method=method, headers=auth_header)
response = self.app.open(
url, data=data, follow_redirects=True, method=method, headers=auth_header
)
result = json.loads(response.get_data(as_text=True))
# TODO: Proper exceptions
if 200 > response.status_code >= 300:
Expand Down Expand Up @@ -79,6 +81,7 @@ def wrapped(*args, **kwargs):

class APIResource(Resource):
"""All api resources should subclass this class."""

method_decorators = [with_session, api_version]

def __init__(self, api, *args, **kwargs):
Expand Down Expand Up @@ -129,7 +132,14 @@ def response(self, code_or_apierror, description='Success', model=None, **kwargs
if issubclass(code_or_apierror, APIError):
description = code_or_apierror.description or description
return self.doc(
responses={code_or_apierror.status_code: (description, code_or_apierror.response_model)}, **kwargs)
responses={
code_or_apierror.status_code: (
description,
code_or_apierror.response_model,
)
},
**kwargs
)
except TypeError:
# If first argument isn't a class this happens
pass
Expand All @@ -150,10 +160,16 @@ def pagination_parser(self, parser=None, sort_choices=None, default=None, add_so
pagination.add_argument('page', type=int, default=1, help='Page number')
pagination.add_argument('per_page', type=int, default=50, help='Results per page')
if sort_choices or add_sort:
pagination.add_argument('order', choices=('desc', 'asc'), default='desc', help='Sorting order')
pagination.add_argument(
'order', choices=('desc', 'asc'), default='desc', help='Sorting order'
)
if sort_choices:
pagination.add_argument('sort_by', choices=sort_choices, default=default or sort_choices[0],
help='Sort by attribute')
pagination.add_argument(
'sort_by',
choices=sort_choices,
default=default or sort_choices[0],
help='Sort by attribute',
)

return pagination

Expand All @@ -172,19 +188,18 @@ def pagination_parser(self, parser=None, sort_choices=None, default=None, add_so
title='Flexget API v{}'.format(__version__),
version=__version__,
description='View and manage flexget core operations and plugins. Open each endpoint view for usage information.'
' Navigate to http://flexget.com/API for more details.',
format_checker=format_checker
' Navigate to http://flexget.com/API for more details.',
format_checker=format_checker,
)

base_message = {
'type': 'object',
'properties': {
'status_code': {'type': 'integer'},
'message': {'type': 'string'},
'status': {'type': 'string'}
'status': {'type': 'string'},
},
'required': ['status_code', 'message', 'status']

'required': ['status_code', 'message', 'status'],
}

base_message_schema = api.schema_model('base_message', base_message)
Expand Down Expand Up @@ -244,35 +259,52 @@ class ValidationError(APIError):
status_code = 422
description = 'Validation error'

response_model = api.schema_model('validation_error', {
'type': 'object',
'properties': {
'validation_errors': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'message': {'type': 'string', 'description': 'A human readable message explaining the error.'},
'validator': {'type': 'string', 'description': 'The name of the failed validator.'},
'validator_value': {
'type': 'string', 'description': 'The value for the failed validator in the schema.'
response_model = api.schema_model(
'validation_error',
{
'type': 'object',
'properties': {
'validation_errors': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'message': {
'type': 'string',
'description': 'A human readable message explaining the error.',
},
'validator': {
'type': 'string',
'description': 'The name of the failed validator.',
},
'validator_value': {
'type': 'string',
'description': 'The value for the failed validator in the schema.',
},
'path': {'type': 'string'},
'schema_path': {'type': 'string'},
},
'path': {'type': 'string'},
'schema_path': {'type': 'string'},
}
},
}
}
},
'required': ['validation_errors'],
},
'required': ['validation_errors']
})
)

verror_attrs = (
'message', 'cause', 'validator', 'validator_value',
'path', 'schema_path', 'parent'
'message',
'cause',
'validator',
'validator_value',
'path',
'schema_path',
'parent',
)

def __init__(self, validation_errors, message='validation error'):
payload = {'validation_errors': [self._verror_to_dict(error) for error in validation_errors]}
payload = {
'validation_errors': [self._verror_to_dict(error) for error in validation_errors]
}
super(ValidationError, self).__init__(message, payload=payload)

def _verror_to_dict(self, error):
Expand All @@ -289,11 +321,7 @@ def _verror_to_dict(self, error):


def success_response(message, status_code=200, status='success'):
rsp_dict = {
'message': message,
'status_code': status_code,
'status': status
}
rsp_dict = {'message': message, 'status_code': status_code, 'status': status}
rsp = jsonify(rsp_dict)
rsp.status_code = status_code
return rsp
Expand Down Expand Up @@ -341,7 +369,11 @@ def wrapped(*args, **kwargs):
rv = make_response(rv)

# Some headers can change without data change for specific page
content_headers = rv.headers.get('link', '') + rv.headers.get('count', '') + rv.headers.get('total-count', '')
content_headers = (
rv.headers.get('link', '')
+ rv.headers.get('count', '')
+ rv.headers.get('total-count', '')
)
data = (rv.get_data().decode() + content_headers).encode()
etag = generate_etag(data)
rv.headers['Cache-Control'] = 'max-age=%s' % cache_age
Expand Down Expand Up @@ -398,8 +430,4 @@ def pagination_headers(total_pages, total_items, page_count, request):
link_string += LINKTEMPLATE.format(page + 1, 'next') + ', '
link_string += LINKTEMPLATE.format(total_pages, 'last')

return {
'Link': link_string,
'Total-Count': total_items,
'Count': page_count
}
return {'Link': link_string, 'Total-Count': total_items, 'Count': page_count}
Loading

0 comments on commit a4037da

Please sign in to comment.