Skip to content

pre-commit hook requires code-embedder pre-installed #52

@JohelEGP

Description

@JohelEGP

Greetings.

pre-commit is great because its hooks require 0 setup with respect to dependency installation.

Both the README's option B and the tracked .pre-commit-hooks.yaml use language: system.
This makes it so that a system installation of code-embedder is required to use the hook.
The output of using the README's option B in my pre-commit configuration serves as evidence:

Code embedder............................................................Failed
- hook id: code-embedder
- exit code: 1

Executable `code-embedder` not found

Simply switching to language: python in .pre-commit-hooks.yaml should make it so that the dependency on code-embedder is fetched from the language's package manager.
Then, a more conventional pre-commit config entry will do the job:

- repo: https://github.com/kvankova/code-embedder
  rev: v1.1.2
  hooks:
    - id: code-embedder
      # name: Code embedder # No longer needed, as it comes from the `repo`'s `.pre-commit-hooks.yaml`.
      entry: code-embedder run # No longer needs a system installation.
      # language: system # No longer needed.

You should be able to go further, and make the .pre-commit-hooks.yaml's entry just like above, with the run argument included.
That should reduce the above to this:

- repo: https://github.com/kvankova/code-embedder
  rev: v1.1.2
  hooks:
    - id: code-embedder

For now, this is what I'm using, with great success:

- repo: local
  hooks:
  - id: code-embedder
    name: Code embedder
    entry: code-embedder run
    language: python
    files: .*.md$
    additional_dependencies: [code-embedder==1.1.2]

Incidentally, I should be using types: [markdown] to more correctly filter the types the hook operates on.
I see that .pre-commit-hooks.yaml is totally unconstrained on that, so it's also needed there.
In the end, I think .pre-commit-hooks.yaml should look like this:

- id: code-embedder
  name: Code embedder
  description: >
    Keep your code snippets in README up-to-date!
  entry: code-embedder run
  types: [markdown]
  language: python

Thank you for this software.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions