Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 9ffac2b

Browse files
authored
Remote dependency on distutils (#9125)
`distutils` is pretty much deprecated these days, and replaced with `setuptools`. It's also annoying because it's you can't `pip install` it, and it's hard to figure out which debian package we should depend on to make sure it's there. Since we only use it for a tiny function anyway, let's just vendor said function into our codebase.
1 parent d34c6e1 commit 9ffac2b

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

changelog.d/9125.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove dependency on `distutils`.

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
matrix-synapse-py3 (1.25.0ubuntu1) UNRELEASED; urgency=medium
2+
3+
* Remove dependency on `python3-distutils`.
4+
5+
-- Richard van der Hoff <[email protected]> Fri, 15 Jan 2021 12:44:19 +0000
6+
17
matrix-synapse-py3 (1.25.0) stable; urgency=medium
28

39
[ Dan Callahan ]

debian/control

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Pre-Depends: dpkg (>= 1.16.1)
3131
Depends:
3232
adduser,
3333
debconf,
34-
python3-distutils|libpython3-stdlib (<< 3.6),
3534
${misc:Depends},
3635
${shlibs:Depends},
3736
${synapse:pydepends},

synapse/config/registration.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
# limitations under the License.
1515

1616
import os
17-
from distutils.util import strtobool
1817

1918
import pkg_resources
2019

2120
from synapse.api.constants import RoomCreationPreset
2221
from synapse.config._base import Config, ConfigError
2322
from synapse.types import RoomAlias, UserID
24-
from synapse.util.stringutils import random_string_with_symbols
23+
from synapse.util.stringutils import random_string_with_symbols, strtobool
2524

2625

2726
class AccountValidityConfig(Config):
@@ -86,12 +85,12 @@ class RegistrationConfig(Config):
8685
section = "registration"
8786

8887
def read_config(self, config, **kwargs):
89-
self.enable_registration = bool(
90-
strtobool(str(config.get("enable_registration", False)))
88+
self.enable_registration = strtobool(
89+
str(config.get("enable_registration", False))
9190
)
9291
if "disable_registration" in config:
93-
self.enable_registration = not bool(
94-
strtobool(str(config["disable_registration"]))
92+
self.enable_registration = not strtobool(
93+
str(config["disable_registration"])
9594
)
9695

9796
self.account_validity = AccountValidityConfig(

synapse/events/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import abc
1919
import os
20-
from distutils.util import strtobool
2120
from typing import Dict, Optional, Tuple, Type
2221

2322
from unpaddedbase64 import encode_base64
@@ -26,6 +25,7 @@
2625
from synapse.types import JsonDict, RoomStreamToken
2726
from synapse.util.caches import intern_dict
2827
from synapse.util.frozenutils import freeze
28+
from synapse.util.stringutils import strtobool
2929

3030
# Whether we should use frozen_dict in FrozenEvent. Using frozen_dicts prevents
3131
# bugs where we accidentally share e.g. signature dicts. However, converting a
@@ -34,6 +34,7 @@
3434
# NOTE: This is overridden by the configuration by the Synapse worker apps, but
3535
# for the sake of tests, it is set here while it cannot be configured on the
3636
# homeserver object itself.
37+
3738
USE_FROZEN_DICTS = strtobool(os.environ.get("SYNAPSE_USE_FROZEN_DICTS", "0"))
3839

3940

synapse/util/stringutils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,22 @@ def shortstr(iterable: Iterable, maxitems: int = 5) -> str:
7575
if len(items) <= maxitems:
7676
return str(items)
7777
return "[" + ", ".join(repr(r) for r in items[:maxitems]) + ", ...]"
78+
79+
80+
def strtobool(val: str) -> bool:
81+
"""Convert a string representation of truth to True or False
82+
83+
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
84+
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
85+
'val' is anything else.
86+
87+
This is lifted from distutils.util.strtobool, with the exception that it actually
88+
returns a bool, rather than an int.
89+
"""
90+
val = val.lower()
91+
if val in ("y", "yes", "t", "true", "on", "1"):
92+
return True
93+
elif val in ("n", "no", "f", "false", "off", "0"):
94+
return False
95+
else:
96+
raise ValueError("invalid truth value %r" % (val,))

0 commit comments

Comments
 (0)