File: common.py

package info (click to toggle)
sphinx-toolbox 3.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,924 kB
  • sloc: python: 11,636; sh: 26; javascript: 25; makefile: 16
file content (48 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# stdlib
from http import HTTPStatus
from types import SimpleNamespace
from typing import Any, Dict, NamedTuple, Sequence, Tuple

# 3rd party
import pytest
import sphinx


class AttrDict(dict):

	def __getattr__(self, item):  # noqa: MAN001,MAN002
		try:
			return self[item]
		except KeyError as e:
			raise AttributeError(str(e))

	def __setattr__(self, item, value):  # noqa: MAN001,MAN002
		self[item] = value


error_codes_list = [x for x in HTTPStatus if x not in {100, 200}]  # pylint: disable=not-an-iterable
error_codes = pytest.mark.parametrize("error_code", error_codes_list)


class AppParams(NamedTuple):
	args: Sequence[Any]
	kwargs: Dict[str, Any]


def get_app_config_values(config: Any) -> Tuple[str, str, Any]:
	if sphinx.version_info >= (7, 3):
		valid_types = config.valid_types
		default = config.default
		rebuild = config.rebuild
	else:
		default, rebuild, valid_types = config

	if isinstance(valid_types, (set, frozenset, tuple, list)):
		valid_types = sorted(valid_types)

	if hasattr(valid_types, "_candidates"):
		new_valid_types = SimpleNamespace()
		new_valid_types.candidates = sorted(valid_types._candidates)
		valid_types = new_valid_types

	return (default, rebuild, valid_types)