Skip to content

Commit 117cd9c

Browse files
Fixes build for PyPy3 (celery#6635)
* installs packages the same way docker does * removes couchbase dependency for PyPy * removes ephem dependency for PyPy * fixes mongo unit tests for PyPy3 Mocking `datetime.datetime` was causing an issue with `datetime.utcnow()`. This mock doesn't appear to be needed. See https://github.com/celery/celery/pull/6635/checks?check_run_id=1944166896. * fix: Avoid shadowing `Thread` attributes Fixes celery#6489 * ci: Install default deps for pypy3 toxenvs * ci: Run unit tests with `tox` * ci: Lint source in separate action using `tox` * ci: Redent codecov action * test: Rework some mocking in `test_platforms.py` Also fix some flakes which may have been added by some other autoformatter in celery#6804. The 4 space non-visual-indentation should keep most formatters fairly happy. * style: Fix some flakes Co-authored-by: maybe-sybr <58414429+maybe-sybr@users.noreply.github.com>
1 parent 47c5cea commit 117cd9c

File tree

16 files changed

+188
-164
lines changed

16 files changed

+188
-164
lines changed

.github/workflows/python-package.yml

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,31 @@ jobs:
4848
${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}
4949
restore-keys: |
5050
${{ matrix.python-version }}-v1-
51-
- name: Install dependencies
52-
run: |
53-
python -m pip install --upgrade pip
54-
python -m pip install flake8 pytest case pytest-celery pytest-subtests pytest-timeout pytest-cov
55-
python -m pip install moto boto3 msgpack PyYAML
56-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
5751
58-
- name: Run Unit test with pytest
59-
run: |
60-
PYTHONPATH=. pytest -xv --cov=celery --cov-report=xml --cov-report term t/unit
52+
- name: Install tox
53+
run: python -m pip install tox
54+
- name: >
55+
Run tox for
56+
"${{ matrix.python-version }}-unit"
57+
timeout-minutes: 15
58+
run: >
59+
tox --verbose --verbose -e
60+
"${{ matrix.python-version }}-unit"
61+
62+
- uses: codecov/codecov-action@v1
63+
with:
64+
flags: unittests # optional
65+
fail_ci_if_error: true # optional (default = false)
66+
verbose: true # optional (default = false)
6167

68+
lint:
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@v2
72+
- uses: actions/setup-python@v2
73+
# Must match the Python version in tox.ini for flake8
74+
with: { python-version: 3.9 }
75+
- name: Install tox
76+
run: python -m pip install tox
6277
- name: Lint with flake8
63-
run: |
64-
# stop the build if there are Python syntax errors or undefined names
65-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
66-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
67-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
68-
- uses: codecov/codecov-action@v1
69-
with:
70-
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
71-
flags: unittests # optional
72-
fail_ci_if_error: true # optional (default = false)
73-
verbose: true # optional (default = false)
78+
run: tox --verbose -e flake8

celery/backends/redis.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ class SentinelManagedSSLConnection(
585585

586586
class SentinelBackend(RedisBackend):
587587
"""Redis sentinel task result store."""
588+
588589
# URL looks like `sentinel://0.0.0.0:26347/3;sentinel://0.0.0.0:26348/3`
589590
_SERVER_URI_SEPARATOR = ";"
590591

@@ -598,9 +599,7 @@ def __init__(self, *args, **kwargs):
598599
super().__init__(*args, **kwargs)
599600

600601
def as_uri(self, include_password=False):
601-
"""
602-
Return the server addresses as URIs, sanitizing the password or not.
603-
"""
602+
"""Return the server addresses as URIs, sanitizing the password or not."""
604603
# Allow superclass to do work if we don't need to force sanitization
605604
if include_password:
606605
return super().as_uri(

celery/bin/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def say_chat(self, direction, title, body='', show_body=False):
116116

117117

118118
def handle_preload_options(f):
119+
"""Extract preload options and return a wrapped callable."""
119120
def caller(ctx, *args, **kwargs):
120121
app = ctx.obj.app
121122

celery/canvas.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,10 @@ def _freeze_group_tasks(self, _id=None, group_id=None, chord=None,
12531253

12541254
def freeze(self, _id=None, group_id=None, chord=None,
12551255
root_id=None, parent_id=None, group_index=None):
1256-
return self.app.GroupResult(*self._freeze_group_tasks(_id=_id, group_id=group_id,
1257-
chord=chord, root_id=root_id, parent_id=parent_id, group_index=group_index))
1256+
return self.app.GroupResult(*self._freeze_group_tasks(
1257+
_id=_id, group_id=group_id,
1258+
chord=chord, root_id=root_id, parent_id=parent_id, group_index=group_index
1259+
))
12581260

12591261
_freeze = freeze
12601262

celery/concurrency/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ def get_implementation(cls):
2929

3030

3131
def get_available_pool_names():
32+
"""Return all available pool type names."""
3233
return tuple(ALIASES.keys())

celery/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def __repr__(self):
304304

305305

306306
class CeleryCommandException(ClickException):
307+
"""A general command exception which stores an exit code."""
307308

308309
def __init__(self, message, exit_code):
309310
super().__init__(message=message)

celery/utils/threads.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class bgThread(threading.Thread):
4646

4747
def __init__(self, name=None, **kwargs):
4848
super().__init__()
49-
self._is_shutdown = threading.Event()
50-
self._is_stopped = threading.Event()
49+
self.__is_shutdown = threading.Event()
50+
self.__is_stopped = threading.Event()
5151
self.daemon = True
5252
self.name = name or self.__class__.__name__
5353

@@ -60,7 +60,7 @@ def on_crash(self, msg, *fmt, **kwargs):
6060

6161
def run(self):
6262
body = self.body
63-
shutdown_set = self._is_shutdown.is_set
63+
shutdown_set = self.__is_shutdown.is_set
6464
try:
6565
while not shutdown_set():
6666
try:
@@ -77,16 +77,16 @@ def run(self):
7777

7878
def _set_stopped(self):
7979
try:
80-
self._is_stopped.set()
80+
self.__is_stopped.set()
8181
except TypeError: # pragma: no cover
8282
# we lost the race at interpreter shutdown,
8383
# so gc collected built-in modules.
8484
pass
8585

8686
def stop(self):
8787
"""Graceful shutdown."""
88-
self._is_shutdown.set()
89-
self._is_stopped.wait()
88+
self.__is_shutdown.set()
89+
self.__is_stopped.wait()
9090
if self.is_alive():
9191
self.join(THREAD_TIMEOUT_MAX)
9292

celery/utils/timer2.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ def __init__(self, schedule=None, on_error=None, on_tick=None,
4949
self.on_start = on_start
5050
self.on_tick = on_tick or self.on_tick
5151
threading.Thread.__init__(self)
52-
self._is_shutdown = threading.Event()
53-
self._is_stopped = threading.Event()
52+
# `_is_stopped` is likely to be an attribute on `Thread` objects so we
53+
# double underscore these names to avoid shadowing anything and
54+
# potentially getting confused by the superclass turning these into
55+
# something other than an `Event` instance (e.g. a `bool`)
56+
self.__is_shutdown = threading.Event()
57+
self.__is_stopped = threading.Event()
5458
self.mutex = threading.Lock()
5559
self.not_empty = threading.Condition(self.mutex)
5660
self.daemon = True
@@ -71,7 +75,7 @@ def run(self):
7175
self.running = True
7276
self.scheduler = iter(self.schedule)
7377

74-
while not self._is_shutdown.isSet():
78+
while not self.__is_shutdown.isSet():
7579
delay = self._next_entry()
7680
if delay:
7781
if self.on_tick:
@@ -80,7 +84,7 @@ def run(self):
8084
break
8185
sleep(delay)
8286
try:
83-
self._is_stopped.set()
87+
self.__is_stopped.set()
8488
except TypeError: # pragma: no cover
8589
# we lost the race at interpreter shutdown,
8690
# so gc collected built-in modules.
@@ -91,9 +95,9 @@ def run(self):
9195
os._exit(1)
9296

9397
def stop(self):
94-
self._is_shutdown.set()
98+
self.__is_shutdown.set()
9599
if self.running:
96-
self._is_stopped.wait()
100+
self.__is_stopped.wait()
97101
self.join(THREAD_TIMEOUT_MAX)
98102
self.running = False
99103

celery/worker/consumer/consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
These tasks cannot be acknowledged as the connection is gone, and the tasks are automatically redelivered back to the queue.
120120
You can enable this behavior using the worker_cancel_long_running_tasks_on_connection_loss setting.
121121
In Celery 5.1 it is set to False by default. The setting will be set to True by default in Celery 6.0.
122-
"""
122+
""" # noqa: E501
123123

124124

125125
def dump_body(m, body):

requirements/extras/couchbase.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
couchbase>=3.0.0
1+
couchbase>=3.0.0; platform_python_implementation!='PyPy'

0 commit comments

Comments
 (0)