Debian Codegraph @

hypothesis-python/src/hypothesis/entry_points.py

raw
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Copyright the Hypothesis Authors.
5 # Individual contributors are listed in AUTHORS.rst and the git log.
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public License,
8 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9 # obtain one at https://mozilla.org/MPL/2.0/.
10
11 """Run all functions registered for the "hypothesis" entry point.
12
13 This can be used with `st.register_type_strategy` to register strategies for your
14 custom types, running the relevant code when *hypothesis* is imported instead of
15 your package.
16 """
17
18 import importlib.metadata
19 import os
20
21
22 def run() -> None:
23 if os.environ.get("HYPOTHESIS_NO_PLUGINS"):
24 return
25
26 for entry in importlib.metadata.entry_points(
27 group="hypothesis"
28 ): # pragma: no cover
29 hook = entry.load()
30 if callable(hook):
31 hook()