K0nkere / MLOps_Car-prices-project

Covers the most important stages of ML system / Auction car prices prediction model for MLOps-zoomcamp
0 stars 0 forks source link

5.3 Pre-commit hooks #8

Open K0nkere opened 2 years ago

K0nkere commented 2 years ago

Video

!!! на последних 4 минутах показан быстрый последовательный запуск > прогон через pre-commit hooks коммит, снова прогон !!!

Pre-commit python tool

Open needed directory in VSCode Under the pipenv pipenv install --dev pre-commit

In the source folder of git we can find .git/hooks/ > pre-commit.sample - examlpe

!!! Pre-commit hooks are executed from git repo So if we want to run pre-commit hooks for specific folder its need to create a new repo in the needed folder from the needed folder git init pre-commit sample-config > .pre-commit-config.yaml

To change how many spaces == tab Ctrl+Shift+P > indent > indent using whitespaces

ls .git/hooks pre-commit install > pre-commit installed at .git/hooks/pre-commit check this file less .git/hooks/pre-commit

# 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

!!! Лишних отступов через Tab быть не должно - это важно для дальнейшего коммита !!!

K0nkere commented 2 years ago

run git status

Create .gitignore and paste there no needed files git add . - add files to commit git commit -m "..." - pre-commit will check and fix

K0nkere commented 2 years ago

Other Hooks - from .pre-commit-config.yaml

K0nkere commented 2 years ago

Adding pre-commit hooks for isort >

google pre-commit isort

- repo: https://github.com/pycqa/isort
    rev: 5.10.1
    hooks:
      - id: isort
        name: isort (python)

copy it to .pre-commit-config.yaml and format spaces if need

K0nkere commented 2 years ago

Adding pre-commit hooks for black >

google pre-commit black

-   repo: https://github.com/psf/black
    rev: stable
    hooks:
    - id: black
      language_version: python3.9

its need to replace stable with version of black from Pipfile.lock > 22.8.0 copy it to .pre-commit-config.yaml and format spaces if need

K0nkere commented 2 years ago

Adding pre-commit hooks for pylint >

google pre-commit pylint

- repo: local
  hooks:
    - id: pylint
      name: pylint
      entry: pylint
      language: system
      types: [python]
      args:
        [
          "-rn", # Only display messages
          "-sn", # Don't display the score
          "--recursive=y",
        ]

copy it to .pre-commit-config.yaml and format spaces if need

K0nkere commented 2 years ago

Pre-commit hook for pytest >

google pre-commit pytest

  - repo: local
    hooks:
      - id: pytest-check
        name: pytest-check
        entry: pytest
        language: system
        pass_filenames: false
        always_run: true
        args: [
           "tests/"
        ]

copy it to .pre-commit-config.yaml and format spaces if need

K0nkere commented 2 years ago

After that we can run again git add <filenames> - add files to commit git commit -m "..." - pre-commit will check and fix and automaticly run the tests from tests/ folder