Fitness Functions API Reference¶
Architecture fitness functions: measure component health with Robert Martin's
Abstractness / Instability / Distance metrics, adapted for Python. Drives the
istos analyze command; also importable for custom checks.
Architecture fitness functions for measuring component health.
Implements Robert Martin's Abstractness / Instability / Distance metrics as
described in "Software Architecture: The Hard Parts" (ch. 4), adapted for
Python: a type counts as abstract when it is a typing.Protocol, an
abc.ABC, or carries an @abstractmethod -- the real seams of a Python
codebase, rather than Java-style interfaces.
A component is a top-level subpackage or module of the package under
analysis (e.g. istos.consistency, istos.routing), never an individual
line or class. For each component we measure:
Ce efferent coupling other components it imports from
Ca afferent coupling other components that import it
I instability Ce / (Ce + Ca) 0 = stable .. 1 = unstable
A abstractness abstract types / all types
D distance |A + I - 1| 0 = on the main sequence
Distance is diagnostic, not a score to drive to zero. Concrete leaf utilities in Python legitimately sit at A=0, I=0 (D=1); that only signals pain when the component is also large and volatile. Read the numbers, don't optimise them.
Component
dataclass
¶
Health metrics for one package-level component.
Source code in src/istos/fitness.py
Report
dataclass
¶
The full result of analysing a package.
Source code in src/istos/fitness.py
analyze(path, package=None)
¶
Analyse a package and return per-component health metrics.
Source code in src/istos/fitness.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
find_package(path, package=None)
¶
Locate the importable package to analyse under path.
Looks for src/<pkg>/__init__.py first (the src layout), then a
top-level <pkg>/__init__.py. Pass package to disambiguate when a
project ships more than one.
Source code in src/istos/fitness.py
format_report(report)
¶
Render a report as a human-readable table.