From db93a85d466440691cb411c6b68c022583882e86 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 23 Nov 2023 20:48:17 -0500 Subject: [PATCH] Switch to ruff (#672) --- pyproject.toml | 8 ++++++-- release.py | 18 ++++++++---------- setup.py | 2 +- src/bcrypt/__about__.py | 5 +---- src/bcrypt/__init__.py | 5 +---- tests/test_bcrypt.py | 11 +++++------ tox.ini | 15 +++------------ 7 files changed, 25 insertions(+), 39 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9a5bc26..83938e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,10 @@ requires = [ # disable Pip's fallback guessing build-backend = "setuptools.build_meta" -[tool.black] +[tool.ruff] +ignore = ['N818'] +select = ['E', 'F', 'I', 'N', 'W', 'UP', 'RUF'] line-length = 79 -target-version = ["py37"] + +[tool.ruff.isort] +known-first-party = ["bcrypt", "tests"] diff --git a/release.py b/release.py index e104c65..38426a1 100644 --- a/release.py +++ b/release.py @@ -2,7 +2,6 @@ # 2.0, and the BSD License. See the LICENSE file in the root of this repository # for complete details. -from __future__ import absolute_import, division, print_function import getpass import io @@ -13,12 +12,11 @@ import time import zipfile import click - import requests def run(*args, **kwargs): - print("[running] {0}".format(list(args))) + print(f"[running] {list(args)}") subprocess.check_call(list(args), **kwargs) @@ -28,7 +26,7 @@ def wait_for_build_complete_github_actions(session, token, run_url): run_url, headers={ "Content-Type": "application/json", - "Authorization": "token {}".format(token), + "Authorization": f"token {token}", }, ) response.raise_for_status() @@ -42,7 +40,7 @@ def download_artifacts_github_actions(session, token, run_url): run_url, headers={ "Content-Type": "application/json", - "Authorization": "token {}".format(token), + "Authorization": f"token {token}", }, ) response.raise_for_status() @@ -51,7 +49,7 @@ def download_artifacts_github_actions(session, token, run_url): response.json()["artifacts_url"], headers={ "Content-Type": "application/json", - "Authorization": "token {}".format(token), + "Authorization": f"token {token}", }, ) response.raise_for_status() @@ -61,7 +59,7 @@ def download_artifacts_github_actions(session, token, run_url): artifact["archive_download_url"], headers={ "Content-Type": "application/json", - "Authorization": "token {}".format(token), + "Authorization": f"token {token}", }, ) with zipfile.ZipFile(io.BytesIO(response.content)) as z: @@ -89,7 +87,7 @@ def build_github_actions_sdist_wheels(token, version): headers={ "Content-Type": "application/json", "Accept": "application/vnd.github.v3+json", - "Authorization": "token {}".format(token), + "Authorization": f"token {token}", }, data=json.dumps({"ref": "main", "inputs": {"version": version}}), ) @@ -104,7 +102,7 @@ def build_github_actions_sdist_wheels(token, version): ), headers={ "Content-Type": "application/json", - "Authorization": "token {}".format(token), + "Authorization": f"token {token}", }, ) response.raise_for_status() @@ -121,7 +119,7 @@ def release(version): """ github_token = getpass.getpass("Github person access token: ") - run("git", "tag", "-s", version, "-m", "{0} release".format(version)) + run("git", "tag", "-s", version, "-m", f"{version} release") run("git", "push", "--tags") github_actions_paths = build_github_actions_sdist_wheels( diff --git a/setup.py b/setup.py index c5f5c45..c07000c 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ try: ), ], ) -except: # noqa: E722 +except: # Note: This is a bare exception that re-raises so that we don't interfere # with anything the installation machinery might want to do. Because we # print this for any exception this msg can appear (e.g. in verbose logs) diff --git a/src/bcrypt/__about__.py b/src/bcrypt/__about__.py index 020b748..69167b2 100644 --- a/src/bcrypt/__about__.py +++ b/src/bcrypt/__about__.py @@ -13,9 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import -from __future__ import division -from __future__ import unicode_literals __all__ = [ "__title__", @@ -38,4 +35,4 @@ __author__ = "The Python Cryptographic Authority developers" __email__ = "cryptography-dev@python.org" __license__ = "Apache License, Version 2.0" -__copyright__ = "Copyright 2013-2022 {0}".format(__author__) +__copyright__ = f"Copyright 2013-2023 {__author__}" diff --git a/src/bcrypt/__init__.py b/src/bcrypt/__init__.py index 6663d7c..6fdf04f 100644 --- a/src/bcrypt/__init__.py +++ b/src/bcrypt/__init__.py @@ -13,9 +13,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import -from __future__ import division +from . import _bcrypt from .__about__ import ( __author__, __copyright__, @@ -26,8 +25,6 @@ from .__about__ import ( __uri__, __version__, ) -from . import _bcrypt # noqa: I100 - __all__ = [ "__title__", diff --git a/tests/test_bcrypt.py b/tests/test_bcrypt.py index 148a509..e7919d6 100644 --- a/tests/test_bcrypt.py +++ b/tests/test_bcrypt.py @@ -2,7 +2,6 @@ import pytest import bcrypt - _test_vectors = [ ( b"Kk4DQuMMfZL9o", @@ -393,13 +392,13 @@ def test_checkpw_extra_data(): [ # longer password 8, - b"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " - b"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut " + b"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do" + b" eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut " b"enim ad minim veniam, quis nostrud exercitation ullamco laboris " b"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor " - b"in reprehenderit in voluptate velit esse cillum dolore eu fugiat " - b"nulla pariatur. Excepteur sint occaecat cupidatat non proident, " - b"sunt in culpa qui officia deserunt mollit anim id est laborum.", + b"in reprehenderit in voluptate velit esse cillum dolore eu fugiat" + b" nulla pariatur. Excepteur sint occaecat cupidatat non proident," + b" sunt in culpa qui officia deserunt mollit anim id est laborum.", b"salis\x00", b"\x10\x97\x8b\x07\x25\x3d\xf5\x7f\x71\xa1\x62\xeb\x0e\x8a\xd3\x0a", ], diff --git a/tox.ini b/tox.ini index 4814eb5..7184202 100644 --- a/tox.ini +++ b/tox.ini @@ -15,13 +15,10 @@ commands = [testenv:pep8] deps = - black - flake8 - flake8-import-order - pep8-naming + ruff commands = - flake8 . - black --check . + ruff . + ruff format --check . [testenv:mypy] deps = @@ -39,12 +36,6 @@ commands = python setup.py check --metadata --restructuredtext --strict -[flake8] -ignore = E203,E211,E501,W503,W504 -exclude = .tox,*.egg -select = E,W,F,N,I -application-import-names = bcrypt,tests - [check-manifest] ignore = tests/reference/*