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

Replace Flake8 with Ruff #157

Merged
merged 4 commits into from
Nov 21, 2023
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
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

3 changes: 2 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ pre-commit run --all-files # to run on all files now

## Docstrings

Follow [Google style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
Follow
[Google style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
for docstrings.

## Localization
Expand Down
5 changes: 4 additions & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

Please include **code** that reproduces the issue.

The [best reproductions](https://stackoverflow.com/help/minimal-reproducible-example) are [self-contained scripts](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) with minimal dependencies.
The [best reproductions](https://stackoverflow.com/help/minimal-reproducible-example)
are
[self-contained scripts](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)
with minimal dependencies.

```python
code goes here
Expand Down
4 changes: 2 additions & 2 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Security policy

Security reports can be made via [Tidelift](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure.
Security reports can be made via [Tidelift](https://tidelift.com/security). Tidelift
will coordinate the fix and disclosure.
4 changes: 4 additions & 0 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: Sync labels

permissions:
pull-requests: write

on:
push:
branches:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ name: Lint

on: [push, pull_request, workflow_dispatch]

env:
FORCE_COLOR: 1

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
allow-prereleases: true
cache: pip


- name: Install Linux dependencies
if: startsWith(matrix.os, 'ubuntu')
run: |
Expand Down
64 changes: 22 additions & 42 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,24 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.14.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: pyupgrade
args: [--py38-plus]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
rev: 23.11.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: [--add-import=from __future__ import annotations]

- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
name: autoflake
args:
[
"--in-place",
"--remove-unused-variables",
"--remove-all-unused-imports",
]
language: python
files: \.py$

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-no-log-warn

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: \.github/ISSUE_TEMPLATE\.md|\.github/PULL_REQUEST_TEMPLATE\.md
Expand All @@ -63,20 +31,20 @@ repos:
files: "src/"

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.7.0
hooks:
- id: mypy
additional_dependencies: [pytest, types-freezegun, types-setuptools]
args: [--strict, --pretty, --show-error-codes]

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.2.0
rev: 1.5.1
hooks:
- id: pyproject-fmt
additional_dependencies: [tox]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.14
rev: v0.15
hooks:
- id: validate-pyproject

Expand All @@ -85,5 +53,17 @@ repos:
hooks:
- id: tox-ini-fmt

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
exclude: \.github/ISSUE_TEMPLATE\.md|\.github/PULL_REQUEST_TEMPLATE\.md

- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

ci:
autoupdate_schedule: quarterly
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
[![MIT License](https://img.shields.io/github/license/python-humanize/humanize.svg)](LICENCE)
[![Tidelift](https://tidelift.com/badges/package/pypi/humanize)](https://tidelift.com/subscription/pkg/pypi-humanize?utm_source=pypi-humanize&utm_medium=badge)

This modest package contains various common humanization utilities, like turning
a number into a fuzzy human-readable duration ("3 minutes ago") or into a
human-readable size or throughput. It is localized to:
This modest package contains various common humanization utilities, like turning a
number into a fuzzy human-readable duration ("3 minutes ago") or into a human-readable
size or throughput. It is localized to:

- Arabic
- Basque
Expand Down
24 changes: 13 additions & 11 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Release Checklist

- [ ] Get `main` to the appropriate code release state.
[GitHub Actions](https://github.com/python-humanize/humanize/actions) should be running
cleanly for all merges to `main`.
[GitHub Actions](https://github.com/python-humanize/humanize/actions) should be
running cleanly for all merges to `main`.
[![GitHub Actions status](https://github.com/python-humanize/humanize/workflows/Test/badge.svg)](https://github.com/python-humanize/humanize/actions)

* [ ] Start from a freshly cloned repo:
Expand All @@ -16,7 +16,7 @@ cd humanize
scripts/generate-translation-binaries.sh
```

* [ ] (Optional) Create a distribution and release on **TestPyPI**:
- [ ] (Optional) Create a distribution and release on **TestPyPI**:

```bash
pip install -U pip build keyring twine
Expand All @@ -33,13 +33,13 @@ pip3 install -U -i https://test.pypi.org/simple/ humanize --pre
python3 -c "import humanize; print(humanize.__version__)"
```

* [ ] Tag with the version number:
- [ ] Tag with the version number:

```bash
git tag -a 2.1.0 -m "Release 2.1.0"
```

* [ ] Create a distribution and release on **live PyPI**:
- [ ] Create a distribution and release on **live PyPI**:

```bash
pip install -U pip build keyring twine
Expand All @@ -48,21 +48,23 @@ python -m build
twine check --strict dist/* && twine upload --repository pypi dist/*
```

* [ ] Check installation:
- [ ] Check installation:

```bash
pip uninstall -y humanize
pip install -U humanize
python3 -c "import humanize; print(humanize.__version__)"
```

* [ ] Push tag:
```bash
- [ ] Push tag:

```bash
git push --tags
```

* [ ] Edit release draft, adjust text if needed: https://github.com/python-humanize/humanize/releases
- [ ] Edit release draft, adjust text if needed:
https://github.com/python-humanize/humanize/releases

* [ ] Check next tag is correct, amend if needed
- [ ] Check next tag is correct, amend if needed

* [ ] Publish release
- [ ] Publish release
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Welcome to the humanize API reference.

* [Number](number.md)
* [Time](time.md)
* [Filesize](filesize.md)
* [I18n](i18n.md)
- [Number](number.md)
- [Time](time.md)
- [Filesize](filesize.md)
- [I18n](i18n.md)

{%
include-markdown "../README.md"
Expand Down
27 changes: 25 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,31 @@ artifacts = [
[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

[tool.isort]
profile = "black"
[tool.ruff]
line-length = 88
select = [
"E", # pycodestyle errors
"EM", # flake8-errmsg
"F", # pyflakes errors
"I", # isort
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"RUF100", # unused noqa (yesqa)
"UP", # pyupgrade
"W", # pycodestyle warnings
"YTT", # flake8-2020
# "LOG", # TODO: enable flake8-logging when it's not in preview anymore
]
extend-ignore = [
"E203", # Whitespace before ':'
"E221", # Multiple spaces before operator
"E226", # Missing whitespace around arithmetic operator
"E241", # Multiple spaces after ','
]

[tool.ruff.isort]
required-imports = ["from __future__ import annotations"]
known-first-party = ["humanize"]

[tool.pytest.ini_options]
addopts = "--color=yes"
Expand Down
3 changes: 1 addition & 2 deletions src/humanize/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from typing import TYPE_CHECKING

from .i18n import _gettext as _
from .i18n import _ngettext
from .i18n import _ngettext, decimal_separator, thousands_separator
from .i18n import _ngettext_noop as NS_
from .i18n import _pgettext as P_
from .i18n import decimal_separator, thousands_separator

if TYPE_CHECKING:
if sys.version_info >= (3, 10):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ def test_fractional(test_input: float | str, expected: str) -> None:
([5781651000], "5.78 x 10⁹"),
(["1000"], "1.00 x 10³"),
(["99"], "9.90 x 10¹"),
([float(0.3)], "3.00 x 10⁻¹"),
([0.3], "3.00 x 10⁻¹"),
(["foo"], "foo"),
([None], "None"),
([1000, 1], "1.0 x 10³"),
([float(0.3), 1], "3.0 x 10⁻¹"),
([0.3, 1], "3.0 x 10⁻¹"),
([1000, 0], "1 x 10³"),
([float(0.3), 0], "3 x 10⁻¹"),
([float(1e20)], "1.00 x 10²⁰"),
([float(2e-20)], "2.00 x 10⁻²⁰"),
([0.3, 0], "3 x 10⁻¹"),
([1e20], "1.00 x 10²⁰"),
([2e-20], "2.00 x 10⁻²⁰"),
([float(-3e20)], "-3.00 x 10²⁰"),
([float(-4e-20)], "-4.00 x 10⁻²⁰"),
([math.nan], "NaN"),
Expand Down
Loading