Giter VIP home page Giter VIP logo

pre-commit-hook-yamlfmt's Introduction

YAML formatter for pre-commit git hooks

YAML formatter for pre-commit.

This hook formats the indentation of YAML files and optionally aligns top-level colons.
It uses ruamel.yaml to do the heavy lifting and preserve comments within YAML files.

How-to

Configure pre-commit

Use defaults

Add to .pre-commit-config.yaml in your git repo:

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
  rev: 0.2.1  # or other specific tag
  hooks:
      - id: yamlfmt

💡 If a pre-commit hook changes a file, the hook fails with a warning that files were changed.

The default settings are:

  • mapping: 4 spaces
  • sequence: 6 spaces
  • offset: 4 spaces
  • colons: do not align top-level colons
  • width: None (use ruamel default)

Given this input:

foo:
  bar:
    - baz1
    - baz2

The default settings result in this output:

---
foo:
    bar:
        - baz1
        - baz2

Combine with yamllint

yamlfmt only works with valid YAML files, so I recommend to use yamllint and yamlfmt together.

- repo: https://github.com/adrienverge/yamllint.git
  rev: v1.21.0  # or higher tag
  hooks:
      - id: yamllint
        args: [--format, parsable, --strict]

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
  rev: 0.2.1  # or other specific tag
  hooks:
      - id: yamlfmt

Override defaults

Add to .pre-commit-config.yaml in your git repo:

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
  rev: 0.2.1  # or other specific tag
  hooks:
      - id: yamlfmt
        args: [--mapping, '2', --sequence, '2', --offset, '0', --colons, --width, '150']

Invoke pre-commit

On every commit

If you want to invoke the checks as a git pre-commit hook, run:

# Run on every commit.
pre-commit install

On demand

If you want to run the checks on-demand (outside of git hooks), run:

# Run on-demand.
pre-commit run --all-files

The test harness of this git repo uses this approach.

Contributing

Please see CONTRIBUTING.md.

Testing

Please see TESTING.md.

License

The code in this repo is licensed under the MIT License.

pre-commit-hook-yamlfmt's People

Contributors

archoversight avatar donbowman avatar dudicoco avatar jumanjiman avatar rsnodgrass avatar voodoodror avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pre-commit-hook-yamlfmt's Issues

pre-commit hook installation fails on linux

Running on Ubuntu 20.04 Github runner with revision 0.1.0, pre-commit hook installation fails

[INFO] Installing environment for https://github.com/jumanjihouse/pre-commit-hook-yamlfmt.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/runner/.cache/pre-commit/repox1ruov2g/py_env-python3.9/bin/python', '-mpip', 'install', '.')
return code: 1
expected return code: 0
stdout:
    Processing /home/runner/.cache/pre-commit/repox1ruov2g
      Preparing metadata (setup.py): started
      Preparing metadata (setup.py): finished with status 'error'
    
stderr:
      error: subprocess-exited-with-error
      
      × python setup.py egg_info did not run successfully.
      │ exit code: 1
      ╰─> [14 lines of output]
          error: Multiple top-level packages discovered in a flat-layout: ['assets', 'pre_commit_hooks'].
          
          To avoid accidental inclusion of unwanted files or directories,
          setuptools will not proceed with this build.
          
          If you are trying to create a single distribution with multiple packages
          on purpose, you should not rely on automatic discovery.
          Instead, consider the following options:
          
          1. set up custom discovery (`find` directive with `include` or `exclude`)
          2. use a `src-layout`
          3. explicitly set `py_modules` or `packages` with a list of names
          
          To find more information, look for "package discovery" on setuptools docs.
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: metadata-generation-failed
    
    × Encountered error while generating package metadata.
    ╰─> See above for output.
    
    note: This is an issue with the package mentioned above, not pip.
    hint: See above for details.

Implement dictionary key sorting

When formatting yaml files it is a good idea to order dictionary keys to minimise merge conflicts when storing his code in git. This issue is to request the implementation of key sorting in the yamlfmt pre-commit hook.

Executable ... not found when running pre-commit

Issue

When I run pre-commit run --all-files I get the following:

Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Passed
Check Yaml...............................................................Passed
Check for added large files..............................................Passed
yamllint.................................................................Passed
Format YAML files........................................................Failed
- hook id: yamlfmt
- exit code: 1

Executable `C:UsersUser.cachepre-commitrepoolie1bxepy_env-python3.9Scriptspython.EXE` not found

It looks like somwhere somehow the / characters are being stripped because I was able to find this:

C:\Users\User\.cache\pre-commit\repoolie1bxe\py_env-python3.9\Scripts\python.exe

I even tried renaming .../python.exe to .../python.EXE but that didn't seem to matter.

Config

My .pre-commit-config.yaml file:

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
  - repo: 'https://github.com/pre-commit/pre-commit-hooks'
    rev: v3.2.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-added-large-files

  - repo: https://github.com/adrienverge/yamllint.git
    rev: v1.21.0
    hooks:
      - id: yamllint
        args: [--format, parsable, --strict, --config-file, config.yamllint]

  - repo: 'https://github.com/jumanjihouse/pre-commit-hook-yamlfmt'
    rev: 0.1.0
    hooks:
      - id: yamlfmt

Environment

I am using Windows 10 Pro
I have activated a virtual environment, but both the virtual environment and the global one have pre-commit installed.
My python version is 3.9.5

Request: ability to use double quotes

Python black prefers double quotes: https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#strings

Since I use Python, I like my YAML to use double quotes too. Running this tool on my repo moves it to use single quotes:

-        if: "github.event_name == 'release' && github.event.action == 'published'"
+        if: github.event_name == 'release' && github.event.action == 'published'

There is the --preserve-quotes option, which leads to not touching quotes at all. I actually like when this tool makes changes like this, so I want to keep --preserve-quote on:

-                  cache: "pip"
+                  cache: pip

My request is to add a new option resembling black's --skip-string-normalization that will just not convert double quotes to single quotes.

Recommended autoformatter introduces lint errors

For YAML files like this:

location: external
sources:
  - repo: foo
    name: bar
    rev: main
    type: git
    params:
    sparse_paths:
      -
    links:
      -

The autoformatter adds trailing spaces:

diff --git a/test.yaml b/test.yaml
index 272e7eb..f1b8fbe 100644
--- a/test.yaml
+++ b/test.yaml
@@ -1,12 +1,13 @@
+---
 location: external
 sources:
-  - repo: foo
-    name: bar
-    rev: main
-    type: git
-    params:
-    sparse_paths:
-      -
-    links:
-      -
+    - repo: foo
+      name: bar
+      rev: main
+      type: git
+      params:
+      sparse_paths:
+          - 
+      links:
+          - 

image

Is it possible to ignore a line ?

Hello,

I am working on a docker compose including mongo (among other services), and I have an issue with yamlfmt. Let's look at the following example:

  mongo:
    image: $MONGO_IMAGE:$MONGO_VERSION
    container_name: mongo
    hostname: mongo
    volumes:
      # Persistent docker volume
      - mongo-storage:/data/db:rw
    networks:
      - logging_network
    restart: 'no'

Yamlfmt turns it into:

  mongo:
    image: $MONGO_IMAGE:$MONGO_VERSION
    container_name: mongo
    hostname: mongo
    volumes:
      # Persistent docker volume
      - mongo-storage:/data/db:rw
    networks:
      - logging_network
    restart: no

Please notice that the single quotes around no are removed. But they are required. Is it possible to make yamlfmt ignore this line ?

Turn --preserve-quotes on by default

I ran yamlfmt with it's default settings over a codebase with a lot of YAML config.
It removes quotation marks from strings by default. This changes the semantic meaning of the files being formatted in the following ways:

Booleans:
"yes" and "no" are strings, but without quotes, they are parsed as booleans. Docker-compose in particular wants strings and chokes when given booleans.

Integers:
"10" is a string, but without quotes it is parsed as a number. This can cause problems.

This formatter should only be moving text around, not changing the meaning of it.
The --preserve-quotes flag should be on by default to avoid these issues.

yamlfmt conflicts with yamllint if there is a long URL

  • yamllint recommends breaking long URL [more than 80 characters] into a new line.
  • yamlfmt removes the new line and put the URL back in one line.

yamllint
error line too long (86 > 80 characters) (line-length)

yamlfmt
Format YAML files........................................................Failed

  • hook id: yamlfmt
  • files were modified by this hook

File path issue when running locally on Windows

Hi.
The senior developer on my team has set up pre-commit hooks using this utility.
The pre-commit succeeds in github, but when I run it locally, I get an error like this:

$ git commit -m "Line ending fix"
Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Passed
Check Yaml...............................................................Passed
Check JSON...........................................(no files to check)Skipped
Check Toml...........................................(no files to check)Skipped
Check for added large files..............................................Passed
Check for case conflicts.................................................Passed
Check for broken symlinks............................(no files to check)Skipped

Executable `C:UsersMSOV.cachepre-commitrepo3vt2tuwjpy_env-python3.10Scriptspython.EXE` not found

The exe files exist:

 Directory of C:\Users\MSOV\.cache\pre-commit\repo3vt2tuwj\py_env-python3.10\Scripts

06.04.2022  13:54    <DIR>          .
06.04.2022  13:54    <DIR>          ..
06.04.2022  13:53             2 185 activate
06.04.2022  13:53             1 025 activate.bat
06.04.2022  13:53             3 062 activate.fish
06.04.2022  13:53             1 369 activate.nu
06.04.2022  13:53             1 758 activate.ps1
06.04.2022  13:53             1 193 activate_this.py
06.04.2022  13:53               510 deactivate.bat
06.04.2022  13:53               333 deactivate.nu
06.04.2022  13:53           106 904 pip-3.10.exe
06.04.2022  13:53           106 904 pip.exe
06.04.2022  13:53           106 904 pip3.10.exe
06.04.2022  13:53           106 904 pip3.exe
06.04.2022  13:53                24 pydoc.bat
06.04.2022  13:53           263 056 python.exe
06.04.2022  13:53           251 792 pythonw.exe
06.04.2022  13:53           106 891 wheel-3.10.exe
06.04.2022  13:53           106 891 wheel.exe
06.04.2022  13:53           106 891 wheel3.10.exe
06.04.2022  13:53           106 891 wheel3.exe
06.04.2022  13:54             4 450 yamlfmt
              20 File(s)      1 385 937 bytes
               2 Dir(s)  668 514 533 376 bytes free

but the path seems to have a problem

How to exclude certain files from yamlfmt?

My review build runs pre-commit run --all-files. I have some jinja templates that end with extension .yaml. Is there a way to exclude certain files from yamlfmt?

I know I can add an exclude to .pre-commit-config.yaml and change the template's extension. Is there a way to configure yamlfmt itself though?

yamllint

Meant to search for yamllint and opened this ticket by accident 🤦🏻

Anyway, I saw #28

mapping values are not allowed here

Pre-commit-config :

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
  rev: 0.2.2
  hooks:
  - id: yamlfmt
    name: YAML FMT
    args: [--mapping, '2', --sequence, '2', --offset, '0', --width, '250']

Example YAML file with indentation problem :

images:
    - name: eu.gcr.io/xxxxxxxxxx/xxxx/xxxxxxxxxxx/xxxxxxxx
         newTag: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Error when i commit :

YAML FMT.................................................................Failed
- hook id: yamlfmt
- exit code: 1

api-medicaments/overlays/dev/kustomization.yamlTraceback (most recent call last):
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/bin/yamlfmt", line 181, in <module>
    FORMATTER.format(file_name)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/bin/yamlfmt", line 137, in format
    FORMATTER.parse_file(path)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/bin/yamlfmt", line 147, in parse_file
    self.content = list(self.yaml.load_all(stream))
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/main.py", line 461, in load_all
    yield constructor.get_data()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/constructor.py", line 114, in get_data
    return self.construct_document(self.composer.get_node())
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 66, in get_node
    return self.compose_document()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 99, in compose_document
    node = self.compose_node(None, None)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 143, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 223, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 141, in compose_node
    node = self.compose_sequence_node(anchor)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 185, in compose_sequence_node
    node.value.append(self.compose_node(node, index))
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 143, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 223, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 113, in compose_node
    if self.parser.check_event(AliasEvent):
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/parser.py", line 146, in check_event
    self.current_event = self.state()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/parser.py", line 630, in parse_block_mapping_value
    if self.scanner.check_token(ValueToken):
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/scanner.py", line 1796, in check_token
    self._gather_comments()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/scanner.py", line 1838, in _gather_comments
    self.fetch_more_tokens()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/scanner.py", line 288, in fetch_more_tokens
    return self.fetch_value()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/scanner.py", line 657, in fetch_value
    raise ScannerError(
ruamel.yaml.scanner.ScannerError: mapping values are not allowed here
  in "api-medicaments/overlays/dev/kustomization.yaml", line 20, column 15

Pin ruamel.yaml dependency version

2 hours ago, a new version of https://pypi.org/project/ruamel.yaml/ was released, which introduced breaking changes. Ideally, if there is no update to this hook itself, there should be no changes in the transient dependencies. To prevent this in the future, I would suggest to either pin the version in the setup.py or switch to poetry where the version is pinned automatically in the peotry.lock file.

Docker support

There is no issue, more of a request :)

What about adding a Dockerfile and release a docker image to a public registry?
This will allow to run this hook as a docker image in pre-commit.

Unexpected ':'

I have the following bit in .pre-commit-config.yaml

---
repos:
    - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
      rev: 0.0.11
      hooks:
          - id: yamlfmt
    - repo: https://github.com/PyCQA/flake8
      rev: 3.9.2
      hooks:
          - id: flake8
            args: [--max-line-length=100, --per-file-ignores=python/myrepo/*.py:F401]

However, I'm getting a persistent

while scanning a plain scalar
  in ".pre-commit-config.yaml", line 11, column 43
found unexpected ':'
  in ".pre-commit-config.yaml", line 11, column 81

The syntax that I use in legal, and I think the only syntax. How do I get rid of this error?

ruamel.yaml.clib 0.2.8 breaks the hook

This config:

/src # cat .pre-commit-config.yaml 
repos:
  - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
    rev: 0.2.3
    hooks:
      - id: yamlfmt
        args: [--mapping, "2", --sequence, "4", --offset, "2", --implicit_start, --preserve-quotes]

started failing recently with the following error, in a docker image that doesn't have a compiler:

/src # pre-commit run -a
[INFO] Initializing environment for https://github.com/jumanjihouse/pre-commit-hook-yamlfmt.

[INFO] Installing environment for https://github.com/jumanjihouse/pre-commit-hook-yamlfmt.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/root/.cache/pre-commit/repoqe2uup23/py_env-python3.10/bin/python', '-mpip', 'install', '.')
return code: 1
expected return code: 0
stdout:
    Processing /root/.cache/pre-commit/repoqe2uup23
      Preparing metadata (setup.py): started
      Preparing metadata (setup.py): finished with status 'done'
    Collecting ruamel.yaml<=0.17.21,>=0.16.10
      Using cached ruamel.yaml-0.17.21-py3-none-any.whl (109 kB)
    Collecting ruamel.yaml.clib>=0.2.6
      Using cached ruamel.yaml.clib-0.2.8.tar.gz (213 kB)
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'done'
      Preparing metadata (pyproject.toml): started
      Preparing metadata (pyproject.toml): finished with status 'done'
    Building wheels for collected packages: yamlfmt, ruamel.yaml.clib
      Building wheel for yamlfmt (setup.py): started
      Building wheel for yamlfmt (setup.py): finished with status 'done'
      Created wheel for yamlfmt: filename=yamlfmt-0.0.0-py3-none-any.whl size=3676 sha256=99f22f651364bb144b5a6102e6ae63f7eb2e7689a86a538ea90f40673494fc15
      Stored in directory: /tmp/pip-ephem-wheel-cache-207pj1w7/wheels/1e/76/19/b716d6907ed8957038ab893ad923597a246cf9974f5bb2acf5
      Building wheel for ruamel.yaml.clib (pyproject.toml): started
      Building wheel for ruamel.yaml.clib (pyproject.toml): finished with status 'error'
    Successfully built yamlfmt
    Failed to build ruamel.yaml.clib
    
stderr:
      ERROR: Command errored out with exit status 1:
       command: /root/.cache/pre-commit/repoqe2uup23/py_env-python3.10/bin/python /root/.cache/pre-commit/repoqe2uup23/py_env-python3.10/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmp8z9rfm4a
           cwd: /tmp/pip-install-8hfum2w8/ruamel-yaml-clib_9987d0789bba4cf09cb30210c3e77a7b
      Complete output (16 lines):
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-310
      creating build/lib.linux-x86_64-cpython-310/ruamel
      creating build/lib.linux-x86_64-cpython-310/ruamel/yaml
      creating build/lib.linux-x86_64-cpython-310/ruamel/yaml/clib
      copying ./__init__.py -> build/lib.linux-x86_64-cpython-310/ruamel/yaml/clib
      copying ./setup.py -> build/lib.linux-x86_64-cpython-310/ruamel/yaml/clib
      copying ./LICENSE -> build/lib.linux-x86_64-cpython-310/ruamel/yaml/clib
      running build_ext
      building '_ruamel_yaml' extension
      creating build/temp.linux-x86_64-cpython-310
      gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/root/.cache/pre-commit/repoqe2uup23/py_env-python3.10/include -I/usr/local/include/python3.10 -c _ruamel_yaml.c -o build/temp.linux-x86_64-cpython-310/_ruamel_yaml.o
      error: command 'gcc' failed: No such file or directory
      ----------------------------------------
      ERROR: Failed building wheel for ruamel.yaml.clib
    ERROR: Could not build wheels for ruamel.yaml.clib, which is required to install pyproject.toml-based projects

Forcing installation of 0.2.7 fixes the issue:

/src # cat constraint.txt 
ruamel.yaml.clib<=0.2.7

/src # PIP_CONSTRAINT=`pwd`/constraint.txt pre-commit run -a
[INFO] Installing environment for https://github.com/jumanjihouse/pre-commit-hook-yamlfmt.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
Format YAML files........................................................Passed
/src # cat .pre-commit-config.yaml 

Enable ability to retain null values

We use this for yaml templates for flux and it overwrites null values instead of retaining them which prevents things from deploying properly.

Installation with tag 0.1.0 is failing

Hello when I'm running pre-commit run -a with .pre-commit-config.yaml:

repos:
  - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
    rev: 0.1.0
    hooks:
      - id: yamlfmt
        args: [--mapping, "2", --sequence, "4", --offset, "2", --implicit_start, --preserve]

I got an error:

pre-commit run --all-files
[INFO] Installing environment for https://github.com/jumanjihouse/pre-commit-hook-yamlfmt.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/andrzej/.cache/pre-commit/repojun84su0/py_env-python3.8/bin/python', '-mpip', 'install', '.')
return code: 1
expected return code: 0
stdout:
    Looking in indexes: <Obfuscated link>, https://pypi.org/simple
    Processing /home/andrzej/.cache/pre-commit/repojun84su0
      Preparing metadata (setup.py): started
      Preparing metadata (setup.py): finished with status 'error'

stderr:
      error: subprocess-exited-with-error

      × python setup.py egg_info did not run successfully.
      │ exit code: 1
      ╰─> [14 lines of output]
          error: Multiple top-level packages discovered in a flat-layout: ['assets', 'pre_commit_hooks'].

          To avoid accidental inclusion of unwanted files or directories,
          setuptools will not proceed with this build.

          If you are trying to create a single distribution with multiple packages
          on purpose, you should not rely on automatic discovery.
          Instead, consider the following options:

          1. set up custom discovery (`find` directive with `include` or `exclude`)
          2. use a `src-layout`
          3. explicitly set `py_modules` or `packages` with a list of names

          To find more information, look for "package discovery" on setuptools docs.
          [end of output]

      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: metadata-generation-failed

    × Encountered error while generating package metadata.
    ╰─> See above for output.

    note: This is an issue with the package mentioned above, not pip.
    hint: See above for details.

Check the log at /home/andrzej/.cache/pre-commit/pre-commit.log

Changing the ref from 0.1.0 to 0.1.1 solves the problem. I think both of tag should work. The problem appeared 5-6 hours ago on my CI

Setting different offset breaks hte pre-commit-hook config

I am trying to run different formatting option than the default

    args: [--mapping, '2', --sequence, '2', --offset, '2', --width, '150']

After setting offset to 2 I try to commit the changes and the format breaks the config itself by doing these changes

 ---
 repos:
-- repo: https://github.com/pre-commit/pre-commit-hooks
+  - repo: https://github.com/pre-commit/pre-commit-hooks
   rev: v4.2.0
   hooks:
-  - id: check-yaml
-  - id: check-ast
+    - id: check-yaml
+    - id: check-ast

Example of the config before

---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.2.0
  hooks:
  - id: check-yaml
  - id: check-ast
  - id: trailing-whitespace
  - id: check-added-large-files
  - id: debug-statements
  - id: detect-private-key
  - id: requirements-txt-fixer
  - id: name-tests-test

After the format

---
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.2.0
  hooks:
    - id: check-yaml
    - id: check-ast
          #- id: end-of-file-fixer
    - id: trailing-whitespace
    - id: check-added-large-files
    - id: debug-statements
    - id: detect-private-key
    - id: requirements-txt-fixer
    - id: name-tests-test

i have no idea what is causing this, but in need for more info I can help out with something.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.