or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ast-visitor.mdbadge-generation.mdcli-interface.mdconfiguration.mdcoverage-analysis.mdindex.mdutilities.md

configuration.mddocs/

0

# Configuration

1

2

Configuration management for interrogate supporting multiple configuration sources including command-line arguments, pyproject.toml, and setup.cfg files. Provides unified configuration interface with validation and sensible defaults.

3

4

## Capabilities

5

6

### Configuration Class

7

8

Main configuration object that holds all interrogate settings and options.

9

10

```python { .api }

11

class InterrogateConfig:

12

"""Configuration object for interrogate analysis."""

13

14

# Class constants

15

VALID_STYLES: Tuple[str, ...] = ("sphinx", "google")

16

17

# Attributes (using attr.s decorator)

18

color: bool = False # Enable colored output

19

docstring_style: str = "sphinx" # Docstring style validation

20

fail_under: float = 80.0 # Coverage threshold

21

ignore_regex: bool = False # Regex patterns to ignore

22

ignore_magic: bool = False # Ignore magic methods

23

ignore_module: bool = False # Ignore module docstrings

24

ignore_private: bool = False # Ignore private methods

25

ignore_semiprivate: bool = False # Ignore semiprivate methods

26

ignore_init_method: bool = False # Ignore __init__ methods

27

ignore_init_module: bool = False # Ignore __init__.py modules

28

ignore_nested_classes: bool = False # Ignore nested classes

29

ignore_nested_functions: bool = False # Ignore nested functions

30

ignore_property_setters: bool = False # Ignore property setters

31

ignore_property_decorators: bool = False # Ignore property decorators

32

ignore_overloaded_functions: bool = False # Ignore @overload functions

33

include_regex: bool = False # Regex patterns to include

34

omit_covered_files: bool = False # Omit 100% covered files

35

```

36

37

### Configuration Discovery

38

39

Functions for finding and loading configuration from project files.

40

41

```python { .api }

42

def find_project_root(srcs):

43

"""

44

Find the project root directory.

45

46

Args:

47

srcs: Source paths to analyze

48

49

Returns:

50

pathlib.Path: Path to project root directory

51

"""

52

53

def find_project_config(path_search_start):

54

"""

55

Find project configuration file (pyproject.toml or setup.cfg).

56

57

Args:

58

path_search_start: Directory to start searching from

59

60

Returns:

61

str or None: Path to configuration file, or None if not found

62

"""

63

```

64

65

### Configuration Parsing

66

67

Functions for parsing configuration from different file formats.

68

69

```python { .api }

70

def parse_pyproject_toml(path_config):

71

"""

72

Parse interrogate configuration from pyproject.toml file.

73

74

Args:

75

path_config: Path to pyproject.toml file

76

77

Returns:

78

dict: Configuration values from [tool.interrogate] section

79

80

Raises:

81

FileNotFoundError: If configuration file doesn't exist

82

tomli.TOMLDecodeError: If TOML file is malformed

83

"""

84

85

def parse_setup_cfg(path_config):

86

"""

87

Parse interrogate configuration from setup.cfg file.

88

89

Args:

90

path_config: Path to setup.cfg file

91

92

Returns:

93

dict: Configuration values from [tool:interrogate] section

94

95

Raises:

96

FileNotFoundError: If configuration file doesn't exist

97

configparser.Error: If configuration file is malformed

98

"""

99

100

def sanitize_list_values(value):

101

"""

102

Sanitize configuration list values from strings or lists.

103

104

Args:

105

value: String (comma/space separated) or list of strings

106

107

Returns:

108

list: Cleaned list of values

109

"""

110

```

111

112

### Click Integration

113

114

Function for integrating configuration file loading with Click CLI framework.

115

116

```python { .api }

117

def read_config_file(ctx, param, value):

118

"""

119

Click callback for reading configuration file.

120

121

Args:

122

ctx: Click context

123

param: Click parameter

124

value: Configuration file path

125

126

Returns:

127

str: Configuration file path

128

129

Raises:

130

click.BadParameter: If configuration file is invalid

131

"""

132

```

133

134

## Usage Examples

135

136

### Creating Configuration Programmatically

137

138

```python

139

from interrogate.config import InterrogateConfig

140

141

# Basic configuration

142

config = InterrogateConfig(

143

paths=["src/", "tests/"],

144

fail_under=80.0,

145

ignore_private=True

146

)

147

148

# Advanced configuration

149

config = InterrogateConfig(

150

paths=["src/myproject"],

151

color=True,

152

exclude=["migrations", "tests/fixtures"],

153

ignore_init_method=True,

154

ignore_magic=True,

155

ignore_regex=["test_.*", ".*_test"],

156

fail_under=85.0,

157

verbose=1,

158

generate_badge="docs/badge.svg",

159

badge_style="flat-square"

160

)

161

```

162

163

### Loading Configuration from Files

164

165

```python

166

from interrogate.config import find_project_config, parse_pyproject_toml

167

168

# Find configuration file

169

config_path = find_project_config(".")

170

if config_path:

171

print(f"Found configuration: {config_path}")

172

173

# Parse configuration

174

if config_path.endswith("pyproject.toml"):

175

config_dict = parse_pyproject_toml(config_path)

176

print(f"Configuration options: {config_dict}")

177

```

178

179

### Configuration File Examples

180

181

#### pyproject.toml

182

183

```toml

184

[tool.interrogate]

185

ignore-init-method = true

186

ignore-init-module = true

187

ignore-magic = true

188

ignore-nested-functions = true

189

ignore-private = true

190

ignore-semiprivate = true

191

fail-under = 85

192

exclude = ["tests", "docs", "build"]

193

ignore-regex = ["^get$", "^post$", "^put$"]

194

verbose = 1

195

quiet = 0

196

whitelist-regex = []

197

color = true

198

omit-covered-files = false

199

generate-badge = "."

200

badge-format = "svg"

201

badge-style = "flat"

202

```

203

204

#### setup.cfg

205

206

```ini

207

[tool:interrogate]

208

ignore-init-method = true

209

ignore-init-module = true

210

ignore-magic = true

211

ignore-nested-functions = true

212

ignore-private = true

213

ignore-semiprivate = true

214

fail-under = 85

215

exclude = tests,docs,build

216

ignore-regex = ^get$,^post$,^put$

217

verbose = 1

218

quiet = 0

219

color = true

220

omit-covered-files = false

221

generate-badge = .

222

badge-format = svg

223

badge-style = flat

224

```

225

226

### Regex Pattern Configuration

227

228

```python

229

from interrogate.config import InterrogateConfig

230

231

# Configure regex patterns to ignore

232

config = InterrogateConfig(

233

paths=["src/"],

234

# Ignore test methods, getters, setters

235

ignore_regex=[

236

r"test_.*", # Test methods

237

r"get_.*", # Getter methods

238

r"set_.*", # Setter methods

239

r".*_callback$", # Callback functions

240

r"__.*__" # Magic methods (alternative to ignore_magic)

241

]

242

)

243

```

244

245

### Dynamic Configuration

246

247

```python

248

from interrogate.config import InterrogateConfig, find_project_config, parse_pyproject_toml

249

250

def create_config_with_overrides(paths, **overrides):

251

"""Create configuration with file-based defaults and overrides."""

252

253

# Start with defaults

254

config_kwargs = {

255

"paths": paths,

256

"color": True,

257

"fail_under": 80.0

258

}

259

260

# Load from configuration file if available

261

config_file = find_project_config(".")

262

if config_file and config_file.endswith("pyproject.toml"):

263

file_config = parse_pyproject_toml(config_file)

264

config_kwargs.update(file_config)

265

266

# Apply overrides

267

config_kwargs.update(overrides)

268

269

return InterrogateConfig(**config_kwargs)

270

271

# Usage

272

config = create_config_with_overrides(

273

paths=["src/"],

274

verbose=2, # Override verbose level

275

fail_under=90.0 # Override threshold

276

)

277

```