From f328c529608291443602a5a63110b9f5ee26071c Mon Sep 17 00:00:00 2001 From: Aljoscha Gerber Date: Thu, 17 Aug 2023 16:43:35 +0200 Subject: [PATCH 1/9] hooks: add poetry-update hook When switching branches keeping dependencies in sync with the lock file can become cumbersome, because it is easy to forget. Therefore poetry supplies a pre-commit hook, that can take care of it. After switching branches or checking out a file `poetry install --sync` is invoked and keeps everything nice and tidy. To make use of that, you need to either supply `default_install_hook_types` inside of your `.pre-commit-config.yaml` or you need to manually install them with: `pre-commit install --install-hooks -t pre-commit -t post-checkout -t post-merge`. --- .pre-commit-hooks.yaml | 9 +++++++++ docs/pre-commit-hooks.md | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index be3bca9dbcc..8ad485d1fd5 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -22,3 +22,12 @@ pass_filenames: false files: ^(.*/)?poetry\.lock$ args: ["-f", "requirements.txt", "-o", "requirements.txt"] + +- id: poetry-update + name: poetry-update + description: Update the Poetry dependencies if out of sync + entry: poetry install --sync + language: python + pass_filenames: false + stages: [post-checkout, post-merge] + always_run: true diff --git a/docs/pre-commit-hooks.md b/docs/pre-commit-hooks.md index 49aae8d9ccd..1d1e3baa7e8 100644 --- a/docs/pre-commit-hooks.md +++ b/docs/pre-commit-hooks.md @@ -83,6 +83,18 @@ hooks: args: ["--dev", "-f", "requirements.txt", "-o", "requirements.txt"] ``` +## poetry-update + +The `poetry-update` hook calls the `poetry install --sync` command +to make sure the installed dependencies match the packages defined in `poetry.lock`. +In order to install this hook, you either need to specify `default_install_hook_types`, or you have +to install it via `pre-commit install --install-hooks -t post-checkout -t post-merge`. + +### Arguments + +The hook takes the same arguments as the poetry command. +For more information see the [install command]({{< relref "cli#install" >}}). + ## Usage For more information on how to use pre-commit please see the [official documentation](https://pre-commit.com/). From 635fd0e351f528ccbc506d7f0c64fa9c38634b45 Mon Sep 17 00:00:00 2001 From: Aljoscha Gerber Date: Fri, 18 Aug 2023 11:00:08 +0200 Subject: [PATCH 2/9] hooks: rename hook and remove option --- .pre-commit-hooks.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 8ad485d1fd5..3d8f29e2bb2 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -23,10 +23,10 @@ files: ^(.*/)?poetry\.lock$ args: ["-f", "requirements.txt", "-o", "requirements.txt"] -- id: poetry-update - name: poetry-update - description: Update the Poetry dependencies if out of sync - entry: poetry install --sync +- id: poetry-sync + name: poetry-sync + description: Synchronize the Poetry dependencies with the lock file if out of sync + entry: poetry install language: python pass_filenames: false stages: [post-checkout, post-merge] From d8327293cec6b1072964df351b217b558e48b68a Mon Sep 17 00:00:00 2001 From: Aljoscha Gerber Date: Fri, 18 Aug 2023 11:44:31 +0200 Subject: [PATCH 3/9] hooks: offer sync option, but make it overwritable --- .pre-commit-hooks.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 3d8f29e2bb2..00caa0d37da 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -31,3 +31,4 @@ pass_filenames: false stages: [post-checkout, post-merge] always_run: true + args: ["--sync"] From c1ccc2a61045ebeb6cdd797e36c01a1caff4398e Mon Sep 17 00:00:00 2001 From: Aljoscha Gerber Date: Fri, 18 Aug 2023 14:57:27 +0200 Subject: [PATCH 4/9] docs: change name of the hook and add the hook to minimal example --- docs/pre-commit-hooks.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/pre-commit-hooks.md b/docs/pre-commit-hooks.md index 1d1e3baa7e8..2b1eb86f705 100644 --- a/docs/pre-commit-hooks.md +++ b/docs/pre-commit-hooks.md @@ -83,9 +83,9 @@ hooks: args: ["--dev", "-f", "requirements.txt", "-o", "requirements.txt"] ``` -## poetry-update +## poetry-sync -The `poetry-update` hook calls the `poetry install --sync` command +The `poetry-sync` hook calls the `poetry install --sync` command to make sure the installed dependencies match the packages defined in `poetry.lock`. In order to install this hook, you either need to specify `default_install_hook_types`, or you have to install it via `pre-commit install --install-hooks -t post-checkout -t post-merge`. @@ -109,6 +109,7 @@ repos: - id: poetry-check - id: poetry-lock - id: poetry-export + - id: poetry-sync ``` A `.pre-commit-config.yaml` example for a monorepo setup or if the `pyproject.toml` file is not in the root directory: @@ -124,6 +125,8 @@ repos: args: ["-C", "./subdirectory"] - id: poetry-export args: ["-C", "./subdirectory", "-f", "requirements.txt", "-o", "./subdirectory/requirements.txt"] + - id: poetry-sync + args: ["-C", "./subdirectory"] ``` ## FAQ From 9f61f923f37a8d6ff0f484dde779ddc8eaba7269 Mon Sep 17 00:00:00 2001 From: Aljoscha Gerber Date: Mon, 21 Aug 2023 11:09:10 +0200 Subject: [PATCH 5/9] hooks: rename poetry-sync into poetry-install --- .pre-commit-hooks.yaml | 4 ++-- docs/pre-commit-hooks.md | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 00caa0d37da..0909680227b 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -23,8 +23,8 @@ files: ^(.*/)?poetry\.lock$ args: ["-f", "requirements.txt", "-o", "requirements.txt"] -- id: poetry-sync - name: poetry-sync +- id: poetry-install + name: poetry-install description: Synchronize the Poetry dependencies with the lock file if out of sync entry: poetry install language: python diff --git a/docs/pre-commit-hooks.md b/docs/pre-commit-hooks.md index 2b1eb86f705..dfd06119d5c 100644 --- a/docs/pre-commit-hooks.md +++ b/docs/pre-commit-hooks.md @@ -83,9 +83,9 @@ hooks: args: ["--dev", "-f", "requirements.txt", "-o", "requirements.txt"] ``` -## poetry-sync +## poetry-install -The `poetry-sync` hook calls the `poetry install --sync` command +The `poetry-install` hook calls the `poetry install --sync` command to make sure the installed dependencies match the packages defined in `poetry.lock`. In order to install this hook, you either need to specify `default_install_hook_types`, or you have to install it via `pre-commit install --install-hooks -t post-checkout -t post-merge`. @@ -109,7 +109,7 @@ repos: - id: poetry-check - id: poetry-lock - id: poetry-export - - id: poetry-sync + - id: poetry-install ``` A `.pre-commit-config.yaml` example for a monorepo setup or if the `pyproject.toml` file is not in the root directory: @@ -125,7 +125,7 @@ repos: args: ["-C", "./subdirectory"] - id: poetry-export args: ["-C", "./subdirectory", "-f", "requirements.txt", "-o", "./subdirectory/requirements.txt"] - - id: poetry-sync + - id: poetry-install args: ["-C", "./subdirectory"] ``` From 00ac310cf89cdfc40a98d6ff84cf2e3c1978330e Mon Sep 17 00:00:00 2001 From: Aljoscha Gerber Date: Mon, 21 Aug 2023 15:16:37 +0200 Subject: [PATCH 6/9] hooks: remove args key --- .pre-commit-hooks.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 0909680227b..10fdc008c32 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -31,4 +31,3 @@ pass_filenames: false stages: [post-checkout, post-merge] always_run: true - args: ["--sync"] From 6293d68840350145c48b4acbda5536f7e0a20ae4 Mon Sep 17 00:00:00 2001 From: Aljoscha Gerber Date: Tue, 22 Aug 2023 09:34:38 +0200 Subject: [PATCH 7/9] docs: remove the additional arg from documentation --- docs/pre-commit-hooks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pre-commit-hooks.md b/docs/pre-commit-hooks.md index dfd06119d5c..ca6fecf92ec 100644 --- a/docs/pre-commit-hooks.md +++ b/docs/pre-commit-hooks.md @@ -85,8 +85,8 @@ hooks: ## poetry-install -The `poetry-install` hook calls the `poetry install --sync` command -to make sure the installed dependencies match the packages defined in `poetry.lock`. +The `poetry-install` hook calls the `poetry install` command +to make sure all locked packages are installed. In order to install this hook, you either need to specify `default_install_hook_types`, or you have to install it via `pre-commit install --install-hooks -t post-checkout -t post-merge`. From 4c46fe74eb0f41fb79cc18f1d462bc254010251d Mon Sep 17 00:00:00 2001 From: Aljoscha Gerber Date: Tue, 22 Aug 2023 09:45:58 +0200 Subject: [PATCH 8/9] docs: formatting --- docs/pre-commit-hooks.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/pre-commit-hooks.md b/docs/pre-commit-hooks.md index ca6fecf92ec..de9c229b48b 100644 --- a/docs/pre-commit-hooks.md +++ b/docs/pre-commit-hooks.md @@ -85,8 +85,7 @@ hooks: ## poetry-install -The `poetry-install` hook calls the `poetry install` command -to make sure all locked packages are installed. +The `poetry-install` hook calls the `poetry install` command to make sure all locked packages are installed. In order to install this hook, you either need to specify `default_install_hook_types`, or you have to install it via `pre-commit install --install-hooks -t post-checkout -t post-merge`. From b2af90b22e0df8b9409ae94da6d87aa82dac0027 Mon Sep 17 00:00:00 2001 From: Aljoscha Gerber Date: Mon, 28 Aug 2023 09:41:46 +0200 Subject: [PATCH 9/9] change description of poetry install hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com> --- .pre-commit-hooks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 10fdc008c32..8f4e23448a4 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -25,7 +25,7 @@ - id: poetry-install name: poetry-install - description: Synchronize the Poetry dependencies with the lock file if out of sync + description: run poetry install to install dependencies from the lock file entry: poetry install language: python pass_filenames: false