|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +"""Config for the Jupyter kernel that executes the docs pages. |
| 19 | +
|
| 20 | +``build.sh`` copies this into a throwaway ``IPYTHONDIR`` profile, which is |
| 21 | +where ``IPKernelApp`` looks for it. It is not on the Jupyter config path: |
| 22 | +``IPKernelApp`` derives from ``BaseIPythonApplication`` and reads the IPython |
| 23 | +profile directory, so ``JUPYTER_CONFIG_PATH`` has no effect on it. |
| 24 | +""" |
| 25 | + |
| 26 | +import logging |
| 27 | + |
| 28 | +# ipykernel 7 warns at every kernel start that the ZeroMQ channels are |
| 29 | +# unencrypted TCP. With `nb_execution_mode = "force"` the docs build starts a |
| 30 | +# kernel per executed page, so the message repeats a dozen times per build and |
| 31 | +# buries the output that matters. |
| 32 | +# |
| 33 | +# It does not describe a risk this build has. The kernel is a short-lived child |
| 34 | +# process on the same machine, executing pages from this repository, reachable |
| 35 | +# only over loopback. There is no second party to the conversation. |
| 36 | +# |
| 37 | +# Neither remedy the message itself suggests is usable here: |
| 38 | +# |
| 39 | +# - `transport="ipc"` does silence it, and it did work in isolation, but the |
| 40 | +# real build then fails with "Kernel didn't respond in 60 seconds". |
| 41 | +# - `KernelManager.transport_encryption = "auto"` fails at kernel start on |
| 42 | +# jupyter_client 8.9.1, which hands the provisioned CurveZMQ key to the |
| 43 | +# client as `str` where a `bytes` trait is expected. |
| 44 | +# |
| 45 | +# So the message is filtered rather than the condition removed. A filter is |
| 46 | +# used in preference to `c.Application.log_level = "ERROR"` so that any *other* |
| 47 | +# kernel warning still reaches the build log. If ipykernel rewords the message |
| 48 | +# this filter stops matching and the warning comes back, which is the right way |
| 49 | +# for it to fail. |
| 50 | +_SUPPRESSED = "Kernel is running over TCP without encryption" |
| 51 | + |
| 52 | + |
| 53 | +class _DropTransportEncryptionNotice(logging.Filter): |
| 54 | + """Drop ipykernel's unencrypted-TCP notice, and nothing else.""" |
| 55 | + |
| 56 | + def filter(self, record: logging.LogRecord) -> bool: |
| 57 | + """Return False only for the one message this build does not need.""" |
| 58 | + return _SUPPRESSED not in record.getMessage() |
| 59 | + |
| 60 | + |
| 61 | +# Traitlets names an Application's logger after its class. |
| 62 | +logging.getLogger("IPKernelApp").addFilter(_DropTransportEncryptionNotice()) |
0 commit comments