Skip to content

Commit

Permalink
fix: pre-commits v4 language:python_venv not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
hadialqattan committed Jan 6, 2025
1 parent d0aeb62 commit 42785a0
Show file tree
Hide file tree
Showing 30 changed files with 106 additions and 126 deletions.
49 changes: 26 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
exclude: "vendor/"

repos:
- repo: https://github.com/hadialqattan/pycln
rev: v2.3.0 # Possible releases: https://github.com/hadialqattan/pycln/releases
hooks:
- id: pycln
args: [--config=pyproject.toml]
# - repo: https://github.com/hadialqattan/pycln
# rev: v2.4.0 # Possible releases: https://github.com/hadialqattan/pycln/releases
# hooks:
# - id: pycln
# args: [--config=pyproject.toml]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v5.0.0
hooks:
- id: check-toml
- id: check-yaml
Expand All @@ -26,51 +26,54 @@ repos:
- id: check-executables-have-shebangs

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.1
rev: v4.0.0-alpha.8
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/pycqa/isort
rev: 5.11.5
rev: 5.13.2
hooks:
- id: isort
files: "\\.(py)$"
args: [--settings-path=pyproject.toml]

- repo: https://github.com/myint/docformatter
rev: v1.4
hooks:
- id: docformatter
args: [--in-place]
# - repo: https://github.com/myint/docformatter
# rev: v1.4
# hooks:
# - id: docformatter
# args: [--in-place]

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.10.0
hooks:
- id: black
args: [--config=pyproject.toml]

- repo: https://github.com/pycqa/flake8
rev: "3.9.2"
rev: "7.1.1"
hooks:
- id: flake8
additional_dependencies: [pep8-naming]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782 # Do not update.
hooks:
- id: mypy
exclude: tests/data/
args: [--config-file=pyproject.toml]
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.14.1
# hooks:
# - id: mypy
# additional_dependencies:
# - types-requests==2.32.0.20241016
# - types-PyYAML==6.0.12.20241230
# exclude: tests/data/
# args: [--config-file=pyproject.toml]

- repo: https://github.com/pre-commit/mirrors-pylint
rev: v3.0.0a4
rev: v3.0.0a5
hooks:
- id: pylint
args: [--rcfile=.pylintrc]
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
8 changes: 4 additions & 4 deletions pycln/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
PYPROJECT_PATH = Path(__file__).parent.parent.joinpath("pyproject.toml")

with tokenize.open(PYPROJECT_PATH) as toml_f:
pycln = tomlkit.parse(toml_f.read())["tool"]["poetry"] # type: ignore[index]
pycln = tomlkit.parse(toml_f.read())["tool"]["poetry"]

__name__ = str(pycln["name"]) # type: ignore[index]
__doc__ = str(pycln["description"]) # type: ignore[index]
__version__ = pycln["version"] # type: ignore[index]
__name__ = str(pycln["name"])
__doc__ = str(pycln["description"])
__version__ = pycln["version"]


def version_callback(value: bool):
Expand Down
1 change: 1 addition & 0 deletions pycln/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Entry point to run Pycln as a module."""

from . import __name__
from .cli import app

Expand Down
9 changes: 5 additions & 4 deletions pycln/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pycln CLI implementation."""

from pathlib import Path
from typing import Generator, List, Optional

Expand Down Expand Up @@ -168,9 +169,9 @@ def main( # pylint: disable=R0913,R0914
paths=paths,
skip_imports=set(skip_imports),
config=config,
include=include, # type: ignore
exclude=exclude, # type: ignore
extend_exclude=extend_exclude, # type: ignore
include=include,
exclude=exclude,
extend_exclude=extend_exclude,
all_=all_,
check=check,
diff=diff,
Expand All @@ -190,7 +191,7 @@ def main( # pylint: disable=R0913,R0914
gitignore = regexu.get_gitignore(
path if path.is_dir() else path.parent, configs.no_gitignore
)
sources: Generator = pathu.yield_sources( # type: ignore
sources: Generator = pathu.yield_sources(
path,
configs.include,
configs.exclude,
Expand Down
12 changes: 3 additions & 9 deletions pycln/utils/_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Pycln custom exceptions utility."""

from pathlib import Path
from typing import Union

from ._nodes import NodeLocation


class BaseOSError(Exception):

"""Custom OSError."""

def __init__(self, errno: int, strerror: str, filepath: Path):
Expand All @@ -15,23 +15,19 @@ def __init__(self, errno: int, strerror: str, filepath: Path):


class ReadPermissionError(BaseOSError):

"""Raises when the file does not have read permission."""


class WritePermissionError(BaseOSError):

"""Raises when the file does not have write permission."""


class InitFileDoesNotExistError(BaseOSError):

"""Raises when an `__init__.py` file path encountered of a non-existing
path."""


class UnexpandableImportStar(Exception):

"""Raises when the import `*` statement unexpandable."""

def __init__(self, path: Path, location: NodeLocation, msg: str):
Expand All @@ -41,7 +37,6 @@ def __init__(self, path: Path, location: NodeLocation, msg: str):


class UnparsableFile(Exception):

"""Raises when the compiled source code is invalid, or the source code
contains null bytes."""

Expand All @@ -56,7 +51,7 @@ def __init__(
UnparsableFile._type_check(type_)

if type_ in {SyntaxError, IndentationError}:
lineno, col, text = err.lineno, err.offset, err.text # type: ignore
lineno, col, text = err.lineno, err.offset, err.text
if lineno:
location = f"{path}:{lineno}:{col}"
if text:
Expand All @@ -66,7 +61,7 @@ def __init__(
elif type_ == ValueError:
setattr(err, "msg", str(err))

msg = err.msg # type: ignore
msg = err.msg
message = f"{location} {type_.__name__}: {msg}{postfix}"
super().__init__(message)

Expand All @@ -86,7 +81,6 @@ def _type_check(type_: type) -> None:


class UnsupportedCase(Exception):

"""Raises when unsupported import case detected."""

def __init__(self, path: Path, location: NodeLocation, msg: str):
Expand Down
6 changes: 1 addition & 5 deletions pycln/utils/_nodes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Pycln import statements nodes utility."""

import ast
from dataclasses import dataclass
from typing import List, Optional, Tuple


@dataclass(frozen=True)
class NodePosition:

"""Node position class."""

#: Line numbers are 1-indexed.
Expand All @@ -23,7 +23,6 @@ def __hash__(self):

@dataclass
class NodeLocation:

"""Node location class.
:param start: tuple of start line and col_offset.
Expand All @@ -43,7 +42,6 @@ def __len__(self):

@dataclass
class BaseImport:

"""Custom `ast.AST` node."""

#: Location contains:
Expand All @@ -60,7 +58,6 @@ class BaseImport:

@dataclass
class Import(BaseImport):

"""Custom `ast.Import` node."""

def __hash__(self):
Expand All @@ -69,7 +66,6 @@ def __hash__(self):

@dataclass
class ImportFrom(BaseImport):

"""Custom `ast.ImportFrom` node."""

#: `ast.ImportFrom.module`.
Expand Down
15 changes: 6 additions & 9 deletions pycln/utils/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pycln configuration management utility."""

import configparser
import json
import tokenize
Expand All @@ -24,7 +25,6 @@

@dataclass
class Config:

"""Pycln configs dataclass."""

def __post_init__(self):
Expand All @@ -41,9 +41,9 @@ def __post_init__(self):
paths: List[Path]
skip_imports: Set[str]
config: Optional[Path] = None
include: Pattern[str] = regexu.INCLUDE_REGEX # type: ignore
exclude: Pattern[str] = regexu.EXCLUDE_REGEX # type: ignore
extend_exclude: Pattern[str] = regexu.EMPTY_REGEX # type: ignore
include: Pattern[str] = regexu.INCLUDE_REGEX
exclude: Pattern[str] = regexu.EXCLUDE_REGEX
extend_exclude: Pattern[str] = regexu.EMPTY_REGEX
all_: bool = False
check: bool = False
diff: bool = False
Expand Down Expand Up @@ -112,7 +112,6 @@ def _check_regex(self) -> None:


class ParseConfigFile:

"""Conifg file parser.
:param file_path: config file path.
Expand Down Expand Up @@ -154,7 +153,7 @@ def _parse_cfg(self) -> None:
# Parse `.cfg` file.
parser = configparser.ConfigParser(allow_no_value=True)
parser.read(self._path)
cfg_data = parser._sections.get(self._section, {}) # type: ignore
cfg_data = parser._sections.get(self._section, {})

def cast_bool(v: str) -> Union[str, bool]:
if v.lower() == "true":
Expand All @@ -171,9 +170,7 @@ def cast_bool(v: str) -> Union[str, bool]:
#: skip_imports = [x, y]
#: skip_imports = x,y
skip_imports = configs["skip_imports"]
skip_imports = set(
skip_imports.strip('[]"').replace(" ", "").split(",") # type: ignore
)
skip_imports = set(skip_imports.strip('[]"').replace(" ", "").split(","))
configs["skip_imports"] = skip_imports

self._config_loader(configs)
Expand Down
1 change: 1 addition & 0 deletions pycln/utils/iou.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pycln file IO utility."""

import io
import os
import sys
Expand Down
9 changes: 5 additions & 4 deletions pycln/utils/pathu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pycln path finding utility."""

import os
import sys
import sysconfig
Expand Down Expand Up @@ -73,9 +74,9 @@ def yield_sources(
is_included, is_excluded = regexu.is_included, regexu.is_excluded

if path.is_dir():
root_dir = os.scandir(path) # type: ignore
root_dir = os.scandir(path)
else:
root_dir = {path} # type: ignore
root_dir = {path}
path = path.parent

for entry in root_dir:
Expand Down Expand Up @@ -215,7 +216,7 @@ def get_local_import_path(path: Path, module: str) -> Optional[Path]:
names = module.split(".")

# Test different levels.
for i in [None] + list(range(-10, -0)): # type: ignore
for i in [None] + list(range(-10, -0)):
# If it's a file.
fpath = os.path.join(*dirnames[:i], *names[:-1], f"{names[-1]}{PY_EXTENSION}")
if os.path.isfile(fpath):
Expand Down Expand Up @@ -267,7 +268,7 @@ def get_local_import_from_path(
packages = package.split(".") if package else []

# Test different levels.
for i in [None] + list(range(-10, -0)): # type: ignore
for i in [None] + list(range(-10, -0)):
# If it's a file.
if modules:
fpath = os.path.join(
Expand Down
Loading

0 comments on commit 42785a0

Please sign in to comment.