Skip to main content

A simple tool for auditing and understanding your codebase.

Project description

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 deps: Shows which external packages and standard library modules are used in your 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! ๐Ÿ˜œ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycodar-0.1.7-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file pycodar-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: pycodar-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for pycodar-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bff5fbb5b73db235331e5f58d336fdf8712029fb3ae423a8fe75813f92538f97
MD5 6c19eec9db4d7824cbbae24135850d89
BLAKE2b-256 1404a8d6d26275e40fb3f228b42a2bdf7a1ab83dd0e5f7d31106c8cb2e53b9c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page