Skip to content

Conversation

@j178
Copy link
Owner

@j178 j178 commented Aug 22, 2025

Closes #509

For Python hooks without additional_dependencies, prek will try to read the PEP 723 inline metadata from the entry field. (if shlex.split(entry)[0] is a local file.)

For example:

.pre-commit-config.yaml:

repos:
  - repo: local
    hooks:
      - id: echo
        name: echo
        language: python
        entry: ./echo.py

echo.py:

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "pyecho-cli",
# ]
# ///

from pyecho import main
main()

Note that:

  • The first part of the entry field must be a path to the Python script.
  • If you specified additional_dependencies in .pre-commit-config.yaml, script metadata will not be read.
  • Setting both the language_version in .pre-commit-config.yaml and requiest-python in the inline metadata, the language_version will be ignored.
  • Only the top-level fields dependencies and requires-python in inline metadata are supported, other fields like tool.uv are all ignored.

@j178 j178 added the enhancement New feature or request label Aug 22, 2025
@j178 j178 marked this pull request as draft August 22, 2025 06:39
@potiuk
Copy link

potiuk commented Aug 22, 2025

Nice!

Fix

Debug windows

debug

Fix

# Conflicts:
#	tests/languages/python.rs
@j178 j178 marked this pull request as ready for review August 25, 2025 09:02
@j178 j178 merged commit c5fb6ec into master Aug 25, 2025
21 checks passed
@j178 j178 deleted the pep723-script branch August 25, 2025 09:07
@j178 j178 changed the title Support PEP723 scripts for local Python hooks Support PEP 723 scripts for Python hooks Aug 25, 2025
@nathanjmcdougall
Copy link

This is a really cool feature.

@potiuk
Copy link

potiuk commented Aug 25, 2025

Indeed ;)

potiuk added a commit to potiuk/airflow that referenced this pull request Aug 25, 2025
Following the change in j178/prek#529 and
release of prek 0.1.3, we convert all our Python scripts to use
PEP-723-compliant inline scripts.

This will remove decoupling of scripts from their dependencies,
and will allow to run them easily by `uv run` as well as easier
debugging and testing.
potiuk added a commit to potiuk/airflow that referenced this pull request Aug 25, 2025
Following the change in j178/prek#529 and
release of prek 0.1.3, we convert all our Python scripts to use
PEP-723-compliant inline scripts.

This will remove decoupling of scripts from their dependencies,
and will allow to run them easily by `uv run` as well as easier
debugging and testing.
potiuk added a commit to potiuk/airflow that referenced this pull request Aug 25, 2025
Following the change in j178/prek#529 and
release of prek 0.1.3, we convert all our Python scripts to use
PEP-723-compliant inline scripts.

This will remove decoupling of scripts from their dependencies,
and will allow to run them easily by `uv run` as well as easier
debugging and testing.
potiuk added a commit to potiuk/airflow that referenced this pull request Aug 25, 2025
Following the change in j178/prek#529 and
release of prek 0.1.3, we convert all our Python scripts to use
PEP-723-compliant inline scripts.

This will remove decoupling of scripts from their dependencies,
and will allow to run them easily by `uv run` as well as easier
debugging and testing.
potiuk added a commit to apache/airflow that referenced this pull request Aug 25, 2025
…54917)

Following the change in j178/prek#529 and
release of prek 0.1.3, we convert all our Python scripts to use
PEP-723-compliant inline scripts.

This will remove decoupling of scripts from their dependencies,
and will allow to run them easily by `uv run` as well as easier
debugging and testing.
mangal-vairalkar pushed a commit to mangal-vairalkar/airflow that referenced this pull request Aug 30, 2025
…pache#54917)

Following the change in j178/prek#529 and
release of prek 0.1.3, we convert all our Python scripts to use
PEP-723-compliant inline scripts.

This will remove decoupling of scripts from their dependencies,
and will allow to run them easily by `uv run` as well as easier
debugging and testing.
nothingmin pushed a commit to nothingmin/airflow that referenced this pull request Sep 2, 2025
…pache#54917)

Following the change in j178/prek#529 and
release of prek 0.1.3, we convert all our Python scripts to use
PEP-723-compliant inline scripts.

This will remove decoupling of scripts from their dependencies,
and will allow to run them easily by `uv run` as well as easier
debugging and testing.
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Oct 24, 2025
…#54917)

Following the change in j178/prek#529 and
release of prek 0.1.3, we convert all our Python scripts to use
PEP-723-compliant inline scripts.

This will remove decoupling of scripts from their dependencies,
and will allow to run them easily by `uv run` as well as easier
debugging and testing.

GitOrigin-RevId: 0df08334cd1c6272db09d95b94aa250a3340630b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support inline script metadata (PEP 723) in python hooks

4 participants