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
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
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
Built Distribution
File details
Details for the file reducto-1.0.3.tar.gz
.
File metadata
- Download URL: reducto-1.0.3.tar.gz
- Upload date:
- Size: 68.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e56a0ebc53e7cec937144e29edeb216ae88b28cf168361d964b7a74ef5c48b96 |
|
MD5 | 0c8543d8a2f0b2bfeb818879ceecc1ba |
|
BLAKE2b-256 | e253df563f07f67da243ef86d2ea1a4434d8c0fd234ffd37650cc28adbf8e66f |
File details
Details for the file reducto-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: reducto-1.0.3-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 126e64a9ccfc1391ca938fa18ebdb4622257c1161db2f8aef8722e623f2f9499 |
|
MD5 | c40647438357f82a0f3b354ddfe03966 |
|
BLAKE2b-256 | 2059b4bf0a07ca73de20dad52a139d3aa4ba2589047f31e676369e8e9b9e31d6 |