code-size-counter


Namecode-size-counter JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/VL-CZ/code-size-counter
SummaryCommand line utility used for calculating total size (both KB and lines of code) of program's code.
upload_time2023-12-08 09:35:59
maintainer
docs_urlNone
authorVojtěch Lengál
requires_python>=3.9,<4.0
licenseMIT
keywords lines of code code size kb size
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI - Version](https://img.shields.io/pypi/v/code-size-counter)
](https://pypi.org/project/code-size-counter/)
![GitHub Actions](https://github.com/VL-CZ/code-size-counter/actions/workflows/ci.yml/badge.svg)

# Code size counter
This repository contains a simple command line utility used for calculating total size (both 
KB and lines of code) of program's code.

## Introduction
The main goal of this program is to calculate total size of a source code.
You need to specify the directory that contains the source code and file extension(s) of the desired files.
(for example `html`, `css` and `js`). 
After that, the program searches the directory for files with the given file extension(s). It's also possible to exclude selected subdirectories from the search
(this is especially useful for directories like `.venv`, `.git` and so on).
The program typically prints:
- number of files found
- total number of lines in these files (newline at the end of the file isn't counted)
- total size of these files in KB (rounded to 2 decimal places). 1 KB = 1024 bytes

See the usage section for further details.

## Requirements
- Python version >= 3.9
- pip

## Installation
Install via pip
```shell
pip install code-size-counter
```

This installs the program as a local python package and allows you to use `code-size-counter` CLI command.

See the [PyPI](https://pypi.org/project/code-size-counter/) page for release history.

## Usage

Below, you can see list of all possible arguments (you can also get the help by running `code-size-counter -h`). `directory` is the only
one required.

```
usage: main.py [-h] [-d DIRECTORY] [-e EXTENSION [EXTENSION ...]] [-l] [-x EXCLUDE [EXCLUDE ...]] [-p {kb_size,lines,files}]

Calculate the total size (both KB and lines of code) of program's code.

options:
  -h, --help            show this help message and exit
  -d DIRECTORY, --directory DIRECTORY
                        Path to the directory where to search files. The path can be either absolute or relative; leave empty if you want to search the current directory.
  -e EXTENSION [EXTENSION ...], --extension EXTENSION [EXTENSION ...]
                        extensions of the files that we're searching (separated by spaces) for. Do not prefix them with a dot (e.g. use "py" instead of ".py"). Leave empty if you want to search for all files regardless of their extension.
  -l, --log             If present, the program prints its progress (e.g. 'file XXX processed')
  -x EXCLUDE [EXCLUDE ...], --exclude EXCLUDE [EXCLUDE ...]
                        path to directories & files to exclude (separated by spaces). These paths are relative to the given directory (-d parameter)
  -p {kb_size,lines,files}, --print {kb_size,lines,files}
                        Print just the selected value (KB size, total files or lines of code)
PS C:\Users\vojta\Programming\misc\code-size-counter> 
```

The typical usage of this program looks like this (see below). In this case, we're looking for `.py` and `.txt` files in `C:/Users/hacker123/Documents/hacking_app` directory,
except those in `.venv` and `.git` subdirectories.
Note that we don't prefix the file extensions with a dot (e.g. use `py` instead of `.py`).

```shell
code-size-counter -d C:/Users/hacker123/Documents/hacking_app -e py txt -x .venv .git
```
Possible output
```
+---------------------------------------------------------+
| Extension   Total files   Total lines   Total size (KB) |
+---------------------------------------------------------+
|       .py             1            50              1.51 |
|      .txt             1             2              0.03 |
+---------------------------------------------------------+
|     TOTAL             2            52              1.54 |
+---------------------------------------------------------+
```
See also other examples below.

### Examples
#### Example 1
Calculate the size of `.py` files inside `./tests/complex-test-dir` directory.

```shell
code-size-counter -d ./tests/complex-test-dir -e py
```
Output
```
+---------------------------------------------------------+
| Extension   Total files   Total lines   Total size (KB) |
+---------------------------------------------------------+
|       .py            31         13030            462.61 |
+---------------------------------------------------------+
```

#### Example 2
Calculate the size of `.py` files inside `./tests/complex-test-dir` directory. Exclude `virtualenv` and `src/module1` subdirectories.
```shell
code-size-counter -d ./tests/complex-test-dir -e py -x virtualenv src/module1
```
Output
```
+---------------------------------------------------------+
| Extension   Total files   Total lines   Total size (KB) |
+---------------------------------------------------------+
|       .py             8           268              8.26 |
+---------------------------------------------------------+
```

#### Example 3
Calculate the size of `.py` files inside `./tests/complex-test-dir` directory. Exclude `virtualenv` and `src/module1` subdirectories and print logs.
```shell
code-size-counter -d ./tests/complex-test-dir -e py -x virtualenv src/module1 -l
```
Output
```
./tests/complex-test-dir/src/module2/main.py processed
./tests/complex-test-dir/src/module2/__init__.py processed
./tests/complex-test-dir/src/code_size_counter.py processed
./tests/complex-test-dir/src/file_tools.py processed
./tests/complex-test-dir/src/__init__.py processed
./tests/complex-test-dir/tests/test_code_size_counter.py processed
./tests/complex-test-dir/tests/__init__.py processed
./tests/complex-test-dir/code_size_counter.py processed
+---------------------------------------------------------+
| Extension   Total files   Total lines   Total size (KB) |
+---------------------------------------------------------+
|       .py             8           268              8.26 |
+---------------------------------------------------------+   
```

#### Example 4
Calculate the size of `.py`, `.md` and `.yml` files inside `./tests/complex-test-dir` directory. Exclude `virtualenv` and `src/module1` subdirectories.
```shell
code-size-counter -d ./tests/complex-test-dir -e py md yml -x virtualenv src/module1
```
Output
```
+---------------------------------------------------------+
| Extension   Total files   Total lines   Total size (KB) |
+---------------------------------------------------------+
|      .yml             1            36              1.16 |
|       .py             8           268              8.26 |
|       .md             1             3              0.14 |
+---------------------------------------------------------+
|     TOTAL            10           307              9.56 |
+---------------------------------------------------------+
```

#### Example 5
Calculate the size of all files (regardless of their extension) inside `./directories/my-dir` directory.
```shell
code-size-counter -d ./directories/my-dir
```

Possible output
```
+----------------------------------------------------------+
|  Extension   Total files   Total lines   Total size (KB) |
+----------------------------------------------------------+
|     (NONE)             1            10              0.11 |
|    .flake8             1             2              0.03 |
| .gitignore             2           140              1.95 |
|        .md             2           215              8.83 |
|        .py            44         13533            477.44 |
|       .yml             2            76              2.34 |
+----------------------------------------------------------+
|      TOTAL            52         13976            490.70 |
+----------------------------------------------------------+
```

Also note the `(NONE)` extension, which means that the file has no extension


#### Example 6
Calculate the size of `.py` files inside `./tests/complex-test-dir` directory. Exclude `virtualenv` and `src/module1` subdirectories 
and print just the number of lines.
```shell
code-size-counter -d ./tests/complex-test-dir -e py -x virtualenv src/module1 -p lines
```

Output
```
268
```

You can then pipe the result (as you can see on the example below).
```shell
code-size-counter -d ./tests/complex-test-dir -e py -x virtualenv src/module1 -p lines | python -c "loc = input(); print(f'I copied {loc} lines from StackOverflow.')"
```
Output
```
I copied 268 lines from StackOverflow.
```

## Developer documentation

We're using [Poetry](https://python-poetry.org/docs/) for dependency management and packaging.

### Program structure

- [code_size_counter](./code_size_counter/) folder - source code files of the program
  - [main.py](code_size_counter/main.py) is the entry-point of the app
- [tests](./tests) folder - unit tests of the program (using `Python unittest` module). The subfolders serve as a test data.

To run the tests, use the following command
```shell
poetry run python -m unittest discover tests -v
```

Run this command in the **root** folder to execute `main.py` as a script.
```shell
poetry run python -m code_size_counter.main
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/VL-CZ/code-size-counter",
    "name": "code-size-counter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "lines of code,code size,KB size",
    "author": "Vojt\u011bch Leng\u00e1l",
    "author_email": "vojta.lengal@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/70/9c/42531ff9235e588a3364aeddc3e42c6d55454ba3661c914e70e706cbdb04/code_size_counter-1.0.2.tar.gz",
    "platform": null,
    "description": "[![PyPI - Version](https://img.shields.io/pypi/v/code-size-counter)\n](https://pypi.org/project/code-size-counter/)\n![GitHub Actions](https://github.com/VL-CZ/code-size-counter/actions/workflows/ci.yml/badge.svg)\n\n# Code size counter\nThis repository contains a simple command line utility used for calculating total size (both \nKB and lines of code) of program's code.\n\n## Introduction\nThe main goal of this program is to calculate total size of a source code.\nYou need to specify the directory that contains the source code and file extension(s) of the desired files.\n(for example `html`, `css` and `js`). \nAfter that, the program searches the directory for files with the given file extension(s). It's also possible to exclude selected subdirectories from the search\n(this is especially useful for directories like `.venv`, `.git` and so on).\nThe program typically prints:\n- number of files found\n- total number of lines in these files (newline at the end of the file isn't counted)\n- total size of these files in KB (rounded to 2 decimal places). 1 KB = 1024 bytes\n\nSee the usage section for further details.\n\n## Requirements\n- Python version >= 3.9\n- pip\n\n## Installation\nInstall via pip\n```shell\npip install code-size-counter\n```\n\nThis installs the program as a local python package and allows you to use `code-size-counter` CLI command.\n\nSee the [PyPI](https://pypi.org/project/code-size-counter/) page for release history.\n\n## Usage\n\nBelow, you can see list of all possible arguments (you can also get the help by running `code-size-counter -h`). `directory` is the only\none required.\n\n```\nusage: main.py [-h] [-d DIRECTORY] [-e EXTENSION [EXTENSION ...]] [-l] [-x EXCLUDE [EXCLUDE ...]] [-p {kb_size,lines,files}]\n\nCalculate the total size (both KB and lines of code) of program's code.\n\noptions:\n  -h, --help            show this help message and exit\n  -d DIRECTORY, --directory DIRECTORY\n                        Path to the directory where to search files. The path can be either absolute or relative; leave empty if you want to search the current directory.\n  -e EXTENSION [EXTENSION ...], --extension EXTENSION [EXTENSION ...]\n                        extensions of the files that we're searching (separated by spaces) for. Do not prefix them with a dot (e.g. use \"py\" instead of \".py\"). Leave empty if you want to search for all files regardless of their extension.\n  -l, --log             If present, the program prints its progress (e.g. 'file XXX processed')\n  -x EXCLUDE [EXCLUDE ...], --exclude EXCLUDE [EXCLUDE ...]\n                        path to directories & files to exclude (separated by spaces). These paths are relative to the given directory (-d parameter)\n  -p {kb_size,lines,files}, --print {kb_size,lines,files}\n                        Print just the selected value (KB size, total files or lines of code)\nPS C:\\Users\\vojta\\Programming\\misc\\code-size-counter> \n```\n\nThe typical usage of this program looks like this (see below). In this case, we're looking for `.py` and `.txt` files in `C:/Users/hacker123/Documents/hacking_app` directory,\nexcept those in `.venv` and `.git` subdirectories.\nNote that we don't prefix the file extensions with a dot (e.g. use `py` instead of `.py`).\n\n```shell\ncode-size-counter -d C:/Users/hacker123/Documents/hacking_app -e py txt -x .venv .git\n```\nPossible output\n```\n+---------------------------------------------------------+\n| Extension   Total files   Total lines   Total size (KB) |\n+---------------------------------------------------------+\n|       .py             1            50              1.51 |\n|      .txt             1             2              0.03 |\n+---------------------------------------------------------+\n|     TOTAL             2            52              1.54 |\n+---------------------------------------------------------+\n```\nSee also other examples below.\n\n### Examples\n#### Example 1\nCalculate the size of `.py` files inside `./tests/complex-test-dir` directory.\n\n```shell\ncode-size-counter -d ./tests/complex-test-dir -e py\n```\nOutput\n```\n+---------------------------------------------------------+\n| Extension   Total files   Total lines   Total size (KB) |\n+---------------------------------------------------------+\n|       .py            31         13030            462.61 |\n+---------------------------------------------------------+\n```\n\n#### Example 2\nCalculate the size of `.py` files inside `./tests/complex-test-dir` directory. Exclude `virtualenv` and `src/module1` subdirectories.\n```shell\ncode-size-counter -d ./tests/complex-test-dir -e py -x virtualenv src/module1\n```\nOutput\n```\n+---------------------------------------------------------+\n| Extension   Total files   Total lines   Total size (KB) |\n+---------------------------------------------------------+\n|       .py             8           268              8.26 |\n+---------------------------------------------------------+\n```\n\n#### Example 3\nCalculate the size of `.py` files inside `./tests/complex-test-dir` directory. Exclude `virtualenv` and `src/module1` subdirectories and print logs.\n```shell\ncode-size-counter -d ./tests/complex-test-dir -e py -x virtualenv src/module1 -l\n```\nOutput\n```\n./tests/complex-test-dir/src/module2/main.py processed\n./tests/complex-test-dir/src/module2/__init__.py processed\n./tests/complex-test-dir/src/code_size_counter.py processed\n./tests/complex-test-dir/src/file_tools.py processed\n./tests/complex-test-dir/src/__init__.py processed\n./tests/complex-test-dir/tests/test_code_size_counter.py processed\n./tests/complex-test-dir/tests/__init__.py processed\n./tests/complex-test-dir/code_size_counter.py processed\n+---------------------------------------------------------+\n| Extension   Total files   Total lines   Total size (KB) |\n+---------------------------------------------------------+\n|       .py             8           268              8.26 |\n+---------------------------------------------------------+   \n```\n\n#### Example 4\nCalculate the size of `.py`, `.md` and `.yml` files inside `./tests/complex-test-dir` directory. Exclude `virtualenv` and `src/module1` subdirectories.\n```shell\ncode-size-counter -d ./tests/complex-test-dir -e py md yml -x virtualenv src/module1\n```\nOutput\n```\n+---------------------------------------------------------+\n| Extension   Total files   Total lines   Total size (KB) |\n+---------------------------------------------------------+\n|      .yml             1            36              1.16 |\n|       .py             8           268              8.26 |\n|       .md             1             3              0.14 |\n+---------------------------------------------------------+\n|     TOTAL            10           307              9.56 |\n+---------------------------------------------------------+\n```\n\n#### Example 5\nCalculate the size of all files (regardless of their extension) inside `./directories/my-dir` directory.\n```shell\ncode-size-counter -d ./directories/my-dir\n```\n\nPossible output\n```\n+----------------------------------------------------------+\n|  Extension   Total files   Total lines   Total size (KB) |\n+----------------------------------------------------------+\n|     (NONE)             1            10              0.11 |\n|    .flake8             1             2              0.03 |\n| .gitignore             2           140              1.95 |\n|        .md             2           215              8.83 |\n|        .py            44         13533            477.44 |\n|       .yml             2            76              2.34 |\n+----------------------------------------------------------+\n|      TOTAL            52         13976            490.70 |\n+----------------------------------------------------------+\n```\n\nAlso note the `(NONE)` extension, which means that the file has no extension\n\n\n#### Example 6\nCalculate the size of `.py` files inside `./tests/complex-test-dir` directory. Exclude `virtualenv` and `src/module1` subdirectories \nand print just the number of lines.\n```shell\ncode-size-counter -d ./tests/complex-test-dir -e py -x virtualenv src/module1 -p lines\n```\n\nOutput\n```\n268\n```\n\nYou can then pipe the result (as you can see on the example below).\n```shell\ncode-size-counter -d ./tests/complex-test-dir -e py -x virtualenv src/module1 -p lines | python -c \"loc = input(); print(f'I copied {loc} lines from StackOverflow.')\"\n```\nOutput\n```\nI copied 268 lines from StackOverflow.\n```\n\n## Developer documentation\n\nWe're using [Poetry](https://python-poetry.org/docs/) for dependency management and packaging.\n\n### Program structure\n\n- [code_size_counter](./code_size_counter/) folder - source code files of the program\n  - [main.py](code_size_counter/main.py) is the entry-point of the app\n- [tests](./tests) folder - unit tests of the program (using `Python unittest` module). The subfolders serve as a test data.\n\nTo run the tests, use the following command\n```shell\npoetry run python -m unittest discover tests -v\n```\n\nRun this command in the **root** folder to execute `main.py` as a script.\n```shell\npoetry run python -m code_size_counter.main\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Command line utility used for calculating total size (both KB and lines of code) of program's code.",
    "version": "1.0.2",
    "project_urls": {
        "Documentation": "https://github.com/VL-CZ/code-size-counter",
        "Homepage": "https://github.com/VL-CZ/code-size-counter",
        "Repository": "https://github.com/VL-CZ/code-size-counter"
    },
    "split_keywords": [
        "lines of code",
        "code size",
        "kb size"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c68eba271a0b7c653a87773e8c58bae5a92cf5521dfa303765ff93e2bd4978bd",
                "md5": "fda65cbb760ae4a6c637bd36f2c23c95",
                "sha256": "b111539ed87fba38bfa317de43402b6589a5706379a80b6d3534ed7c561762ac"
            },
            "downloads": -1,
            "filename": "code_size_counter-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fda65cbb760ae4a6c637bd36f2c23c95",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 9045,
            "upload_time": "2023-12-08T09:35:57",
            "upload_time_iso_8601": "2023-12-08T09:35:57.468945Z",
            "url": "https://files.pythonhosted.org/packages/c6/8e/ba271a0b7c653a87773e8c58bae5a92cf5521dfa303765ff93e2bd4978bd/code_size_counter-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "709c42531ff9235e588a3364aeddc3e42c6d55454ba3661c914e70e706cbdb04",
                "md5": "77a65263228e1ae16e6b30b090c545e6",
                "sha256": "56e625ce08d22539c503f9f79e5a6a8129ba25f479bb6746853c059447e28329"
            },
            "downloads": -1,
            "filename": "code_size_counter-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "77a65263228e1ae16e6b30b090c545e6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 7176,
            "upload_time": "2023-12-08T09:35:59",
            "upload_time_iso_8601": "2023-12-08T09:35:59.098514Z",
            "url": "https://files.pythonhosted.org/packages/70/9c/42531ff9235e588a3364aeddc3e42c6d55454ba3661c914e70e706cbdb04/code_size_counter-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-08 09:35:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "VL-CZ",
    "github_project": "code-size-counter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "code-size-counter"
}
        
Elapsed time: 0.15700s