Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ruff #313

Merged
merged 7 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .bandit.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .bumpversion.cfg

This file was deleted.

6 changes: 0 additions & 6 deletions .coveragerc

This file was deleted.

15 changes: 0 additions & 15 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
tox

- name: Upload coverage report
run: bash <(curl -s https://codecov.io/bash)
uses: codecov/codecov-action@v5
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

21 changes: 5 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
repos:
- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
hooks:
- id: bandit
args: [-r, -c, .bandit.yml]
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
- repo: https://github.com/psf/black.git
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- id: ruff
args: [ --fix ]
- id: ruff-format
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python

import os
import sys
from pathlib import Path

# Get the project root dir, which is the parent dir of this
cwd = os.getcwd()
project_root = os.path.dirname(cwd)
project_root = str(Path.cwd().parent)

# Insert the project root dir as the first element in the PYTHONPATH.
# This lets us ensure that the source package is imported, and that its
Expand Down
7 changes: 3 additions & 4 deletions docs/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from doctest import ELLIPSIS, NORMALIZE_WHITESPACE
from pathlib import Path

from sybil import Sybil

Expand All @@ -16,9 +16,8 @@


def load_selector(filename, **kwargs):
input_path = os.path.join(os.path.dirname(__file__), "_static", filename)
with open(input_path, encoding="utf-8") as input_file:
return Selector(text=input_file.read(), **kwargs)
input_path = Path(__file__).parent / "_static" / filename
return Selector(text=input_path.read_text(encoding="utf-8"), **kwargs)


def setup(namespace):
Expand Down
6 changes: 3 additions & 3 deletions parsel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"xpathfuncs",
]

from parsel import xpathfuncs # NOQA
from parsel.csstranslator import css2xpath # NOQA
from parsel.selector import Selector, SelectorList # NOQA
from parsel import xpathfuncs
from parsel.csstranslator import css2xpath
from parsel.selector import Selector, SelectorList

xpathfuncs.setup()
17 changes: 9 additions & 8 deletions parsel/csstranslator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from functools import lru_cache
from typing import TYPE_CHECKING, Any, Optional, Protocol
from typing import TYPE_CHECKING, Any, Protocol

from cssselect import GenericTranslator as OriginalGenericTranslator
from cssselect import HTMLTranslator as OriginalHTMLTranslator
Expand All @@ -13,17 +15,16 @@


class XPathExpr(OriginalXPathExpr):

textnode: bool = False
attribute: Optional[str] = None
attribute: str | None = None

@classmethod
def from_xpath(
cls,
xpath: OriginalXPathExpr,
textnode: bool = False,
attribute: Optional[str] = None,
) -> "Self":
attribute: str | None = None,
) -> Self:
x = cls(path=xpath.path, element=xpath.element, condition=xpath.condition)
x.textnode = textnode
x.attribute = attribute
Expand All @@ -47,12 +48,12 @@ def __str__(self) -> str:
return path

def join(
self: "Self",
self: Self,
combiner: str,
other: OriginalXPathExpr,
*args: Any,
**kwargs: Any,
) -> "Self":
) -> Self:
if not isinstance(other, XPathExpr):
raise ValueError(
f"Expressions of type {__name__}.XPathExpr can ony join expressions"
Expand Down Expand Up @@ -141,5 +142,5 @@ def css_to_xpath(self, css: str, prefix: str = "descendant-or-self::") -> str:


def css2xpath(query: str) -> str:
"Return translated XPath version of a given CSS query"
"""Return translated XPath version of a given CSS query"""
return _translator.css_to_xpath(query)
Loading