Skip to content

Commit

Permalink
Adds pep257 as a tox target
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Oct 11, 2016
1 parent 1ec4d4a commit 4cd5bc3
Show file tree
Hide file tree
Showing 124 changed files with 1,097 additions and 654 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ GIT=git
TOX=tox
ICONV=iconv
FLAKE8=flake8
PEP257=pep257
PYROMA=pyroma
FLAKEPLUS=flakeplus
SPHINX2RST=sphinx2rst
RST2HTML=rst2html.py
Expand Down Expand Up @@ -40,6 +42,7 @@ help:
@echo " flakes -------- - Check code for syntax and style errors."
@echo " flakecheck - Run flake8 on the source code."
@echo " flakepluscheck - Run flakeplus on the source code."
@echo " pep257check - Run pep257 on the source code."
@echo "readme - Regenerate README.rst file."
@echo "contrib - Regenerate CONTRIBUTING.rst file"
@echo "clean-dist --------- - Clean all distribution build artifacts."
Expand Down Expand Up @@ -90,6 +93,9 @@ flakecheck:
# the only way to enable all-1 errors is to ignore one of them.
$(FLAKE8) --ignore=X999 "$(PROJ)" "$(TESTDIR)"

pep257check:
$(PEP257) --ignore=D102,D104,D203,D105 "$(PROJ)"

flakediag:
-$(MAKE) flakecheck

Expand All @@ -99,7 +105,7 @@ flakepluscheck:
flakeplusdiag:
-$(MAKE) flakepluscheck

flakes: flakediag flakeplusdiag
flakes: flakediag flakeplusdiag pep257check

clean-readme:
-rm -f $(README)
Expand Down
15 changes: 9 additions & 6 deletions celery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""Distributed Task Queue"""
"""Distributed Task Queue."""
# :copyright: (c) 2015-2016 Ask Solem. All rights reserved.
# :copyright: (c) 2012-2014 GoPivotal, Inc., All rights reserved.
# :copyright: (c) 2009 - 2012 Ask Solem and individual contributors,
Expand Down Expand Up @@ -122,10 +122,13 @@ def maybe_patch_concurrency(argv=sys.argv,
short_opts=['-P'], long_opts=['--pool'],
patches={'eventlet': _patch_eventlet,
'gevent': _patch_gevent}):
"""With short and long opt alternatives that specify the command line
"""Apply eventlet/gevent monkeypatches.
With short and long opt alternatives that specify the command line
option to set the pool, this makes sure that anything that needs
to be patched is completed as early as possible.
(e.g., eventlet/gevent monkey patches)."""
(e.g., eventlet/gevent monkey patches).
"""
try:
pool = _find_option_with_arg(argv, short_opts, long_opts)
except KeyError:
Expand All @@ -143,9 +146,9 @@ def maybe_patch_concurrency(argv=sys.argv,
concurrency.get_implementation(pool)

# Lazy loading
from celery import five # noqa
from celery import local # noqa

old_module, new_module = five.recreate_module( # pragma: no cover
old_module, new_module = local.recreate_module( # pragma: no cover
__name__,
by_module={
'celery.app': ['Celery', 'bugreport', 'shared_task'],
Expand All @@ -162,7 +165,7 @@ def maybe_patch_concurrency(argv=sys.argv,
__package__='celery', __file__=__file__,
__path__=__path__, __doc__=__doc__, __version__=__version__,
__author__=__author__, __contact__=__contact__,
__homepage__=__homepage__, __docformat__=__docformat__, five=five,
__homepage__=__homepage__, __docformat__=__docformat__, local=local,
VERSION=VERSION, SERIES=SERIES, VERSION_BANNER=VERSION_BANNER,
version_info_t=version_info_t,
version_info=version_info,
Expand Down
1 change: 1 addition & 0 deletions celery/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


def main():
"""Entrypoint to the ``celery`` umbrella command."""
if 'multi' not in sys.argv:
maybe_patch_concurrency()
from celery.bin.celery import main
Expand Down
3 changes: 3 additions & 0 deletions celery/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@


def connect_on_app_finalize(callback):
"""Connect callback to be called when any app is finalized."""
_on_app_finalizers.add(callback)
return callback

Expand Down Expand Up @@ -66,6 +67,7 @@ class _TLS(threading.local):


def set_default_app(app):
"""Set default app."""
global default_app
default_app = app

Expand All @@ -87,6 +89,7 @@ def _set_current_app(app):

if os.environ.get('C_STRICT_APP'): # pragma: no cover
def get_current_app():
"""Return the current app."""
raise Exception('USES CURRENT APP')
import traceback
print('-- USES CURRENT_APP', file=sys.stderr) # noqa+
Expand Down
6 changes: 4 additions & 2 deletions celery/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@


def bugreport(app=None):
"""Return information useful in bug reports."""
return (app or current_app()).bugreport()


Expand Down Expand Up @@ -71,11 +72,13 @@ def _app_or_default_trace(app=None): # pragma: no cover


def enable_trace():
"""Enable tracing of app instances."""
global app_or_default
app_or_default = _app_or_default_trace


def disable_trace():
"""Disable tracing of app instances."""
global app_or_default
app_or_default = _app_or_default

Expand All @@ -86,7 +89,7 @@ def disable_trace():


def shared_task(*args, **kwargs):
"""Create shared tasks (decorator).
"""Create shared task (decorator).
This can be used by library authors to create tasks that'll work
for any app environment.
Expand All @@ -109,7 +112,6 @@ def shared_task(*args, **kwargs):
>>> add.app is app2
True
"""

def create_shared_task(**options):

def __inner(fun):
Expand Down
18 changes: 11 additions & 7 deletions celery/app/amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Queues(dict):
ha_policy (Sequence, str): Default HA policy for queues with none set.
max_priority (int): Default x-max-priority for queues with none set.
"""

#: If set, this is a subset of queues to consume from.
#: The rest of the queues are then used for routing only.
_consume_from = None
Expand Down Expand Up @@ -163,17 +164,18 @@ def format(self, indent=0, indent_first=True):
return info[0] + '\n' + textindent('\n'.join(info[1:]), indent)

def select_add(self, queue, **kwargs):
"""Add new task queue that'll be consumed from even when
a subset has been selected using the
:option:`celery worker -Q` option."""
"""Add new task queue that'll be consumed from.
The queue will be active even when a subset has been selected
using the :option:`celery worker -Q` option.
"""
q = self.add(queue, **kwargs)
if self._consume_from is not None:
self._consume_from[q.name] = q
return q

def select(self, include):
"""Sets :attr:`consume_from` by selecting a subset of the
currently defined queues.
"""Select a subset of currently defined queues to consume from.
Arguments:
include (Sequence[str], str): Names of queues to consume from.
Expand Down Expand Up @@ -210,6 +212,8 @@ def consume_from(self):


class AMQP(object):
"""App AMQP API: app.amqp."""

Connection = Connection
Consumer = Consumer
Producer = Producer
Expand Down Expand Up @@ -256,8 +260,8 @@ def send_task_message(self):

def Queues(self, queues, create_missing=None, ha_policy=None,
autoexchange=None, max_priority=None):
"""Create new :class:`Queues` instance, using queue defaults
from the current configuration."""
# Create new :class:`Queues` instance, using queue defaults
# from the current configuration.
conf = self.app.conf
if create_missing is None:
create_missing = conf.task_create_missing_queues
Expand Down
5 changes: 3 additions & 2 deletions celery/app/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


class MapAnnotation(dict):
"""Annotation map: task_name => attributes."""

def annotate_any(self):
try:
Expand All @@ -35,8 +36,7 @@ def annotate(self, task):


def prepare(annotations):
"""Expands the :setting:`task_annotations` setting."""

"""Expand the :setting:`task_annotations` setting."""
def expand_annotation(annotation):
if isinstance(annotation, dict):
return MapAnnotation(annotation)
Expand All @@ -52,4 +52,5 @@ def expand_annotation(annotation):


def resolve_all(anno, task):
"""Resolve all pending annotations."""
return (x for x in (_first_match(anno, task), _first_match_any(anno)) if x)
Loading

0 comments on commit 4cd5bc3

Please sign in to comment.