Skip to content

Understand your Python codebase. ๐Ÿ“ก Summarizes your directory in a single table. Displays the file structure of all the files, their functions, classes, and methods in a nicely colored tree. Shows a table of all the files with counts of the lines and much more.

Notifications You must be signed in to change notification settings

QuentinWach/PyCodar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

26 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

License: MIT Last Commit PyPI PyPI Downloads

PyCodar: A Radar for Your Code

A simple tool for auditing and understanding your (python) codebase.

pip install pycodar
  • pycodar stats: Summarizes the most basic stats of your directory in a single table. ๐Ÿ“Š
  • pycodar strct: Displays the file structure of all the files, their functions, classes, and methods in a nicely colored tree. ๐Ÿ—‚๏ธ
  • pycodar files: Shows a table of all the files with counts of the lines of code, comments, empty lines, total lines, and file size. ๐Ÿ“‹
  • pycodar calls: Counts how often elements (modules, functions, methods) of your code are called within the code. ๐Ÿ“ž
  • pycodar dead: Finds (likely) unused code. โ˜ ๏ธ

General Overview

Type

pycodar stats

in your terminal to get the most basic statistics of your directory printed out:

๐Ÿ“Š Basic Metrics
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  Total Size         โ”‚  54.21KB  โ”‚
โ”‚  Total Files        โ”‚  6        โ”‚
โ”‚  Total Directories  โ”‚  2        โ”‚
โ”‚  Total Lines        โ”‚  1,394    โ”‚
โ”‚  Code Lines         โ”‚  885      โ”‚
โ”‚  Comment Lines      โ”‚  26       โ”‚
โ”‚  Empty Lines        โ”‚  208      โ”‚
โ”‚  Functions          โ”‚  38       โ”‚
โ”‚  Classes            โ”‚  2        โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Structure

pycodar strct

gives you something like:

๐ŸŒณ File Structure
๐Ÿ“ Root
โ”œโ”€โ”€ ๐Ÿ“„ README.md
โ”œโ”€โ”€ ๐Ÿ“„ pyproject.toml
โ”œโ”€โ”€ ๐Ÿ“„ setup.py
โ””โ”€โ”€ ๐Ÿ“ pycodar
    โ”œโ”€โ”€ ๐Ÿ“„ __init__.py
    โ”œโ”€โ”€ ๐Ÿ“„ analyze.py
    โ”‚   โ”œโ”€โ”€ ๐Ÿ”ท CodeElementVisitor
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น __init__
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น visit_FunctionDef
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น visit_ClassDef
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น visit_Import
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น visit_ImportFrom
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น visit_Call
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น visit_Assign
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น visit_Name
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น visit_Attribute
    โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”น visit_Return
    โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ”น visit_Decorator
    โ”‚   โ”œโ”€โ”€ ๐Ÿ”ธ count_functions_and_classes
    โ”‚   โ”œโ”€โ”€ ๐Ÿ”ธ get_file_size_kb
    โ”‚   โ”œโ”€โ”€ ๐Ÿ”ธ count_lines
    โ”‚   โ”œโ”€โ”€ ๐Ÿ”ธ analyze_code_connections
    โ”‚   โ”œโ”€โ”€ ๐Ÿ”ธ analyze_directory
    โ”‚   โ””โ”€โ”€ ๐Ÿ”ธ generate_report
    โ””โ”€โ”€ ๐Ÿ“„ cli.py
        โ”œโ”€โ”€ ๐Ÿ”ท TestClass
        โ”‚   โ”œโ”€โ”€ ๐Ÿ”น __init__
        โ”‚   โ””โ”€โ”€ ๐Ÿ”น test_method
        โ”œโ”€โ”€ ๐Ÿ”ธ extract_code_structure
        โ”œโ”€โ”€ ๐Ÿ”ธ create_structure_tree
        โ”œโ”€โ”€ ๐Ÿ”ธ parse_ignore_file
        โ”œโ”€โ”€ ๐Ÿ”ธ should_ignore
        โ”œโ”€โ”€ ๐Ÿ”ธ get_ignore_patterns
        โ”œโ”€โ”€ ๐Ÿ”ธ format_size
        โ”œโ”€โ”€ ๐Ÿ”ธ count_code_metrics
        โ”œโ”€โ”€ ๐Ÿ”ธ create_metrics_table
        โ”œโ”€โ”€ ๐Ÿ”ธ create_code_connections_table
        โ”œโ”€โ”€ ๐Ÿ”ธ create_dead_code_table
        โ”œโ”€โ”€ ๐Ÿ”ธ create_code_connections_tree
        โ”œโ”€โ”€ ๐Ÿ”ธ create_file_table
        โ”œโ”€โ”€ ๐Ÿ”ธ print_stats
        โ”œโ”€โ”€ ๐Ÿ”ธ print_structure
        โ”œโ”€โ”€ ๐Ÿ”ธ print_files
        โ”œโ”€โ”€ ๐Ÿ”ธ print_calls
        โ”œโ”€โ”€ ๐Ÿ”ธ print_dead_code
        โ”œโ”€โ”€ ๐Ÿ”ธ process_directory
        โ””โ”€โ”€ ๐Ÿ”ธ main

File Statistics

Typing

pycodar files

will give you an overview of the lines of code, comments, empty lines, total lines and file sizes:

๐Ÿ“ File Distribution
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  Path     โ”‚  File            โ”‚  Code  โ”‚  Comments  โ”‚  Empty  โ”‚  Total  โ”‚     Size  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Root     โ”‚  pyproject.toml  โ”‚     0  โ”‚         0  โ”‚      0  โ”‚     43  โ”‚   1.37KB  โ”‚
โ”‚  Root     โ”‚  README.md       โ”‚     0  โ”‚         0  โ”‚      0  โ”‚     95  โ”‚   3.37KB  โ”‚
โ”‚  Root     โ”‚  setup.py        โ”‚    45  โ”‚         0  โ”‚      1  โ”‚     46  โ”‚   1.72KB  โ”‚
โ”‚  pycodar  โ”‚  __init__.py     โ”‚     7  โ”‚         1  โ”‚      3  โ”‚     11  โ”‚   0.22KB  โ”‚
โ”‚  pycodar  โ”‚  cli.py          โ”‚   384  โ”‚        18  โ”‚     90  โ”‚    492  โ”‚  18.62KB  โ”‚
โ”‚  pycodar  โ”‚  analyze.py      โ”‚   449  โ”‚         7  โ”‚    114  โ”‚    570  โ”‚  22.27KB  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Calls

To check how much the modules, functions and methods in your code are actually being used, type:

pycondar calls

which will give you another table like:

๐Ÿ“Š Most Called Elements
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  Type      โ”‚  Name                   โ”‚  Called  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Function  โ”‚  isinstance             โ”‚      28  โ”‚
โ”‚  Function  โ”‚  print                  โ”‚      22  โ”‚
โ”‚  Function  โ”‚  defaultdict            โ”‚      17  โ”‚
โ”‚  Function  โ”‚  set                    โ”‚      11  โ”‚
โ”‚  Function  โ”‚  sorted                 โ”‚      10  โ”‚
โ”‚  Function  โ”‚  len                    โ”‚      10  โ”‚
โ”‚  Function  โ”‚  str                    โ”‚       9  โ”‚
โ”‚  Function  โ”‚  open                   โ”‚       7  โ”‚
โ”‚  Function  โ”‚  Path                   โ”‚       4  โ”‚
โ”‚  Function  โ”‚  sum                    โ”‚       4  โ”‚
โ”‚  Method    โ”‚  console.print          โ”‚      22  โ”‚
โ”‚  Method    โ”‚  table.add_row          โ”‚      15  โ”‚
โ”‚  Method    โ”‚  table.add_column       โ”‚      14  โ”‚
โ”‚  Method    โ”‚  self.generic_visit     โ”‚       8  โ”‚
โ”‚  Method    โ”‚  ast.walk               โ”‚       5  โ”‚
โ”‚  Method    โ”‚  subparsers.add_parser  โ”‚       5  โ”‚
โ”‚  Method    โ”‚  ast.parse              โ”‚       4  โ”‚
โ”‚  Method    โ”‚  tree.add               โ”‚       4  โ”‚
โ”‚  Method    โ”‚  method.startswith      โ”‚       4  โ”‚
โ”‚  Method    โ”‚  file.read              โ”‚       3  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Dead Code

And finally, to see if there is any code that's not even used, type

๐Ÿ’€ Potentially Unused Code
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  Type   โ”‚  Name                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Class  โ”‚  pycodar.cli.TestClass  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

which will point you at whatever code seems to be unused.


If you need any help / a quick reminder, type:

pycodar help

and if you just want to see everything all at once, type:

pycodar all

Thank you and enjoy! ๐Ÿ˜œ

About

Understand your Python codebase. ๐Ÿ“ก Summarizes your directory in a single table. Displays the file structure of all the files, their functions, classes, and methods in a nicely colored tree. Shows a table of all the files with counts of the lines and much more.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages