未验证 提交 1262987d 编写于 作者: A Andrea Mignone 提交者: GitHub

feat: add pdm export to available pre-commit hooks (#1279)

* Add pdm export to available pre-commit hooks

* Add .pre-commit-hooks.yaml
* Update the doc

* Add news fragment with the PR number
Co-authored-by: NAndrea <floatingpurr@users.noreply.github.com>
上级 8d847d59
- id: pdm-export
name: pdm-export-lock
description: export locked packages to requirements.txt or setup.py
entry: pdm export
language: python
language_version: python3
pass_filenames: false
files: ^pdm.lock$
......@@ -221,3 +221,21 @@ Below is a sample code snippet showing how to make PDM work with [lsp-python-ms]
(require 'lsp-python-ms)
(lsp)))) ; or lsp-deferred
```
## Hooks for `pre-commit`
[`pre-commit`](https://pre-commit.com/) is a powerful framework for managing git hooks in a centralized fashion. PDM already uses `pre-commit` [hooks](https://github.com/pdm-project/pdm/blob/main/.pre-commit-config.yaml) for its internal QA checks. PDM exposes also several hooks that can be run locally or in CI pipelines.
### Export `requirements.txt` or `setup.py`
This hook wraps the command `pdm export` along with any valid argument. It can be used as a hook (e.g., for CI) to ensure that you are going to check in the codebase a `requirements.txt` or a `setup.py` file, which reflects the actual content of [`pdm lock`](cli_reference.md#exec-0--lock).
```yaml
# export python requirements
- repo: https://github.com/pdm-project/pdm
rev: 2.x.y # a PDM release exposing the hook
hooks:
- id: pdm-export
# command arguments, e.g.:
args: ["-o", "requirements.txt", "--without-hashes"]
files: ^pdm.lock$
```
......@@ -244,6 +244,9 @@ pdm export -o requirements.txt
pdm export -f setuppy -o setup.py
```
!!! NOTE
You can also run `pdm export` with a [`.pre-commit` hook](advanced.md#hooks-for-pre-commit).
## Hide the credentials from pyproject.toml
There are many times when we need to use sensitive information, such as login credentials for the PyPI server
......
Add `pdm export` to available pre-commit hooks.
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册