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

Commit 6f0c3e6

Browse files
author
David Robertson
authored
Don't require setuptools_rust at runtime (#13952)
1 parent 15754d7 commit 6f0c3e6

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

changelog.d/13952.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in v1.68.0 where Synapse would require `setuptools_rust` at runtime, even though the package is only required at build time.

synapse/util/check_dependencies.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ def _is_dev_dependency(req: Requirement) -> bool:
6666
)
6767

6868

69+
def _should_ignore_runtime_requirement(req: Requirement) -> bool:
70+
# This is a build-time dependency. Irritatingly, `poetry build` ignores the
71+
# requirements listed in the [build-system] section of pyproject.toml, so in order
72+
# to support `poetry install --no-dev` we have to mark it as a runtime dependency.
73+
# See discussion on https://github.com/python-poetry/poetry/issues/6154 (it sounds
74+
# like the poetry authors don't consider this a bug?)
75+
#
76+
# In any case, workaround this by ignoring setuptools_rust here. (It might be
77+
# slightly cleaner to put `setuptools_rust` in a `build` extra or similar, but for
78+
# now let's do something quick and dirty.
79+
if req.name == "setuptools_rust":
80+
return True
81+
return False
82+
83+
6984
class Dependency(NamedTuple):
7085
requirement: Requirement
7186
must_be_installed: bool
@@ -77,7 +92,7 @@ def _generic_dependencies() -> Iterable[Dependency]:
7792
assert requirements is not None
7893
for raw_requirement in requirements:
7994
req = Requirement(raw_requirement)
80-
if _is_dev_dependency(req):
95+
if _is_dev_dependency(req) or _should_ignore_runtime_requirement(req):
8196
continue
8297

8398
# https://packaging.pypa.io/en/latest/markers.html#usage notes that

tests/util/test_check_dependencies.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ class TestDependencyChecker(TestCase):
4040
def mock_installed_package(
4141
self, distribution: Optional[DummyDistribution]
4242
) -> Generator[None, None, None]:
43-
"""Pretend that looking up any distribution yields the given `distribution`."""
43+
"""Pretend that looking up any package yields the given `distribution`.
44+
45+
If `distribution = None`, we pretend that the package is not installed.
46+
"""
4447

4548
def mock_distribution(name: str):
4649
if distribution is None:
@@ -81,7 +84,7 @@ def test_version_reported_as_none(self) -> None:
8184
self.assertRaises(DependencyException, check_requirements)
8285

8386
def test_checks_ignore_dev_dependencies(self) -> None:
84-
"""Bot generic and per-extra checks should ignore dev dependencies."""
87+
"""Both generic and per-extra checks should ignore dev dependencies."""
8588
with patch(
8689
"synapse.util.check_dependencies.metadata.requires",
8790
return_value=["dummypkg >= 1; extra == 'mypy'"],
@@ -142,3 +145,16 @@ def test_release_candidates_satisfy_dependency(self) -> None:
142145
with self.mock_installed_package(new_release_candidate):
143146
# should not raise
144147
check_requirements()
148+
149+
def test_setuptools_rust_ignored(self) -> None:
150+
"""Test a workaround for a `poetry build` problem. Reproduces #13926."""
151+
with patch(
152+
"synapse.util.check_dependencies.metadata.requires",
153+
return_value=["setuptools_rust >= 1.3"],
154+
):
155+
with self.mock_installed_package(None):
156+
# should not raise, even if setuptools_rust is not installed
157+
check_requirements()
158+
with self.mock_installed_package(old):
159+
# We also ignore old versions of setuptools_rust
160+
check_requirements()

0 commit comments

Comments
 (0)