Skip to content
plagussPublic

About

Python source code stats in a command.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

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

Readme badges from shields.io

Badges generated by readme_badges.py:


badge_lines badge_source_lines badge_blank_lines badge_comment_lines badge_docstring_lines badge_average_function_length badge_number_of_functions badge_source_files

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

About

Python source code stats in a command.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages