Skip to content

Commit 0af3c8a

Browse files
fix: set loop for services where missing (#441)
* fix: set loop for services where missing * chore: linting
1 parent c20e11c commit 0af3c8a

38 files changed

+55
-106
lines changed

extra/tools/verify_doc_defaults.py

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,36 @@
1515
from yarl import URL
1616

1717

18-
SETTINGS: Path = Path('docs/userguide/settings.rst')
18+
SETTINGS: Path = Path("docs/userguide/settings.rst")
1919

20-
app = faust.App('verify_defaults')
20+
app = faust.App("verify_defaults")
2121

2222
ignore_settings: Set[str] = {
23-
'id',
24-
'tabledir',
25-
'reply_to',
26-
'broker_consumer',
27-
'broker_producer',
23+
"id",
24+
"tabledir",
25+
"reply_to",
26+
"broker_consumer",
27+
"broker_producer",
2828
}
2929

3030
builtin_locals: Dict[str, Any] = {
31-
'aiohttp': aiohttp,
32-
'app': app,
33-
'datetime': datetime,
34-
'datadir': app.conf.datadir,
35-
'faust': faust,
36-
'logging': logging,
37-
'mode': mode,
38-
'socket': socket,
39-
'timedelta': timedelta,
40-
'web_host': socket.gethostname(),
41-
'web_port': 6066,
42-
'VERSION': faust.__version__,
43-
'uuid': uuid,
44-
'URL': URL,
31+
"aiohttp": aiohttp,
32+
"app": app,
33+
"datetime": datetime,
34+
"datadir": app.conf.datadir,
35+
"faust": faust,
36+
"logging": logging,
37+
"mode": mode,
38+
"socket": socket,
39+
"timedelta": timedelta,
40+
"web_host": socket.gethostname(),
41+
"web_port": 6066,
42+
"VERSION": faust.__version__,
43+
"uuid": uuid,
44+
"URL": URL,
4545
}
4646

47-
RE_REF = re.compile(r'^:(\w+):`')
47+
RE_REF = re.compile(r"^:(\w+):`")
4848

4949

5050
class Error(NamedTuple):
@@ -63,7 +63,7 @@ def verify_settings(rst_path: Path) -> Iterator[Error]:
6363
actual = actual.value
6464
if actual != default:
6565
yield Error(
66-
reason='mismatch',
66+
reason="mismatch",
6767
setting=setting_name,
6868
default=default,
6969
actual=actual,
@@ -74,53 +74,54 @@ def report_errors(errors: Iterator[Error]) -> int:
7474
num_errors: int = 0
7575
for num_errors, e in enumerate(errors, start=1):
7676
if num_errors == 1:
77-
carp(f'{sys.argv[0]}: Errors in docs/userguide/settings.rst:')
78-
carp(f' + Setting {e.reason} {e.setting}:')
79-
carp(f' documentation: {e.default!r}')
80-
carp(f' actual: {e.actual!r}')
77+
carp(f"{sys.argv[0]}: Errors in docs/userguide/settings.rst:")
78+
carp(f" + Setting {e.reason} {e.setting}:")
79+
carp(f" documentation: {e.default!r}")
80+
carp(f" actual: {e.actual!r}")
8181
if num_errors:
82-
carp(f'Found {num_errors} error(s).', file=sys.stderr)
82+
carp(f"Found {num_errors} error(s).", file=sys.stderr)
8383
else:
84-
print(f'{sys.argv[0]}: All OK :-)', file=sys.stdout)
84+
print(f"{sys.argv[0]}: All OK :-)", file=sys.stdout)
8585
return num_errors
8686

8787

8888
def carp(msg, *, file: IO = sys.stderr, **kwargs: Any) -> None:
8989
print(msg, file=file, **kwargs)
9090

9191

92-
def find_settings_in_rst(rst_path: Path,
93-
locals: Dict[str, Any] = None,
94-
builtin_locals: Dict[str, Any] = builtin_locals,
95-
ignore_settings: Set[str] = ignore_settings):
92+
def find_settings_in_rst(
93+
rst_path: Path,
94+
locals: Dict[str, Any] = None,
95+
builtin_locals: Dict[str, Any] = builtin_locals,
96+
ignore_settings: Set[str] = ignore_settings,
97+
):
9698
setting: str = None
9799
default: Any = None
98-
app = faust.App('_verify_doc_defaults')
100+
app = faust.App("_verify_doc_defaults")
99101
_globals = dict(globals())
100102
# Add setting default to globals
101103
# so that defaults referencing another setting work.
102104
# E.g.:
103105
# :default: :setting:`broker_api_version`
104-
_globals.update({
105-
name: getattr(app.conf, name)
106-
for name in app.conf.setting_names()
107-
})
106+
_globals.update(
107+
{name: getattr(app.conf, name) for name in app.conf.setting_names()}
108+
)
108109
local_ns: Dict[str, Any] = {**builtin_locals, **(locals or {})}
109110
for line in rst_path.read_text().splitlines():
110-
if line.startswith('.. setting::'):
111+
if line.startswith(".. setting::"):
111112
if setting and not default and setting not in ignore_settings:
112-
raise Exception(f'No default value for {setting}')
113-
setting = line.split('::')[-1].strip()
114-
elif ':default:' in line:
115-
if '``' in line:
116-
line, sep, rest = line.rpartition('``')
117-
default = line.split(':default:')[-1].strip()
118-
default = default.strip('`')
119-
default = RE_REF.sub('', default)
113+
raise Exception(f"No default value for {setting}")
114+
setting = line.split("::")[-1].strip()
115+
elif ":default:" in line:
116+
if "``" in line:
117+
line, sep, rest = line.rpartition("``")
118+
default = line.split(":default:")[-1].strip()
119+
default = default.strip("`")
120+
default = RE_REF.sub("", default)
120121
default_value = eval(default, _globals, local_ns)
121122
if setting not in ignore_settings:
122123
yield setting, default_value
123124

124125

125-
if __name__ == '__main__':
126+
if __name__ == "__main__":
126127
sys.exit(report_errors(verify_settings(SETTINGS)))

faust/agents/agent.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def __init__(
226226
"Agent concurrency must be 1 when using isolated partitions"
227227
)
228228
self.use_reply_headers = use_reply_headers
229-
Service.__init__(self)
229+
Service.__init__(self, loop=app.loop)
230230

231231
def on_init_dependencies(self) -> Iterable[ServiceT]:
232232
"""Return list of services dependencies required to start agent."""
@@ -1090,7 +1090,6 @@ def shortlabel(self) -> str:
10901090

10911091

10921092
class AgentTestWrapper(Agent, AgentTestWrapperT): # pragma: no cover
1093-
10941093
_stream: StreamT
10951094

10961095
def __init__(

faust/cli/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ class Command(abc.ABC): # noqa: B024
527527
@classmethod
528528
def as_click_command(cls) -> Callable: # pragma: no cover
529529
"""Convert command into :pypi:`click` command."""
530+
530531
# This is what actually registers the commands into the
531532
# :pypi:`click` command-line interface (the ``def cli`` main above).
532533
# __init_subclass__ calls this for the side effect of being

faust/livecheck/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(
176176
# signal attributes have the correct signal instance.
177177
self.__dict__.update(self.signals)
178178

179-
Service.__init__(self, **kwargs)
179+
Service.__init__(self, loop=app.loop, **kwargs)
180180

181181
@Service.timer(10.0)
182182
async def _sampler(self) -> None:

faust/models/fields.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ def prepare_value(
331331

332332

333333
class NumberField(FieldDescriptor[T]):
334-
335334
max_value: Optional[int]
336335
min_value: Optional[int]
337336

@@ -439,7 +438,6 @@ def validate(self, value: Decimal) -> Iterable[ValidationError]:
439438

440439

441440
class CharField(FieldDescriptor[CharacterType]):
442-
443441
max_length: Optional[int]
444442
min_length: Optional[int]
445443
trim_whitespace: bool

faust/models/tags.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def __format__(self, format_spec: str) -> str:
7979

8080

8181
class _FrameLocal(UserString, Generic[T]):
82-
8382
_field_name: str
8483
_tag_type: str
8584
_frame: str

faust/streams.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,6 @@ def get_key(withdrawal):
866866
if topic is not None:
867867
channel = topic
868868
else:
869-
870869
prefix = ""
871870
if self.prefix and not cast(TopicT, self.channel).has_prefix:
872871
prefix = self.prefix + "-"

faust/tables/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __init__(
125125
synchronize_all_active_partitions: bool = False,
126126
**kwargs: Any,
127127
) -> None:
128-
Service.__init__(self, **kwargs)
128+
Service.__init__(self, loop=app.loop, **kwargs)
129129
self.app = app
130130
self.name = cast(str, name) # set lazily so CAN BE NONE!
131131
self.default = default

faust/tables/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, table: Table, **kwargs: Any) -> None:
7272
self.table_name = self.table.name
7373
self.data = {}
7474
self._dirty = set()
75-
Service.__init__(self, **kwargs)
75+
Service.__init__(self, loop=table.loop, **kwargs)
7676

7777
def send_changelog_event(self, key: Any, operation: int, value: Any) -> None:
7878
"""Send changelog event to the tables changelog topic."""

faust/transport/consumer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,6 @@ def verify_recovery_event_path(self, now: float, tp: TP) -> None:
13631363

13641364

13651365
class ThreadDelegateConsumer(Consumer):
1366-
13671366
_thread: ConsumerThread
13681367

13691368
#: Main thread method queue.

0 commit comments

Comments
 (0)