Coverage for /usr/lib/python3/dist-packages/sympy/polys/polyconfig.py: 50%
28 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1"""Configuration utilities for polynomial manipulation algorithms. """
4from contextlib import contextmanager
6_default_config = {
7 'USE_COLLINS_RESULTANT': False,
8 'USE_SIMPLIFY_GCD': True,
9 'USE_HEU_GCD': True,
11 'USE_IRREDUCIBLE_IN_FACTOR': False,
12 'USE_CYCLOTOMIC_FACTOR': True,
14 'EEZ_RESTART_IF_NEEDED': True,
15 'EEZ_NUMBER_OF_CONFIGS': 3,
16 'EEZ_NUMBER_OF_TRIES': 5,
17 'EEZ_MODULUS_STEP': 2,
19 'GF_IRRED_METHOD': 'rabin',
20 'GF_FACTOR_METHOD': 'zassenhaus',
22 'GROEBNER': 'buchberger',
23}
25_current_config = {}
27@contextmanager
28def using(**kwargs):
29 for k, v in kwargs.items():
30 setup(k, v)
32 yield
34 for k in kwargs.keys():
35 setup(k)
37def setup(key, value=None):
38 """Assign a value to (or reset) a configuration item. """
39 key = key.upper()
41 if value is not None:
42 _current_config[key] = value
43 else:
44 _current_config[key] = _default_config[key]
47def query(key):
48 """Ask for a value of the given configuration item. """
49 return _current_config.get(key.upper(), None)
52def configure():
53 """Initialized configuration of polys module. """
54 from os import getenv
56 for key, default in _default_config.items():
57 value = getenv('SYMPY_' + key)
59 if value is not None:
60 try:
61 _current_config[key] = eval(value)
62 except NameError:
63 _current_config[key] = value
64 else:
65 _current_config[key] = default
67configure()