Skip to main content

hmlines (how many lines) - A package for counting lines of code in a project

Project description

hmlines

This Python package is designed to show how many lines of code and comments your project.

Features

  • Quiet mode : Get only line number without any information with --quiet or -q flag
  • Custom Comments : Add your own prefixes for comments. with --comm or -c flag
  • Raw Input : Get count of all lines in files with --raw or -r flag
  • Ignore Specific Directories: Exclude directories like __pycache__ or venv to avoid analyzing irrelevant files.
  • File Extension Filtering: Analyze only files with specific extensions (e.g., .py, .js).
  • Show File Paths: Option to print paths of the files being analyzed.
  • Detailed Statistics: Provides detailed stats for each file, including the count of code and comment lines, as well as percentages.
  • Summarized Results: Outputs a summary of total lines, code lines, comment lines, and their percentages.

Installation

Requirements

  • Python 3.x
  • No external dependencies are required, the script uses standard Python libraries.
! pip install hmlines 

Usage

python hmlines <project-name> [options]

Arguments

  • directory: Path to the directory you want to analyze.

  • -e, --extensions: Specify which file extensions to analyze. Default is .py.

    python hmlines /path/to/project -e ".py,.js"
    
  • -i, --ignore: Specify directories to ignore (e.g., __pycache__, venv). Directories should be separated by commas.

    python hmlines /path/to/project -i "__pycache__,venv"
    
  • -show, --show-files: Show the paths of the files being analyzed.

    python hmlines /path/to/project -show
    
  • -s, --stats: Show detailed statistics per file (code and comment lines, percentages).

    python hmlines /path/to/project -s
    

Example Command

To analyze all .py files in a project while ignoring __pycache__ and venv directories, and show detailed statistics:

python hmlines /path/to/project -e ".py" -i __pycache__,venv -s

Output Example

With -s (Detailed Statistics)

=== Code Analysis Results ===
| File Extension       | Code      | Code %    | Comments  | Comment % |
|----------------------|-----------|-----------|-----------|-----------|
| .py                  | 100       | 85.0      | 15        | 15.0      |
|----------------------|-----------|-----------|-----------|-----------|
| Total 200 in (2)     | 180       | 90.0      | 20        | 10.0      |
|----------------------|-----------|-----------|-----------|-----------|

Without -s (Summary)

Total Lines: 200
Code: 180 (90.0%)
Comment: 20 (10.0%)

With -q (Quiet mode)

200

Functions

count_lines_in_file(filepath)

Counts the number of code and comment lines in a file. It returns a tuple with:

  • Number of code lines
  • Number of comment lines
  • Total number of lines

count_lines_in_directory(directory, file_extensions=('.py',), show_file=False, ignore_dirs=None)

Recursively scans the directory and analyzes files with the specified extensions. Returns a dictionary containing file statistics per extension:

  • Number of files
  • Total lines
  • Code lines
  • Comment lines

print_summary(files_by_extension, show_stats=False)

Prints a summary of the code analysis:

  • Total number of files and lines
  • Number of code and comment lines with percentage
  • Breakdown of files by extension

License

This project is licensed under the MIT License - see the LICENSE file for details.


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

hmlines-0.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

hmlines-0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file hmlines-0.2.tar.gz.

File metadata

  • Download URL: hmlines-0.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for hmlines-0.2.tar.gz
Algorithm Hash digest
SHA256 f86653dbf1e7eb2bcfa86d2ef6dee00f795e8c8ded1838b9ca041fd023d2f0c8
MD5 87430e69785045b3108a41560601063e
BLAKE2b-256 3eb17da5a9903ddbba82e0865e487f9125157b954a3c3b4f3a30fb640569859b

See more details on using hashes here.

File details

Details for the file hmlines-0.2-py3-none-any.whl.

File metadata

  • Download URL: hmlines-0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for hmlines-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 740ca6aba37f0f7acdb5ed50ad5a5981f9b925752895b114b6119cd8113e3894
MD5 21ee417b36b6dc7db0db2769e1db9b23
BLAKE2b-256 2d6aa8e35013cda03829c95b3e5a2ed6ca065dfaad3460f73ff5fc630e0aaaa2

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