Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.pre-commit-config.yaml file created by nitpick doesn't have the rev key #472

Open
khuyentran1401 opened this issue Mar 23, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@khuyentran1401
Copy link

Expected behavior

After running, nitpick fix, a .pre-commit-config.yaml file was created. I expect to see the required key rev under all repos.

Current behavior

No key rev is shown in the .pre-commit-config.yaml file. Here is how the file looks like:

repos:
  - repo: https://github.com/PyCQA/bandit
    hooks:
      - id: bandit
        args:
          - --ini
          - setup.cfg
        exclude: tests/
  - repo: https://github.com/psf/black
    hooks:
      - id: black
        args:
          - --safe
          - --quiet
  - repo: https://github.com/asottile/blacken-docs
    hooks:
      - id: blacken-docs
        additional_dependencies:
          - black==21.5b2
  - repo: https://github.com/PyCQA/flake8
    hooks:
      - id: flake8
        additional_dependencies:
          - flake8-blind-except
          - flake8-bugbear
          - flake8-comprehensions
          - flake8-debugger
          - flake8-docstrings
          - flake8-isort
          - flake8-polyfill
          - flake8-pytest
          - flake8-quotes
          - flake8-typing-imports
          - yesqa
  - repo: https://github.com/pre-commit/pygrep-hooks
    hooks:
      - id: python-check-blanket-noqa
      - id: python-check-mock-methods
      - id: python-no-eval
      - id: python-no-log-warn
      - id: rst-backticks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    hooks:
      - id: debug-statements
  - repo: https://github.com/asottile/pyupgrade
    hooks:
      - id: pyupgrade
        args:
          - --py37-plus
  - repo: https://github.com/PyCQA/isort
    hooks:
      - id: isort
  - repo: https://github.com/pre-commit/mirrors-mypy
    hooks:
      - id: mypy
        args:
          - --show-error-codes
  - repo: local
    hooks:
      - id: pylint
        name: pylint
        language: system
        exclude: tests/
        types:
          - python
  - repo: https://github.com/myint/autoflake
    hooks:
      - id: autoflake
        args:
          - --in-place
          - --remove-all-unused-imports
          - --remove-unused-variables
          - --remove-duplicate-keys
          - --ignore-init-module-imports
  - repo: https://github.com/commitizen-tools/commitizen
    hooks:
      - id: commitizen
        stages:
          - commit-msg
  - repo: https://github.com/pre-commit/pre-commit-hooks
    hooks:
      - id: end-of-file-fixer
      - id: trailing-whitespace
  - repo: https://github.com/pre-commit/mirrors-prettier
    hooks:
      - id: prettier
        stages:
          - commit
  - repo: https://github.com/openstack/bashate
    hooks:
      - id: bashate
        args:
          - -i
          - E006

Steps to reproduce

Run nitpick fix created a .pre-commit-config.yaml file

Context

I can't commit because of the missing required key rev. Here is the messing I saw when committed:

An error has occurred: InvalidConfigError: 
==> File .pre-commit-config.yaml
==> At Config()
==> At key: repos
==> At Repository(repo='https://github.com/PyCQA/bandit')
=====> Missing required key: rev
Check the log at /Users/khuyen/.cache/pre-commit/pre-commit.log

Your environment

  • nitpick version used: 0.31.0
  • Python version: 3.8.10
  • Operating System and version: MacOS
  • Link to your project:
  • Run the following commands and paste the output:
$ poetry show
aiohttp                3.8.1     Async http client/server framework (asyncio)
aiohttp-retry          2.4.6     Simple retry client for aiohttp
aiosignal              1.2.0     aiosignal: a list of registered asynchronous callbacks
antlr4-python3-runtime 4.8       ANTLR 4.8 runtime for Python 3.7
appdirs                1.4.4     A small Python module for determining appropriate platform-specific dirs, e.g. a "user dat...
async-timeout          4.0.2     Timeout context manager for asyncio programs
asyncssh               2.8.1     AsyncSSH: Asynchronous SSHv2 client and server library
atpublic               3.0.1     Keep all y'all's __all__'s in sync
attrs                  21.4.0    Classes Without Boilerplate
autorepr               0.3.0     Makes civilized __repr__, __str__, and __unicode__ methods
cachy                  0.3.0     Cachy provides a simple yet effective caching library.
certifi                2021.10.8 Python package for providing Mozilla's CA Bundle.
cffi                   1.15.0    Foreign Function Interface for Python calling C code.
cfgv                   3.3.1     Validate configuration and produce human readable error messages.
charset-normalizer     2.0.12    The Real First Universal Charset Detector. Open, modern and actively maintained alternativ...
click                  8.0.4     Composable command line interface toolkit
colorama               0.4.4     Cross-platform colored terminal text.
commonmark             0.9.1     Python parser for the CommonMark Markdown spec
configobj              5.0.6     Config file reading, writing and validation.
configupdater          3.1       Parser like ConfigParser but for updating configuration files
cryptography           36.0.2    cryptography is a package which provides cryptographic recipes and primitives to Python de...
cycler                 0.11.0    Composable style cycles
dictdiffer             0.9.0     Dictdiffer is a library that helps you to diff and patch dictionaries.
diskcache              5.4.0     Disk Cache -- Disk and file backed persistent cache.
distlib                0.3.4     Distribution utilities
distro                 1.7.0     Distro - an OS platform information API
dpath                  2.0.6     Filesystem-like pathing and searching for dictionaries
dulwich                0.20.35   Python Git Library
dvc                    2.9.5     Git for data scientists - manage your code and data together
filelock               3.6.0     A platform independent file lock.
flake8                 4.0.1     the modular source code checker: pep8 pyflakes and co
flatten-dict           0.4.2     A flexible utility for flattening and unflattening dict-like objects in Python.
flufl.lock             7.0       NFS-safe file locking with timeouts for POSIX and Windows
fonttools              4.31.2    Tools to manipulate font files
frozenlist             1.3.0     A list-like structure which implements collections.abc.MutableSequence
fsspec                 2022.2.0  File-system specification
ftfy                   6.1.1     Fixes mojibake and other problems with Unicode, after the fact
funcy                  1.17      A fancy and practical functional tools
future                 0.18.2    Clean single-source support for Python 3 and 2
gitdb                  4.0.9     Git Object Database
gitpython              3.1.27    GitPython is a python library used to interact with Git repositories
grandalf               0.6       Graph and drawing algorithms framework
hydra-core             1.1.1     A framework for elegantly configuring complex applications
identify               2.4.12    File identification library for Python
idna                   3.3       Internationalized Domain Names in Applications (IDNA)
importlib-resources    5.4.0     Read resources from Python packages
jmespath               1.0.0     JSON Matching Expressions
joblib                 1.1.0     Lightweight pipelining with Python functions
kiwisolver             1.4.0     A fast implementation of the Cassowary constraint solver
loguru                 0.6.0     Python logging made (stupidly) simple
mailchecker            4.1.14    Cross-language email validation. Backed by a database of thousands throwable email providers.
marshmallow            3.15.0    A lightweight library for converting complex datatypes to and from native Python datatypes.
marshmallow-polyfield  5.10      An unofficial extension to Marshmallow to allow for polymorphic fields
matplotlib             3.5.1     Python plotting package
mccabe                 0.6.1     McCabe checker, plugin for flake8
more-itertools         8.12.0    More routines for operating on iterables, beyond itertools
multidict              6.0.2     multidict implementation
nanotime               0.5.2     nanotime python implementation
networkx               2.7.1     Python package for creating and manipulating graphs and networks
nitpick                0.31.0    Enforce the same settings across multiple language-independent projects
nodeenv                1.6.0     Node.js virtual environment builder
numpy                  1.22.3    NumPy is the fundamental package for array computing with Python.
omegaconf              2.1.1     A flexible configuration library
packaging              21.3      Core utilities for Python packages
pandas                 1.4.1     Powerful data structures for data analysis, time series, and statistics
pathspec               0.9.0     Utility library for gitignore style pattern matching of file paths.
phonenumbers           8.12.45   Python version of Google's common library for parsing, formatting, storing and validating ...
pillow                 9.0.1     Python Imaging Library (Fork)
platformdirs           2.5.1     A small Python module for determining appropriate platform-specific dirs, e.g. a "user dat...
pluggy                 1.0.0     plugin and hook calling mechanisms for python
ply                    3.11      Python Lex & Yacc
pre-commit             2.17.0    A framework for managing and maintaining multi-language pre-commit hooks.
psutil                 5.9.0     Cross-platform lib for process and system monitoring in Python.
pyasn1                 0.4.8     ASN.1 types and codecs
pycodestyle            2.8.0     Python style guide checker
pycparser              2.21      C parser in Python
pydot                  1.4.2     Python interface to Graphviz's Dot
pyflakes               2.4.0     passive checker of Python programs
pygit2                 1.9.1     Python bindings for libgit2.
pygments               2.11.2    Pygments is a syntax highlighting package written in Python.
pygtrie                2.4.2     A pure Python trie data structure implementation.
pyparsing              3.0.7     Python parsing module
python-benedict        0.25.0    python-benedict is a dict subclass with keylist/keypath support, normalized I/O operations...
python-dateutil        2.8.2     Extensions to the standard Python datetime module
python-fsutil          0.6.0     file-system utilities for lazy devs.
python-slugify         6.1.1     A Python slugify application that also handles Unicode
pytz                   2022.1    World timezone definitions, modern and historical
pyyaml                 6.0       YAML parser and emitter for Python
requests               2.27.1    Python HTTP for Humans.
rich                   12.0.1    Render rich text, tables, progress bars, syntax highlighting, markdown and more to the ter...
ruamel.yaml            0.17.21   ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq...
ruamel.yaml.clib       0.2.6     C version of reader, parser and emitter for ruamel.yaml derived from libyaml
scikit-learn           1.0.2     A set of python modules for machine learning and data mining
scipy                  1.6.1     SciPy: Scientific Library for Python
scmrepo                0.0.7     SCM wrapper and fsspec filesystem for Git for use in DVC
setuptools-scm         6.4.2     the blessed package to manage your versions by scm tags
shortuuid              1.0.8     A generator library for concise, unambiguous and URL-safe UUIDs.
shtab                  1.5.3     Automagic shell tab completion for Python CLI applications
six                    1.16.0    Python 2 and 3 compatibility utilities
smmap                  5.0.0     A pure Python implementation of a sliding window memory map manager
sortedcontainers       2.4.0     Sorted Containers -- Sorted List, Sorted Dict, Sorted Set
tabulate               0.8.9     Pretty-print tabular data
text-unidecode         1.3       The most basic Text::Unidecode port
threadpoolctl          3.1.0     threadpoolctl
toml                   0.10.2    Python Library for Tom's Obvious, Minimal Language
tomli                  2.0.1     A lil' TOML parser
tomlkit                0.10.0    Style preserving TOML library
tqdm                   4.63.0    Fast, Extensible Progress Meter
typing-extensions      4.1.1     Backported and Experimental Type Hints for Python 3.6+
urllib3                1.26.9    HTTP library with thread-safe connection pooling, file post, and more.
virtualenv             20.13.4   Virtual Python Environment builder
voluptuous             0.12.2    
wcwidth                0.2.5     Measures the displayed width of unicode strings in a terminal
xmltodict              0.12.0    Makes working with XML feel like you are working with JSON
yarl                   1.7.2     Yet another URL library
yellowbrick            1.4       A suite of visual analysis and diagnostic tools for machine learning.
zc.lockfile            2.0       Basic inter-process locks
zipp                   3.7.0     Backport of pathlib-compatible object wrapper for zip files
$ cat $(which flake8)

#!/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
# -*- coding: utf-8 -*-
import re
import sys
from flake8.main.cli import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
@khuyentran1401 khuyentran1401 added the bug Something isn't working label Mar 23, 2022
@andreoliwa
Copy link
Owner

Hey, thanks for the bug report!

TL;DR: the absence of the rev key is actually by design: I don't enforce versions on the built-in styles with pre-commit hooks, because I use https://pre-commit.ci/ for auto-updates on my projects.

Read further below for more details.

Possible solution

This problem should be fixed when #218 will be developed.

  1. Mark the rev key as "should be present" for every pre-commit hook in every built-in style.
  2. Add a default value for each hook as well. It can be the latest tag, or the default branch (master, main, develop... depends on each project).
  3. The developer will be responsible to run pre-commit autoupdate after applying changes with nitpick fix. The built-in styles will only enforce the presence of rev and will not guarantee that the latest tag is being used.

Why the rev key is not set on styles?

I removed all rev keys from the built-in styles because I didn't want to keep updating the styles manually every time a hook got upgraded by https://pre-commit.ci/.

I had to change docs, styles and tests whenever a hook was upgraded. Examples:

It was annoying and there were no auto-updates: I always had to intervene manually.

@khuyentran1401
Copy link
Author

Hi @andreoliwa, thank you for proposing the solutions and for the explanation. I think using numbers 2 and 3 will solve this problem. I didn't know about pre-commit autoupdate until now so it would be nice if you can include that in the documentation

@andreoliwa
Copy link
Owner

I think using numbers 2 and 3 will solve this problem.

Awesome that these items unblock you. 🥳
But I will still keep this bug open until I am (or someone is) able to fix it for good.

I didn't know about pre-commit autoupdate until now so it would be nice if you can include that in the documentation

Good idea, I'll do that. 👍🏻

@AntarktisZ11
Copy link

First of all, great project! Just want to say that I used the following layout

[[".pre-commit-config.yaml".repos]]
repo = "https://github.com/pre-commit/pre-commit-hooks"
rev = "" # run `pre-commit autoupdate`

Which worked well as a placeholder. Not sure if there are any downsides with this though!
If the built-in styles contain that they would work after running pre-commit autoupdate.

@andreoliwa andreoliwa moved this to Upvoted / Requests in Nitpick Roadmap Sep 19, 2022
@valberg
Copy link

valberg commented Jul 3, 2023

Hi y'all!

I'm also running into this issue, and the proposed solution with pre-commit autoupdate does not work in my case:

# nitpick style
[nitpick.files.present]
".pre-commit-config.yaml" = "Create the file with the contents below, then run 'pre-commit install'"

[[".pre-commit-config.yaml".repos]]
repo = "https://github.com/astral-sh/ruff-pre-commit"

[[".pre-commit-config.yaml".repos.hooks]]
id = "ruff"

Trying to run it on a repo without the .pre-commit-config.yaml file

$ nitpick fix
.pre-commit-config.yaml:1: NIP103  should exist: Create the file with the contents below, then run 'pre-commit install'
.pre-commit-config.yaml:1: NIP361  was not found. Create it with this content:
repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    hooks:
      - id: ruff
Violations: ✅ 1 fixed, ❌ 1 to change manually.

$ nitpick fix
No violations found. ✨ 🍰 ✨

$ pre-commit autoupdate
An error has occurred: InvalidConfigError: 
==> File .pre-commit-config.yaml
==> At Config()
==> At key: repos
==> At Repository(repo='https://github.com/astral-sh/ruff-pre-commit')
=====> Missing required key: rev
Check the log at /home/valberg/.cache/pre-commit/pre-commit.log

pre-commit expects there to be a rev key. Or maybe I'm missing something?

@andreoliwa
Copy link
Owner

I'm also running into this issue, and the proposed solution with pre-commit autoupdate does not work in my case:

Maybe it works if you add rev = "master" on your style.

pre-commit expects there to be a rev key. Or maybe I'm missing something?

You're correct.
The problem is that I can't add rev = "master" or rev = "" to the built-in styles.
Otherwise, they will be enforced by Nitpick.

This still depends on #218 being developed first as I mentioned in #472 (comment).
If you see any other solution, let me know.

Not sure if there are any downsides with this though!
If the built-in styles contain that they would work after running pre-commit autoupdate.

@AntarktisZ11 Currently, if the style has rev = "" then Nitpick will enforce it and erase existing revisions. 😕

@andreoliwa
Copy link
Owner

so it would be nice if you can include that in the documentation

I updated the docs: https://nitpick.readthedocs.io/en/latest/troubleshooting.html#missing-rev-key-when-using-the-default-pre-commit-styles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Upvoted / Requests
Development

No branches or pull requests

4 participants