Skip to main content

Compute module coupling metrics for Python projects.

Project description

The "Instability" and "Abstractness" metrics are related to the "Stable Dependencies Principle" and the "Stable Abstractions Principle". This software is attempt to compute these metrics, or something equivalent, in a Python environment.

This distribution package installs the module_coupling_metrics command to be used from the command line. It takes a single parameter as input -the path to the root Python package- and produces two files :

  • A CSV report, one row per module
  • A PNG showing the Abstractness/Instability graph for the analyzed modules

Components

The SDP and SAP are two principles among the six "Component principles" of the Clean Architecture - even though they existed long before this name

These principles are not bound to any software platform. A major difficulty is, being given a software platform, to decide what should be labeled as a "Component". In Python, there are at least three candidates :

The good choice probably depends on the context:

  • Analyzing a big system including all its dependencies or an independent part of it.
  • The code breakdown: one class per module or many classes in each module
  • ...

In this software, we use: 1 component = 1 module

Instability

In the SDP, Instability is defined as following:

  • Fan-in: Incoming dependencies. This metric identifies the number of classes outside this component that depend on classes within the component.
  • Fan-out: Outgoing dependencies. This metric identifies the number of classes inside this component that depend on classes outside the component.
  • I: Instability: I = Fan-out , (Fan-in + Fan-out). This metric has the range [0, 1]. I = 0 indicates a maximally stable component. I = 1 indicates a maximally unstable component.

The dependencies between classes being somewhat difficult to count, we will use the following alternative :

  • Fan-in: Number of modules importing the considered module.
  • Fan-out: Number of modules imported by the considered module.

Abstractness

In the SAP, Abstractness is defined as following:

  • Nc: The number of classes in the component.
  • Na: The number of abstract classes and interfaces in the component.
  • A: Abstractness. A = Na / Nc.

The number of classes is the easy part. The number of interfaces / abstract classes is rather tricky.

Abstract classes can be explicitly defined in Python using the abc module. In a software where those abstract classes are systematically used, their number shall be used. Targeting a broader context, we will consider all classes that are inherited by some other class as Abstract Classes.

Due to duck typing capabilities, interfaces are virtually non-existent in Python. Their number is difficult to guess if they are not impersonated by a class acting as an "informal interface". The software does nothing in this area and expects all interfaces being represented by a base class.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

module_coupling_metrics-0.0.1.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

module_coupling_metrics-0.0.1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file module_coupling_metrics-0.0.1.tar.gz.

File metadata

  • Download URL: module_coupling_metrics-0.0.1.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for module_coupling_metrics-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fbaa91c325a8e438a53e7ed3d116b269fdba44253992b558abc30f7ac2b205c3
MD5 f22464fff5e7a0ecae282b5ce4585a0e
BLAKE2b-256 1ce48b135f780d16665babeed7369a753b330bd6c21f74ea44fe6c935af32a9e

See more details on using hashes here.

File details

Details for the file module_coupling_metrics-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: module_coupling_metrics-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for module_coupling_metrics-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5d73a468fcfcf8ca794a4e5b6612c1904d5849dc5982ef97fdff1b75220bfb6
MD5 bca962a31ef5796b98a8112ef04e8a48
BLAKE2b-256 b31e74dded0a14964d1f3412f0ba303df9da2ba4109ea925464cd9062aa2915a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page