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
13This can be used with `st.register_type_strategy` to register strategies for your
14custom types, running the relevant code when *hypothesis* is imported instead of
15your package.
16"""
17
18import importlib.metadata
19import os
20
21
22def get_entry_points():
23 try:
24 eps = importlib.metadata.entry_points(group="hypothesis")
25 except TypeError: # pragma: no cover
26 # Load-time selection requires Python >= 3.10. See also
27 # https://importlib-metadata.readthedocs.io/en/latest/using.html
28 eps = importlib.metadata.entry_points().get("hypothesis", [])
29 yield from eps
30
31
32def run():
33 if not os.environ.get("HYPOTHESIS_NO_PLUGINS"):
34 for entry in get_entry_points(): # pragma: no cover
35 hook = entry.load()
36 if callable(hook):
37 hook()