Skip to main content

sourcery-analytics is a library and command-line interface (CLI) for analyzing the code quality of Python packages, modules, or source code.

Project description

Sourcery Analytics

PyPI build, test, and publish docs code style docs


sourcery-analytics is a command line tool and library for statically analyzing Python code quality.

Get started by installing using pip:

pip install sourcery-analytics

This will install sourcery-analytics as a command-line tool.

To identify code quality issues:

sourcery-analytics assess path/to/file.py

Example:

sourcery-analytics assess sourcery_analytics/metrics
sourcery_analytics/metrics/cyclomatic_complexity.py:47: error: working_memory of cyclomatic_complexity is 34 exceeding threshold of 20
Found 1 errors.

To analyze a single Python file, use the analyze subcommand:

sourcery-analytics analyze path/to/file.py

Example:

sourcery-analytics analyze sourcery_analytics/analysis.py
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Method                                      ┃ length ┃ cyclomatic_complexity ┃ cognitive_complexity ┃ working_memory ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ sourcery_analytics.analysis.analyze         │      5 │                     1 │                    0 │              8 │
│ sourcery_analytics.analysis.analyze_methods │      4 │                     1 │                    1 │             12 │
└─────────────────────────────────────────────┴────────┴───────────────────────┴──────────────────────┴────────────────┘

Alternatively, import and run analysis using the library:

from sourcery_analytics import analyze_methods
source = """
    def cast_spell(self, spell):
        if self.power < spell.power:
            raise InsufficientPower
        print(f"{self.name} cast {spell.name}!")
"""
analyze_methods(source)
# [{'method_qualname': '.cast_spell', 'method_length': 3, 'method_cyclomatic_complexity': 1, 'method_cognitive_complexity': 1, 'method_working_memory': 6}]

For more, see the docs.

Repoanalysis.com

You can see how hundreds of top projects measure across different code quality metrics and see how your priojects compare at repoanalysis.com

Developed by Sourcery

Sourcery Analytics was originally developed by the team at Sourcery. Sourcery is an automated coding assistant to help Python developers review and improve their code while they work. Sourcery has a built in library of 100+ core rules and you can extend it further to create custom rules for any scenario.

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

sourcery-analytics-1.2.1.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

sourcery_analytics-1.2.1-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file sourcery-analytics-1.2.1.tar.gz.

File metadata

  • Download URL: sourcery-analytics-1.2.1.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.9.9 Linux/5.15.0-1020-azure

File hashes

Hashes for sourcery-analytics-1.2.1.tar.gz
Algorithm Hash digest
SHA256 80e586c5e261994c4be25f6d039177215fc424debcfb3b9b4b9387de13e803dd
MD5 5dab3f337be179b45e684cf179940cdd
BLAKE2b-256 e631bc6008c0f110bf463f1b7321398722eb32d4d325416b3548d8617dff5e62

See more details on using hashes here.

File details

Details for the file sourcery_analytics-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: sourcery_analytics-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 26.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.9.9 Linux/5.15.0-1020-azure

File hashes

Hashes for sourcery_analytics-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d0bcdaaafbcb1cf13f0f7baeaa90d0d819d520a7bd91a8527dbb3ed28b86d23
MD5 c229eb77a8363ec661ddc1c4f9b34881
BLAKE2b-256 d30aed6854e0b3bcf3428f359be15f7fe99b6328ce4d7b12fc94ebeaa6e6a351

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