Skip to content

Commit

Permalink
add pre-commit support. (#76)
Browse files Browse the repository at this point in the history
Adds pre-commit support for the project. I've felt hooks for `--safe`
and `--aggressive` should cover most use-cases but I'll be happy to
include others if that appears better.

Closes #75.
  • Loading branch information
exitflynn authored Aug 19, 2024
1 parent 4dc503a commit 665fd12
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- id: autotyping
name: autotyping
description: Automatically add simple type-annotations to your code.
entry: autotyping
language: python
types_or: [python, pyi]
args: [*]
additional_dependencies: []
minimum_pre_commit_version: 2.9.2
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ annotations.

# Usage

Here's how to use it:
Autotyping can be called directly from the CLI, be used as a [pre-commit hook](#pre-commit-hook) or run via the [`libcst` interface](#LibCST) as a codemod.
Here's how to use it from the CLI:

- `pip install autotyping`
- `python -m autotyping /path/to/my/code`
Expand Down Expand Up @@ -92,6 +93,44 @@ If you wish to run things through the `libcst.tool` interface, you can do this l
For an example, see the `.libcst.codemod.yaml` in this repo.
- Run `python -m libcst.tool codemod autotyping.AutotypeCommand /path/to/my/code`


# pre-commit hook

Pre-commit hooks are scripts that runs automatically before a commit is made,
which makes them really handy for checking and enforcing code-formatting
(or in this case, typing)

1. To add `autotyping` as a [pre-commit](https://pre-commit.com/) hook,
you will first need to install pre-commit if you haven't already:
```
pip install pre-commit
```

2. After that, create or update the `.pre-commit-config.yaml` file at the root
of your repository and add in:

```yaml
- repos:
- repo: https://github.com/JelleZijlstra/autotyping
rev: v24.4.0
hooks:
- id: autotyping
stages: [commit]
types: [python]
args: [--safe] # or alternatively, --aggressive, or any of the other flags mentioned above
```
3. Finally, run the following command to install the pre-commit hook
in your repository:
```
pre-commit install
```

Now whenever you commit changes, autotyping will automatically add
type annotations to your code!


# Limitations

Autotyping is intended to be a simple tool that uses heuristics to find
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ commands =

[testenv:pyanalyze]
deps =
pyanalyze == 0.12.0
pyanalyze == 0.13.1
commands =
python -m pyanalyze --config pyproject.toml -v autotyping

Expand Down

0 comments on commit 665fd12

Please sign in to comment.