Commit graph

53 commits

Author SHA1 Message Date
Anders Kaseorg
43a9263114 ruff: Fix SIM115 Use context handler for opening files.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-11-01 16:58:19 -07:00
Anders Kaseorg
03d132e99e ruff: Fix B007 Loop control variable not used within loop body.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-30 11:44:10 -07:00
Anders Kaseorg
347490c647 ruff: Fix RUF015 Prefer next(iter(…)) over single element slice.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-30 11:44:10 -07:00
Anders Kaseorg
610683ea41 ruff: Fix RUF005 Consider unpacking instead of concatenation.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-30 11:44:10 -07:00
Anders Kaseorg
12e63f493f ruff: Fix PLW2901 for loop variable overwritten by assignment target.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-30 11:44:10 -07:00
Anders Kaseorg
93bb7eb61e ruff: Fix PLR1714 Consider merging multiple comparisons.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-30 11:44:10 -07:00
Anders Kaseorg
7aeb8f2619 ruff: Fix PIE810 Call startswith once with a tuple.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-29 18:17:39 -07:00
Anders Kaseorg
008efed12b ruff: Fix SIM300 Yoda conditions are discouraged.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-29 18:17:39 -07:00
Anders Kaseorg
58a3026f37 ruff: Fix SIM102 Use a single if statement instead of nested if statements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-29 18:17:39 -07:00
Anders Kaseorg
774edb434e ruff: Fix C400 Unnecessary generator (rewrite as a list comprehension).
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-29 17:36:51 -07:00
Anders Kaseorg
6b2861c3ec ruff: Fix G004 Logging statement uses f-string.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-28 16:18:11 -07:00
Anders Kaseorg
d85ace8e7e ruff: Fix G003 Logging statement uses +.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-28 16:17:21 -07:00
Anders Kaseorg
02e0555e0d ruff: Fix G002 Logging statement uses %.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-28 16:17:21 -07:00
Anders Kaseorg
e537bbefdf ruff: Fix G001 Logging statement uses str.format.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-28 16:17:21 -07:00
Anders Kaseorg
63246e4369 ruff: Fix RUF010 Use explicit conversion flag.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-27 22:41:04 -07:00
Anders Kaseorg
fcd4fe330d ruff: Fix UP031 Use format specifiers instead of percent format.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-27 22:04:41 -07:00
Anders Kaseorg
ddccf0eda3 ruff: Fix UP032 Use f-string instead of format call.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-27 22:01:58 -07:00
Anders Kaseorg
2ecabb3260 Fix signal handler types.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-25 13:23:51 -07:00
Anders Kaseorg
a9607dfdf9 Convert type comments to Python ≥ 3.6 variable annotations.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-10-18 01:04:47 -07:00
Zixuan James Li
1b8f1d6e51 lint: Pin black to avoid inconsistent formatting.
This also runs black to reformat the affected files, which had been
causing failures because of upstream updates.

Ideally, we need a more sophisticated toolchain for managing the
versions of the dependencies instead of just requirements.txt. This
should be due in a possible future cleanup.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2023-05-29 10:53:22 -07:00
Anders Kaseorg
7831d979c9 zephyr: Free received notices with ZFreeNotice.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-01-24 12:23:44 -08:00
Anders Kaseorg
a534446315 zephyr: Remove python-zephyr in favor of ctypes.
Our custom patched version of python-zephyr only worked on Python 2.
Now we don’t need python-zephyr at all.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-09-13 16:43:40 -07:00
Anders Kaseorg
56f805a5d7 zephyr_mirror_backend: Fix thread safety problems.
As of commit 5eaac7bfba (#18),
zulip.Client is not thread-safe and especially not fork-safe due to
connections held open by requests.Session.

Delay construction of the Client until after forking off
zulip_to_zephyr.  Replace the fork for each message sent by
zephyr_to_zulip with a threaded queue worker.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-09-13 16:43:40 -07:00
Anders Kaseorg
5da0857d51 zephyr_mirror_backend: Add missing parens for calling lower().
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-08-28 08:32:07 -07:00
PIG208
9ce7c52a10 pyupgrade: Reformat with --py36-plus.
This includes mainly fixes of string literals using f-strings or
.format(...), as well as unpacking of list comprehensions.
2021-06-02 18:45:57 -07:00
PIG208
6f3f9bf7e4 black: Reformat without skipping string normalization. 2021-06-02 18:45:57 -07:00
PIG208
fba21bb00d black: Reformat skipping string normalization. 2021-06-02 18:45:57 -07:00
PIG208
5580c68ae5 isort: Reformat using isort. 2021-06-02 18:45:57 -07:00
Anders Kaseorg
503e8ed82d zephyr: Attempt to fix types.
The mirror has some chance of running on Python 3 now, once the
python-zephyr patch is rebased on 0.2.1, though it’s untested.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 23:59:15 -08:00
Anders Kaseorg
34012a4015 mypy: Add stubs for zephyr.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 23:59:15 -08:00
Alex Vandiver
7a7cfe637e zephyr: Mark the infinite loops as NoReturn. 2020-08-10 15:07:01 -07:00
Alex Vandiver
a20c9cc6d7 zephyr: Use exponential backoffs in retry loops.
This reduces the number of retries that might spam APIs.

There is some complexity here which is left un-managed -- for
instance, maybe_restart_mirroring_script does a number of restart
attempts, and then fails, but will be retried every 15s by the
surrounding `process_loop`.  Previously, it would merely have looped
forever inside maybe_restart_mirroring_script.

Three loops are intentionally left as infinite `while True` loops,
that merely cap their backoff at the default 90s.  Their callers do
not expect, or have any way to handle more gracefully, a failure of
the expected-infinite-loop in `process_loop` or `zulip_to_zephyr`.
They maintain their previous behavior of retrying forever, albeit more
slowly.
2020-08-10 15:07:01 -07:00
Anders Kaseorg
396ef1d11a Update zulipchat.com emails to zulip.com.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-11 21:06:58 -07:00
Anders Kaseorg
17cf26aa1f cleanup: Move line breaks before binary operators.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-18 20:31:14 -07:00
Anders Kaseorg
2f6623bbc4 cleanup: Remove unused imports.
Generated by autoflake.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-18 20:31:14 -07:00
Anders Kaseorg
5428c5f296 typing: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and two fixes for use-before-define
issues:

-    def set_zulip_client(self, zulipToJabberClient: ZulipToJabberBot) -> None:
+    def set_zulip_client(self, zulipToJabberClient: 'ZulipToJabberBot') -> None:

-def init_from_options(options: Any, client: Optional[str] = None) -> Client:
+def init_from_options(options: Any, client: Optional[str] = None) -> 'Client':

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-18 20:31:14 -07:00
Anders Kaseorg
e30b3b094b Modernize legacy Python 2 syntax with pyupgrade.
Generated by `pyupgrade --py3-plus --keep-percent-format` followed by
manual indentation fixes.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-18 15:04:36 -07:00
rht
46c78ce7b5 integrations: Remove usage of six. 2020-04-02 13:02:28 -04:00
rht
1412403037 integrations: Remove from __future__ imports. 2020-04-02 13:02:28 -04:00
rht
a465467388 integrations: Switch to python3. 2020-04-02 13:02:28 -04:00
neiljp (Neil Pilgrim)
60984ab2fa mypy: Add type ignores for mixing of str & bytes in zephyr mirror.
In principle these should be fixed properly, but the zephyr code is
difficult to test except in a production setting and is unlikely to be
heavily developed in future.
2020-03-24 21:25:45 -07:00
neiljp (Neil Pilgrim)
f81843f189 mypy: Clarify type hints in zulip/integrations/. 2020-03-24 21:25:45 -07:00
rht
8a74f576a3 python: Remove per-file copyright notices.
These notices are redundant and obscure what are often very short
example scripts.
2020-03-23 12:52:52 -07:00
XavierCooney
68ec3a5ef0 zephyr_mirror_backend.py: Remove duplicate import. 2018-01-16 08:07:09 -05:00
neiljp (Neil Pilgrim)
02d9ba8edd mypy: Add cast for zephyr_mirror_backend logger variable. 2018-01-08 15:39:03 -05:00
neiljp (Neil Pilgrim)
466f5a7167 mypy: Amend zephyr mirror annotations for strict-optional. 2018-01-08 15:39:03 -05:00
neiljp (Neil Pilgrim)
33ccc04a32 mypy: Amend code & typing of integrations, to pass with strict-optional. 2018-01-02 14:05:33 -05:00
neiljp (Neil Pilgrim)
28687f18ca mypy: Add --disallow-any=generics & extend typing accordingly.
Also reset typing of ExternalBotHandler to Any after discussion.
2017-12-11 20:14:00 -06:00
Tim Abbott
dc2132e629 zephyr_mirror: Eliminate --root-path arguments.
These were quite messy code, and now that almost nobody is running
their own zephyr mirroring script (vs. using webathena), making the
zephyr mirroring script deployable outside the package isn't super
valuable.
2017-10-05 13:24:59 -07:00
Tim Abbott
bc4e54a35d zephyr_mirror: Restart self using __file__, not root-path.
This should do the same thing, but with less complexity.
2017-10-05 12:46:01 -07:00