Skip to content

Commit

Permalink
Merge pull request #85 from emarondan/adding-pre-commit
Browse files Browse the repository at this point in the history
Adding pre commit
  • Loading branch information
Gallaecio committed May 16, 2024
2 parents e710124 + ad1bb4f commit 02c72ad
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 59 deletions.
6 changes: 6 additions & 0 deletions .bandit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
skips:
- B101
- B311
- B320
- B410
exclude_dirs: ['tests']
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# applying pre-commit hooks to the project
106a4e0af9e9ac07defef3c9a781d2fe0ac4640f
17 changes: 7 additions & 10 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,10 @@ jobs:
include:
- python-version: 3.12
env:
TOXENV: black
- python-version: 3.12
env:
TOXENV: bandit
- python-version: 3.12
env:
TOXENV: flake8
TOXENV: pylint
- python-version: 3.12
env:
TOXENV: typing
- python-version: 3.12
env:
TOXENV: pylint
- python-version: 3.12
env:
TOXENV: twinecheck
Expand All @@ -41,3 +32,9 @@ jobs:
pip install -U pip
pip install -U tox
tox
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pre-commit/action@v3.0.0
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile = black
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/PyCQA/bandit
rev: 1.7.8
hooks:
- id: bandit
args: [-r, -c, .bandit.yml]
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/psf/black.git
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
1 change: 0 additions & 1 deletion itemadapter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .adapter import ItemAdapter # noqa: F401
from .utils import get_field_meta_from_class, is_item # noqa: F401


__version__ = "0.9.0"
8 changes: 3 additions & 5 deletions itemadapter/adapter.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import dataclasses
from abc import abstractmethod, ABCMeta
from abc import ABCMeta, abstractmethod
from collections import deque
from collections.abc import KeysView, MutableMapping
from types import MappingProxyType
from typing import Any, Iterable, Iterator, Type, Optional, List
from typing import Any, Iterable, Iterator, List, Optional, Type

from itemadapter._imports import _scrapy_item_classes, attr
from itemadapter.utils import (
_get_pydantic_model_metadata,
_is_attrs_class,
_is_pydantic_model,
)

from itemadapter._imports import attr, _scrapy_item_classes


__all__ = [
"AdapterInterface",
"AttrsAdapter",
Expand Down
2 changes: 0 additions & 2 deletions itemadapter/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import warnings

from types import MappingProxyType
from typing import Any

from itemadapter._imports import attr, pydantic


__all__ = ["is_item", "get_field_meta_from_class"]


Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import setuptools


with open("README.md", "r") as fh:
long_description = fh.read()

Expand Down
6 changes: 4 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class AttrsItemEmpty:


try:
from pydantic import BaseModel, Field as PydanticField
from pydantic import BaseModel
from pydantic import Field as PydanticField
except ImportError:
PydanticModel = None
PydanticSpecialCasesModel = None
Expand Down Expand Up @@ -153,7 +154,8 @@ class PydanticModelEmpty(BaseModel):


try:
from scrapy.item import Item as ScrapyItem, Field
from scrapy.item import Field
from scrapy.item import Item as ScrapyItem
except ImportError:
ScrapyItem = None
ScrapySubclassedItem = None
Expand Down
13 changes: 6 additions & 7 deletions tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
from typing import KeysView

from itemadapter.adapter import ItemAdapter

from tests import (
AttrsItem,
AttrsItemEmpty,
AttrsItemNested,
AttrsItemWithoutInit,
AttrsItemSubclassed,
AttrsItemEmpty,
AttrsItemWithoutInit,
DataClassItem,
DataClassItemEmpty,
DataClassItemNested,
DataClassWithoutInit,
DataClassItemSubclassed,
DataClassItemEmpty,
DataClassWithoutInit,
PydanticModel,
PydanticModelEmpty,
PydanticModelNested,
PydanticModelSubclassed,
PydanticModelEmpty,
ScrapySubclassedItem,
ScrapySubclassedItemEmpty,
ScrapySubclassedItemNested,
ScrapySubclassedItemSubclassed,
ScrapySubclassedItemEmpty,
)


Expand Down
3 changes: 1 addition & 2 deletions tests/test_adapter_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
from unittest import mock

from itemadapter.utils import get_field_meta_from_class

from tests import (
AttrsItem,
DataClassItem,
PydanticModel,
ScrapyItem,
ScrapySubclassedItem,
make_mock_import,
clear_itemadapter_imports,
make_mock_import,
)


Expand Down
1 change: 0 additions & 1 deletion tests/test_adapter_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from unittest import TestCase

from itemadapter.utils import get_field_meta_from_class

from tests import (
AttrsItem,
DataClassItem,
Expand Down
3 changes: 1 addition & 2 deletions tests/test_adapter_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
from unittest import mock

from itemadapter.utils import get_field_meta_from_class

from tests import (
AttrsItem,
DataClassItem,
PydanticModel,
PydanticSpecialCasesModel,
ScrapyItem,
ScrapySubclassedItem,
make_mock_import,
clear_itemadapter_imports,
make_mock_import,
)


Expand Down
3 changes: 1 addition & 2 deletions tests/test_adapter_scrapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
from unittest import mock

from itemadapter.utils import get_field_meta_from_class

from tests import (
AttrsItem,
DataClassItem,
PydanticModel,
ScrapyItem,
ScrapySubclassedItem,
make_mock_import,
clear_itemadapter_imports,
make_mock_import,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_itemadapter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from itemadapter.adapter import ItemAdapter, DictAdapter
from itemadapter.adapter import DictAdapter, ItemAdapter


class DictOnlyItemAdapter(ItemAdapter):
Expand Down
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from itemadapter import ItemAdapter
from itemadapter.utils import get_field_meta_from_class, is_item

from tests import (
AttrsItem,
DataClassItem,
Expand Down
28 changes: 6 additions & 22 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = bandit,flake8,typing,black,py,py38-scrapy22,pylint
envlist = typing,py,py38-scrapy22,pylint,pre-commit,twinecheck

[testenv]
deps =
Expand All @@ -8,20 +8,6 @@ deps =
commands =
pytest --verbose --cov=itemadapter --cov-report=term-missing --cov-report=html --cov-report=xml --doctest-glob=README.md {posargs: itemadapter README.md tests}

[testenv:bandit]
basepython = python3
deps =
bandit
commands =
bandit -r {posargs:itemadapter}

[testenv:flake8]
basepython = python3
deps =
flake8==7.0.0
commands =
flake8 --exclude=.git,.tox,venv* {posargs:itemadapter tests}

[testenv:typing]
basepython = python3
deps =
Expand All @@ -33,13 +19,6 @@ commands =
mypy --install-types --non-interactive \
--ignore-missing-imports {posargs:itemadapter}

[testenv:black]
basepython = python3
deps =
black==24.4.2
commands =
black --check {posargs:itemadapter tests}

[testenv:pylint]
deps =
pylint==3.1.0
Expand All @@ -54,3 +33,8 @@ deps =
commands =
python -m build --sdist
twine check dist/*

[testenv:pre-commit]
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure
skip_install = true

0 comments on commit 02c72ad

Please sign in to comment.