Skip to main content

Python source code stats in a command.

Project description

Reducto

Reducto is a command line utility to extract statistical features from your python source code.

  • Count the number of lines in a project (.py files only)
  • Number of functions/methods.
  • Average function length.
  • Docstring lines.
  • Comment lines.
  • Blank lines.
  • Source files (number of .py files).
  • Source lines (number of lines corresponding to python code, total number of lines minus docstrings, comments and blank lines).

For the average package the code should be fast enough. The average time is of 0.5 seconds against top pypi packages by number of downloads.

A simple analysis run top of the 4000 top pypi packages at the following repository: top_pypi_source_code_stats.

Development status

ci workflow Code style: black codecov Documentation Status

Installation

reducto is available in PyPI, run from your terminal:

$ pip install reducto

Install with extras to print tables via tabulate:

$ pip install reducto[tabulate]

Currently tested on python 3.8 only.

Usage

To start with the default example:

$ reducto {source_file_or_directory}

The default mode will print the base json report to the command line using pprint.pprint.

Let's see an example running on the reducto source code (for the current version):

$ reducto reducto
{'reducto': {'average_function_length': 6,
             'blank_lines': 208,
             'comment_lines': 20,
             'docstring_lines': 803,
             'lines': 1973,
             'number_of_functions': 108,
             'source_files': 7,
             'source_lines': 942}}

The formats include json as a default, but when installing tabulate dependency, the formats defined there are available too. For example:

$ reducto reducto --format="rst"
=========  =======  ===========  ========  ===========  =========  =======  ==========  ========
package      lines       number    source    docstring    comment    blank     average    source
                             of     lines        lines      lines    lines    function     files
                      functions                                                 length
=========  =======  ===========  ========  ===========  =========  =======  ==========  ========
reducto       1973          108       942          803         20      208           6         7
=========  =======  ===========  ========  ===========  =========  =======  ==========  ========

Or copying directly the output from executing reducto reducto/ --format "github" --percentage to this README.md:

package lines number_of_functions source_lines docstring_lines comment_lines blank_lines average_function_length source_files
reducto 1973 108 48% 41% 1% 11% 6 7

Typing the help command may show the different formats defined currently, but for more info, the documentation may be more helpful.

$ reducto --help
usage: reducto [-h] [-v]
               [-f {json,simple,plain,grid,fancy_grid,github,pipe,orgtbl,jira,presto,pretty,psql,rst,mediawiki,moinmoin,youtrack,html,unsafehtml,latex,latex_raw,latex_booktabs,latex_longtable,tsv,textile}]
               [--grouped | --ungrouped] [-o OUTPUT] [-p]
               [target]

positional arguments:
  target                Path to execute the program into. Must be either a python package (directory containing an __init__.py) or a python source file {SRC.py}

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         Show the version of the program.
  -f {json,simple,plain,grid,fancy_grid,github,pipe,orgtbl,jira,presto,pretty,psql,rst,mediawiki,moinmoin,youtrack,html,unsafehtml,latex,latex_raw,latex_booktabs,latex_longtable,tsv,textile}, --format {json,simple,plain,grid,fancy_grid,github,pipe,orgtbl,jira,presto,pretty,psql,rst,mediawiki,moinmoin,youtrack,html,unsafehtml,latex,latex_raw,latex_booktabs,latex_longtable,tsv,textile}
                        Format for the report type.
  --grouped             Return the results separated by source files, or grouped for the whole package. Only used when the target path is a package.
  --ungrouped           Opposite of --grouped.
  -o OUTPUT, --output OUTPUT
                        Full path of the report to be generated. If not given, redirects to stdout.
  -p, --percentage      Report the number of lines as percentage.

Documentation

Read the documentation on ReadTheDocs.

License

MIT License

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

reducto-1.0.3.tar.gz (68.2 kB view hashes)

Uploaded Source

Built Distribution

reducto-1.0.3-py3-none-any.whl (20.0 kB view hashes)

Uploaded Python 3

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