Skip to content

Add pre commit with ruff - #298

Open
Medno wants to merge 13 commits into
fhamborg:masterfrom
Medno:add_pre_commit_with_ruff
Open

Medno wants to merge 13 commits into
fhamborg:masterfrom
Medno:add_pre_commit_with_ruff

Conversation

@Medno

@Medno Medno commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Context

The package currently lacks consistency due to a heterogeneous coding style.

Several tools are available to improve code consistency and readability, including linters and formatters. Among them, ruff has recently gained significant popularity thanks to its speed and broad feature set. It is a compelling alternative to black, while also providing linting and formatting capabilities.

Running the linter also highlighted several compatibility layers intended to support both Python 2 and Python 3. Since Python 2 is no longer supported by the project, this PR removes these legacy compatibility patterns.

Proposed changes

Added a pre-commit configuration

  • Added ruff check and ruff format hooks.
  • Added pre-commit to extras_require in setup.py.

Applied ruff to the codebase

  • The largest part of the diff is the formatting-only commit: 922c1e8. This commit does not introduce any functional changes.

    • Added a .git-blame-ignore-revs file so that git blame can ignore this formatting commit and keep the history easier to navigate.
  • Applied several PEP 8 recommendations:

    • Reordered imports.
    • Replaced bare except: statements with explicit except Exception:.
    • Replaced != None with is not None.

Removed legacy Python 2 compatibility

⚠️ While no functional changes are intended, removing Python 2 compatibility may introduce minor behavioral differences in edge cases. This PR removes several compatibility patterns that are no longer needed:

  • Removed try ... except ImportError patterns used to support both Python 2 and Python 3 imports (e.g. urllib.parse).
  • Removed the six dependency and replaced its usage with native Python 3 features.

How to test

Run the configured pre-commit hooks:

source .venv/bin/activate
pre-commit run --all-files

Comment on lines +12 to -18
import urllib.parse

from ago import human
import boto3
import botocore
from dateutil import parser
from hurry.filesize import size
from scrapy.utils.log import configure_logging
from six.moves import urllib

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example of six package replacement by urllib.parse

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant