Metadata-Version: 2.1
Name: init-file-checker
Version: 0.0.2
Summary: Checker of __init__.py files in Python projects
Home-page: https://github.com/DavidPal/init-file-checker
License: MIT
Author: David Pal
Author-email: davidko.pal@gmail.com
Requires-Python: >=3.8.5,<4.0.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Project-URL: Repository, https://github.com/DavidPal/init-file-checker
Description-Content-Type: text/markdown

# `__init__` file checker

[![Build, lint and test](https://github.com/DavidPal/init-file-checker/actions/workflows/build.yaml/badge.svg)](https://github.com/DavidPal/init-file-checker/actions/workflows/build.yaml)

Tool that ensures that `__init__.py` files are not missing. Various Python tools needs these files, most notably pylint.

## Installation

```shell
pip install init-file-checker
```

Installation requires Python 3.8.5 or higher.

## Usage

A sample command that checks presence of `__init__.py` files is:
```shell
init-file-checker my_project/
```

If you want to create missing `__init__.py` files, use `--add-missing` command line option:
```shell
init-file-checker --add-missing my_project/
```
The created files will have zero size.

## License

MIT

## Development setup

1) Make sure you have [brew](https://brew.sh/) package manager installed.

2) Install [pyenv](https://github.com/pyenv/pyenv), [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv)
   and [poetry](https://python-poetry.org/):
    ```shell
    brew install pyenv
    brew install pyenv-virtualenv
    brew install poetry
    ```

3) Add the following lines to `.zshrc` or `.bash_profile` and restart the terminal:
   ```shell
   # Pyenv settings
   export PYENV_ROOT="$HOME/.pyenv"
   export PATH="$PYENV_ROOT/bin:$PATH"
   eval "$(pyenv init --path)"
   eval "$(pyenv virtualenv-init -)"
   ```

4) Create Python virtual environment with the correct Python version:
   ```shell
   make install-python
   make create-environment
   ```

5) Install all dependencies
    ```shell
    make install-dependencies
    ```

If you need to delete the Python virtual environment, you can do so with the
command `make delete-environment`.

## Running unit tests and code checks

If you make code change, run unit tests and code checks with the command:
```shell
make clean whitespace-format-check isort-check black-check flake8 pydocstyle pylint ruff mypy test coverage
```
or, equivalently, with the command:
```shell
make clean lint test coverage
```

Each make target runs different checks:
- `clean` deletes temporary files
- `whitespace-format-check` runs [whitespace-format](https://github.com/DavidPal/whitespace-format) checker on all files
- `isort-check` runs [isort](https://pycqa.github.io/isort/) checker of imports in `*.py` files
- `black-check` runs [black](https://github.com/psf/black/) code format checker on `*.py` files
- `flake8` runs [flake8](https://flake8.pycqa.org/) code style checker on `*.py` files
- `pydocstyle` runs [pydocstyle](http://www.pydocstyle.org/) docstring checker on `*.py` files
- `pylint` runs [pylint](https://pylint.org/) code checker on `*.py` files
- `ruff` runs [ruff](https://ruff.rs/) code checker on `*.py` files
- `mypy` runs [mypy](http://mypy-lang.org/) type checker on `*.py` files
- `test` runs unit tests
- `coverage` generates code coverage report
- `lint` runs all code checks

You can automatically format code with the command:
```shell
make isort-format black-format whitespace-format
```

## Modifying dependencies

The list of Python packages that this project depends on is specified in
`pyproject.toml` and in `poetry.lock` files. The file `pyproject.toml` can be
edited by humans. The file `poetry.lock` is automatically generated by `poetry`.

Install a development dependency with the command:
```shell
poetry add --dev <some_new_python_tool>
```

Install a new production dependency with the command:
```shell
poetry add <some_python_library>
```

### Manual modification of `pyproject.toml`

Instead of using `poetry add` command, you can edit `pyproject.toml` file. Then,
regenerate `poetry.lock` file with the command:
```shell
poetry lock
```
or the command:
```shell
poetry lock --no-update
```
The latter command does not update already locked packages.

### Fixing broken Python environment

If your Python virtual environment becomes broken or polluted with unnecessary
packages, delete it, recreate it from scratch and install dependencies a fresh
with the following commands:
```shell
make delete-environment
make create-environment
make install-dependencies
```

