简体   繁体   中英

Pre Commit Run Failing

Whenever I am trying to run pre-commit run is failing.I am getting errors in flake8,black,end of file,Validate filenames,and trailling white spaces .My python code is

from __future__ import annotations


def hopkinsons_law(
    magnetomotiveforce:float, flux:float, reluctance:float) -> dict[str, float]:
    """
    Apply Hopkinson's Law, on any two given electrical values, which can be magnetomotive
    force, flux, and reluctance, and then in a Python dict return name/value pair of the
    zero value.

    >>> hopkinsons_law(magnetomotiveforce=10, flux=5, reluctance=0)
    {'reluctance': 2.0}
    >>> hopkinsons_law(magnetomotiveforce=0, flux=0, reluctance=10)
    Traceback (most recent call last):
      ...
    ValueError: One and only one argument must be 0
    >>> hopkinsons_law(magnetomotiveforce=0, flux=1, reluctance=-2)
    Traceback (most recent call last):
      ...
    ValueError: Reluctance cannot be negative
    >>> hopkinsons_law(reluctance=0, magnetomotiveforce=-10, flux=1)
    {'reluctance': -10.0}
    >>> hopkinsons_law(magnetomotiveforce=0, flux=-1.5, reluctance=2)
    {'magnetomotiveforce': -3.0}
    """
    if (magnetomotiveforce, flux, reluctance).count(0) != 1:
        raise ValueError("One and only one argument must be 0")
    if reluctance < 0:
        raise ValueError("Reluctance cannot be negative")
    if magnetomotiveforce == 0:
        return {"magnetomotiveforce": float(flux * reluctance)}
    elif flux == 0:
        return {"flux": magnetomotiveforce / reluctance}
    elif reluctance == 0:
        return {"reluctance": magnetomotiveforce / flux}
    else:
        raise ValueError("Exactly one argument must be 0")


if __name__ == "__main__":
    import doctest

    doctest.testmod()

And i am getting the following errors

check that executables have shebangs.....................................Passed
check yaml...........................................(no files to check)Skipped
fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Fixing electronics/hopkinsons_law.py

trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook

Fixing electronics/hopkinsons_law.py

fix requirements.txt.................................(no files to check)Skipped
black....................................................................Failed
- hook id: black
- files were modified by this hook

reformatted electronics\hopkinsons_law.py

All done! \u2728 \U0001f370 \u2728
1 file reformatted.

isort....................................................................Passed
pyupgrade................................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

electronics/hopkinsons_law.py:9:89: E501 line too long (89 > 88 characters)

mypy.....................................................................Passed
codespell................................................................Passed
Validate filenames.......................................................Failed
- hook id: validate-filenames
- exit code: 1

Executable `python3` not found

[WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes...
[INFO] Restored changes from C:\Users\rehan\.cache\pre-commit\patch1664778171-18976.

Also I am not allow to change any thing in .pre-commit-config.yaml file Also I have tried adding space between lines and removing space between commas but none of them have worked

pre-commit didn't actually apply the fixes because

[WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes...

(In addition, one of the configured hooks won't work on Windows because it apparently expects a python3 executable.)

Anyway, to help you fix things:

  • black: The file disagrees with the black autoformatter. Run black on your file.
  • flake8: It's saying line 9 is too long. That's the docstring. Reformat the docstring.

These two will probably be automatically fixed by black :

  • end-of-file: You need a newline at the end of the file.
  • trailing-whitespace: There are lines with trailing whitespace. Get rid of the trailing whitespaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM