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

Remove dependency on distutils #9125

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/9125.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove dependency on `distutils`.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
matrix-synapse-py3 (1.25.0ubuntu1) UNRELEASED; urgency=medium

* Remove dependency on `python3-distutils`.

-- Richard van der Hoff <[email protected]> Fri, 15 Jan 2021 12:44:19 +0000

matrix-synapse-py3 (1.25.0) stable; urgency=medium

[ Dan Callahan ]
Expand Down
1 change: 0 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Pre-Depends: dpkg (>= 1.16.1)
Depends:
adduser,
debconf,
python3-distutils|libpython3-stdlib (<< 3.6),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nb that python3.X depends on libpython3.X-stdlib so we don't need to pull it in explicitly.

This was here to say that we didn't need a separate python3-distutils provided libpython3-stdlib was old enough. Now we don't need a separate python3-distutils at all, so the whole line is redundant.

${misc:Depends},
${shlibs:Depends},
${synapse:pydepends},
Expand Down
11 changes: 5 additions & 6 deletions synapse/config/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
# limitations under the License.

import os
from distutils.util import strtobool

import pkg_resources

from synapse.api.constants import RoomCreationPreset
from synapse.config._base import Config, ConfigError
from synapse.types import RoomAlias, UserID
from synapse.util.stringutils import random_string_with_symbols
from synapse.util.stringutils import random_string_with_symbols, strtobool


class AccountValidityConfig(Config):
Expand Down Expand Up @@ -86,12 +85,12 @@ class RegistrationConfig(Config):
section = "registration"

def read_config(self, config, **kwargs):
self.enable_registration = bool(
strtobool(str(config.get("enable_registration", False)))
self.enable_registration = strtobool(
str(config.get("enable_registration", False))
)
if "disable_registration" in config:
self.enable_registration = not bool(
strtobool(str(config["disable_registration"]))
self.enable_registration = not strtobool(
str(config["disable_registration"])
)

self.account_validity = AccountValidityConfig(
Expand Down
3 changes: 2 additions & 1 deletion synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import abc
import os
from distutils.util import strtobool
from typing import Dict, Optional, Tuple, Type

from unpaddedbase64 import encode_base64
Expand All @@ -26,6 +25,7 @@
from synapse.types import JsonDict, RoomStreamToken
from synapse.util.caches import intern_dict
from synapse.util.frozenutils import freeze
from synapse.util.stringutils import strtobool

# Whether we should use frozen_dict in FrozenEvent. Using frozen_dicts prevents
# bugs where we accidentally share e.g. signature dicts. However, converting a
Expand All @@ -34,6 +34,7 @@
# NOTE: This is overridden by the configuration by the Synapse worker apps, but
# for the sake of tests, it is set here while it cannot be configured on the
# homeserver object itself.

USE_FROZEN_DICTS = strtobool(os.environ.get("SYNAPSE_USE_FROZEN_DICTS", "0"))


Expand Down
19 changes: 19 additions & 0 deletions synapse/util/stringutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,22 @@ def shortstr(iterable: Iterable, maxitems: int = 5) -> str:
if len(items) <= maxitems:
return str(items)
return "[" + ", ".join(repr(r) for r in items[:maxitems]) + ", ...]"


def strtobool(val: str) -> bool:
"""Convert a string representation of truth to True or False

True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.

This is lifted from distutils.util.strtobool, with the exception that it actually
returns a bool, rather than an int.
"""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError("invalid truth value %r" % (val,))