Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger pre-commit hooks for pyproject.toml in subfolder #8204

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Trigger pre-commit hooks for pyproject.toml in subfolder
Signed-off-by: bentocin <[email protected]>
  • Loading branch information
bentocin authored and radoering committed Jul 26, 2023
commit f6358885ba4d3756f5ff1576b6e7503e31a76615
3 changes: 2 additions & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
entry: poetry lock
language: python
pass_filenames: false
files: ^(.*/)?(poetry.lock|pyproject.toml)$

- id: poetry-export
name: poetry-export
description: run poetry export to sync lock file with requirements.txt
entry: poetry export
language: python
pass_filenames: false
files: ^poetry.lock$
files: ^(.*/)?poetry.lock$
args: ["-f", "requirements.txt", "-o", "requirements.txt"]
30 changes: 21 additions & 9 deletions docs/pre-commit-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ the defaults are overwritten. You must fully specify all arguments for
your hook if you make use of `args:`.
{{% /note %}}

{{% note %}}
If the `pyproject.toml` file is not in the root directory, you can specify `args: ["-C", "./subdirectory"]`.
{{% /note %}}

## poetry-check

The `poetry-check` hook calls the `poetry check` command
Expand All @@ -34,10 +38,6 @@ to make sure the poetry configuration does not get committed in a broken state.
The hook takes the same arguments as the poetry command.
For more information see the [check command]({{< relref "cli#check" >}}).

{{% note %}}
If the `pyproject.toml` file is not in the root directory, you can specify `args: ["-C", "./subdirectory"]`.
{{% /note %}}

## poetry-lock

The `poetry-lock` hook calls the `poetry lock` command
Expand All @@ -48,7 +48,6 @@ to make sure the lock file is up-to-date when committing changes.
The hook takes the same arguments as the poetry command.
For more information see the [lock command]({{< relref "cli#lock" >}}).


## poetry-export

The `poetry-export` hook calls the `poetry export` command
Expand All @@ -64,7 +63,7 @@ The hook takes the same arguments as the poetry command.
For more information see the [export command]({{< relref "cli#export" >}}).

The default arguments are `args: ["-f", "requirements.txt", "-o", "requirements.txt"]`,
which will create/update the requirements.txt file in the current working directory.
which will create/update the `requirements.txt` file in the current working directory.

You may add `verbose: true` in your `.pre-commit-config.yaml` in order to output to the
console:
Expand All @@ -84,22 +83,35 @@ hooks:
args: ["--dev", "-f", "requirements.txt", "-o", "requirements.txt"]
```


## Usage

For more information on how to use pre-commit please see the [official documentation](https://pre-commit.com/).

A full `.pre-commit-config.yaml` example:
A minimalistic `.pre-commit-config.yaml` example:

```yaml
repos:
- repo: https://github.com/python-poetry/poetry
rev: '' # add version here
hooks:
- id: poetry-check
- id: poetry-lock
- id: poetry-export
```

A `.pre-commit-config.yaml` example for a monorepo setup or if the `pyproject.toml` file is not in the root directory:

```yaml
repos:
- repo: https://github.com/python-poetry/poetry
rev: '' # add version here
hooks:
- id: poetry-check
args: ["-C", "./subdirectory"]
- id: poetry-lock
args: ["-C", "./subdirectory"]
- id: poetry-export
args: ["-f", "requirements.txt", "-o", "requirements.txt"]
args: ["-C", "./subdirectory", "-f", "requirements.txt", "-o", "./subdirectory/requirements.txt"]
```

## FAQ
Expand Down