Skip to content

Commit

Permalink
Switch from pylint to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
rkhwaja committed Sep 29, 2023
1 parent 05c172b commit b05e6c5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 48 deletions.
45 changes: 12 additions & 33 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,53 +33,32 @@ aiohttp = ">=3.8.1"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.1"
pylint = ">=2.13"
wrapt = ">=1.4.0" # should have been a dependency of pylint
pylint-quotes = ">=0.2.1"
pytest-cov = ">=2.10.1"
pytest-asyncio = ">=0.16.0"
poethepoet = ">=0.16.4"
ruff = ">=0.0.289"

[tool.poe.tasks]
lint = "pylint src/wccls tests"
lint = "ruff src tests"

[tool.poe.tasks.test]
shell = """
pytest --cov=src/wccls || exit 1
coverage xml
"""

[tool.pylint.master]
load-plugins = [
"pylint_quotes",
"pylint.extensions.code_style",
"pylint.extensions.confusing_elif",
"pylint.extensions.bad_builtin",
"pylint.extensions.mccabe",
"pylint.extensions.check_elif",
"pylint.extensions.redefined_variable_type",
"pylint.extensions.overlapping_exceptions",
"pylint.extensions.empty_comment",
"pylint.extensions.set_membership",
# "pylint.extensions.while_used",
]
enable="useless-suppression"
[tool.ruff]
line-length = 200
ignore = ["A003", "ANN", "B011", "D", "DTZ", "EM", "FBT003", "FIX002", "I", "N", "PT013", "PT015", "PTH123", "S101", "TCH", "TD", "TRY003", "W191"]
select = ["ALL"]

[tool.pylint.format]
indent-string = "\t"
string-quote = "single-avoid-escape"
triple-quote = "single"
[tool.ruff.extend-per-file-ignores]
"__init__.py" = ["F403"]
"tests/*" = ["INP001"]

[tool.pylint.messages_control]
disable = [
"consider-using-assignment-expr",
"fixme",
"invalid-name",
"line-too-long",
"missing-docstring",
"too-few-public-methods",
"too-many-arguments"
]
[tool.ruff.flake8-quotes]
inline-quotes = "single"
multiline-quotes = "single"

[tool.pytest.ini_options]
pythonpath = ["src"]
14 changes: 7 additions & 7 deletions src/wccls/bibliocommons.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations

from aiohttp import ClientSession
from requests import Session
Expand All @@ -25,7 +25,7 @@ async def _DoRequestAsync(session, request):
return await resp.text()
assert False, f'Unexpected request: {request}'

def BiblioCommons(subdomain: str, login: str, password: str) -> List[Item]:
def BiblioCommons(subdomain: str, login: str, password: str) -> list[Item]:
"""Gets the list of items for a Bibliocommons site"""
parser = Parser(subdomain, login, password)
with Session() as session:
Expand All @@ -36,7 +36,7 @@ def BiblioCommons(subdomain: str, login: str, password: str) -> List[Item]:
reqs.extend(parser.Receive(req.url, resp))
return parser.items

async def BiblioCommonsAsync(subdomain: str, login: str, password: str) -> List[Item]:
async def BiblioCommonsAsync(subdomain: str, login: str, password: str) -> list[Item]:
"""Gets the list of items for a Bibliocommons site"""
parser = Parser(subdomain, login, password)
async with ClientSession() as session:
Expand All @@ -47,18 +47,18 @@ async def BiblioCommonsAsync(subdomain: str, login: str, password: str) -> List[
reqs.extend(parser.Receive(req.url, response))
return parser.items

def Wccls(login: str, password: str) -> List[Item]:
def Wccls(login: str, password: str) -> list[Item]:
"""Gets the list of items for the WCCLS site"""
return BiblioCommons('wccls', login, password)

def MultCoLib(login: str, password: str) -> List[Item]:
def MultCoLib(login: str, password: str) -> list[Item]:
"""Gets the list of items for the Multnomah County Library site"""
return BiblioCommons('multcolib', login, password)

async def WcclsAsync(login: str, password: str) -> List[Item]:
async def WcclsAsync(login: str, password: str) -> list[Item]:
"""Gets the list of items for the WCCLS site"""
return await BiblioCommonsAsync('wccls', login, password)

async def MultCoLibAsync(login: str, password: str) -> List[Item]:
async def MultCoLibAsync(login: str, password: str) -> list[Item]:
"""Gets the list of items for the Multnomah County Library site"""
return await BiblioCommonsAsync('multcolib', login, password)
2 changes: 1 addition & 1 deletion src/wccls/item_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ParseError(Exception):
StatusType = Enum('StatusType', [])

def _AddStatusType(name):
global StatusType # pylint: disable=global-statement
global StatusType # noqa: PLW0603
names = [x.name for x in StatusType]
names.append(name)
StatusType = Enum('StatusType', names)
Expand Down
6 changes: 2 additions & 4 deletions src/wccls/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def _ProcessLogin(self, response):

def _ProcessItems(self, ParseFunction, response):
soup = _MakeSoup(response)
result = []
for listItem in soup.find_all(class_='item-row'):
result.append(ParseFunction(listItem))
result = [ParseFunction(item) for item in soup.find_all(class_='item-row')]
# Make sure the whole parse works before adding items
self.items.extend(result)
return []
Expand Down Expand Up @@ -162,7 +160,7 @@ def _ParseFormatInfo(element):
'DVD': FormatType.DVD,
'Blu-ray Disc': FormatType.BluRay,
'Graphic Novel': FormatType.GraphicNovel,
'3D Object': FormatType.Object3D
'3D Object': FormatType.Object3D,
}
return formatLookup[formatIndicator.text]

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def pytest_addoption(parser):
parser.addoption('--collect', action='store', default='test', help=f'Valid options are {",".join(_COLLECT_OPTIONS)}')

@fixture
@fixture()
def collect(request):
value = request.config.getoption('--collect')
if value not in _COLLECT_OPTIONS:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def default(self, o):
return o.isoformat()
if isinstance(o, Item):
return asdict(o) | {'status': str(o.status)}
if isinstance(o, FormatType): # pylint: disable=isinstance-second-argument-not-valid-type
if isinstance(o, FormatType):
return str(o)
return super().default(o)

Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(self, subdomain, fileset, login, password):

def _DoRequest(self, request):
path = self._rootPath / FilenameFromRequest(request)
with open(path, 'r', encoding='utf-8') as f:
with open(path, encoding='utf-8') as f:
return f.read()

class SaveToFileWrapper(BaseWrapper):
Expand Down

0 comments on commit b05e6c5

Please sign in to comment.