Repository: jjjake/internetarchive (language: python)

Issue:
pre-commit autoupdate for 2023_04_06
Upgrade bandit, black, codespell, and mypy running in pre-commit.

Fix three instances of bandit `S113 Probable use of requests call without timeout` by setting `timeout=10` seconds.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml
index 34a11363..3b8173e0 100644
--- a/.github/workflows/lint_python.yml
+++ b/.github/workflows/lint_python.yml
@@ -9,10 +9,10 @@ jobs:
         with:
           cache: pip
           python-version: 3.x
-      - run: pip install --upgrade pip wheel
+      - run: pip install --upgrade pip setuptools wheel
       - run: pip install .[all]
       - run: black --check --skip-string-normalization . || true
-      - run: flake8 .  # See setup.cfg for configuration
+      - run: ruff --format=github .  # See pyproject.toml for configuration
       - run: pip install -r pex-requirements.txt -r tests/requirements.txt
       - run: mypy .  # See setup.cfg for configuration
       - run: safety check || true  # Temporary fix for https://pyup.io/v/51457/f17
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index ecdac63f..b1f255f4 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -20,12 +20,12 @@ repos:
       - id: requirements-txt-fixer
       - id: trailing-whitespace
 
-  - repo: https://github.com/PyCQA/bandit
-    rev: 1.7.5
+  - repo: https://github.com/charliermarsh/ruff-pre-commit
+    rev: v0.0.261
+
     hooks:
-      - id: bandit
-        args:
-          - --skip=B101,B103,B105,B106,B303,B324,B318,B404,B408,B602
+      - id: ruff
+        # args: [ --fix, --exit-non-zero-on-fix ]
 
   - repo: https://github.com/psf/black
     rev: 23.3.0
@@ -41,22 +41,6 @@ repos:
     hooks:
       - id: codespell  # See setup.cfg for args
 
-  - repo: https://github.com/pycqa/flake8
-    rev: 6.0.0
-    hooks:
-      - id: flake8
-        additional_dependencies:
-          - flake8-2020
-          - flake8-bugbear
-          - flake8-comprehensions
-
-  - repo: https://github.com/timothycrosley/isort
-    rev: 5.12.0
-    hooks:
-      - id: isort
-        args:
-          - --profile=black
-
   - repo: https://github.com/pre-commit/mirrors-mypy
     rev: v1.1.1
     hooks:
@@ -70,13 +54,6 @@ repos:
           - types-ujson
           - types-urllib3
 
-  - repo: https://github.com/asottile/pyupgrade
-    rev: v3.3.1
-    hooks:
-      - id: pyupgrade
-        args:
-          - --py37-plus
-
   - repo: https://github.com/asottile/setup-cfg-fmt
     rev: v2.2.0
     hooks:
diff --git a/internetarchive/api.py b/internetarchive/api.py
index 3896bbdd..8ebd295c 100644
--- a/internetarchive/api.py
+++ b/internetarchive/api.py
@@ -33,9 +33,8 @@
 import requests
 from urllib3 import Retry
 
-from internetarchive import auth, catalog
+from internetarchive import auth, catalog, files, item, search, session
 from internetarchive import config as config_module
-from internetarchive import files, item, search, session
 from internetarchive.exceptions import AuthenticationError
 
 
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 00000000..ef31cd55
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,90 @@
+[tool.ruff]
+select = [
+  "B",    # flake8-bugbear
+  "C4",   # flake8-comprehensions
+  "C90",  # McCabe cyclomatic complexity
+  "E",    # pycodestyle
+  "EXE",  # flake8-executable
+  "F",    # Pyflakes
+  "I",    # isort
+  "ICN",  # flake8-import-conventions
+  "INT",  # flake8-gettext
+  "ISC",  # flake8-implicit-str-concat
+  "PIE",  # flake8-pie
+  "PL",   # Pylint
+  "PT",   # flake8-pytest-style
+  "PYI",  # flake8-pyi
+  "RSE",  # flake8-raise
+  "RUF",  # Ruff-specific rules
+  "S",    # flake8-bandit
+  "SLF",  # flake8-self
+  "T10",  # flake8-debugger
+  "TID",  # flake8-tidy-imports
+  "UP",   # pyupgrade
+  "W",    # pycodestyle
+  "YTT",  # flake8-2020
+  # "A",    # flake8-builtins
+  # "ANN",  # flake8-annotations
+  # "ARG",  # flake8-unused-arguments
+  # "BLE",  # flake8-blind-except
+  # "COM",  # flake8-commas
+  # "D",    # pydocstyle
+  # "DJ",   # flake8-django
+  # "DTZ",  # flake8-datetimez
+  # "EM",   # flake8-errmsg
+  # "ERA",  # eradicate
+  # "FBT",  # flake8-boolean-trap
+  # "G",    # flake8-logging-format
+  # "INP",  # flake8-no-pep420
+  # "N",    # pep8-naming
+  # "NPY",  # NumPy-specific rules
+  # "PD",   # pandas-vet
+  # "PGH",  # pygrep-hooks
+  # "PTH",  # flake8-use-pathlib
+  # "Q",    # flake8-quotes
+  # "RET",  # flake8-return
+  # "SIM",  # flake8-simplify
+  # "T20",  # flake8-print
+  # "TCH",  # flake8-type-checking
+  # "TRY",  # tryceratops
+]
+ignore = [
+  "B904",
+  "F401",
+  "F841",
+  "PLC1901",
+  "PLR2004",
+  "PLR5501",
+  "PLW0603",
+  "PLW2901",
+  "RUF001",
+  "RUF005",
+  "S101",
+  "S103",
+  "S105",
+  "S106",
+  "S318",
+  "S324",
+]
+target-version = "py37"
+
+line-length = 102
+
+[tool.ruff.mccabe]
+max-complexity = 33
+
+[tool.ruff.pylint]
+max-args = 23
+max-branches = 33
+max-statements = 124
+
+[tool.ruff.per-file-ignores]
+"__init__.py" = ["E402"]
+"tests/*" = [
+  "PT017",
+  "S101",
+]
+"tests/conftest.py" = ["B018", "F811"]
+"tests/cli/test_ia_list.py" = ["E741"]
+"tests/test_api.py" = ["E712"]
+"tests/test_config.py" = ["PT011"]
diff --git a/setup.cfg b/setup.cfg
index 120e32bf..1b6af950 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -46,14 +46,9 @@ all =
     %(types)s
 dev =
     black
-    flake8
-    flake8-2020
-    flake8-bugbear
-    flake8-comprehensions
     mypy
     pre-commit
     pytest
-    pyupgrade
     safety
     setuptools
 docs =
@@ -62,9 +57,9 @@ docs =
     sphinx==4.5.0
     sphinx-autodoc-typehints==1.18.1
 test =
-    flake8==6.0.0
     pytest==7.1.2
     responses==0.20.0
+    ruff==0.0.261
 types =
     tqdm-stubs>=0.2.0
     types-colorama
@@ -82,18 +77,6 @@ types =
 [codespell]
 ignore-words-list = alers
 
-[flake8]
-ignore = E128,E722,F401,F841,W503,W605
-exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,.tox
-max-complexity = 43
-max-line-length = 102
-per-file-ignores =
-    ./tests/conftest.py: F811
-    ./tests/cli/test_ia_list.py: E741
-    ./tests/test_api.py: E712
-show-source = true
-statistics = true
-
 [mypy]
 exclude = ^\.git/|^__pycache__/|^docs/source/conf.py$|^old/|^build/|^dist/|\.tox
 python_version = 3.9
@@ -103,9 +86,6 @@ scripts_are_modules = True
 show_error_codes = True
 show_error_context = True
 
-[isort]
-profile = black
-
 [tool:black]
 line-length = 102
 skip-string-normalization = true
diff --git a/tox.ini b/tox.ini
index 1ac0c772..062086a0 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,7 +4,7 @@ envlist = py37,py38,py39,py310,py311,pypy37,pypy38,pypy39
 [testenv]
 deps = -r tests/requirements.txt
 # See setup.cfg for changes to default settings
-commands = flake8
+commands = ruff .
            pytest {posargs}
 
 [testenv:py37]


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 46272b6e..0b1392a7 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -101,20 +101,20 @@ def mock_all_downloads(self, num_calls=1, body='test content', protocol='https?'
             self.add(responses.GET, url, body=body)
 
 
-@pytest.fixture
+@pytest.fixture()
 def tmpdir_ch(tmpdir):
     tmpdir.chdir()
     return tmpdir
 
 
-@pytest.fixture
+@pytest.fixture()
 def nasa_mocker():
     with IaRequestsMock() as mocker:
         mocker.add_metadata_mock('nasa')
         yield mocker
 
 
-@pytest.fixture
+@pytest.fixture()
 def nasa_item():
     session = get_session()
     with IaRequestsMock() as mocker:
@@ -122,17 +122,17 @@ def nasa_item():
         yield session.get_item('nasa')
 
 
-@pytest.fixture
+@pytest.fixture()
 def session():
     return get_session(config={'s3': {'access': 'access', 'secret': 'secret'}})
 
 
-@pytest.fixture
+@pytest.fixture()
 def nasa_metadata():
     return json.loads(load_test_data_file('metadata/nasa.json'))
 
 
 # TODO: Why is this function defined twice in this file?  See issue #505
-@pytest.fixture  # type: ignore
+@pytest.fixture()  # type: ignore
 def nasa_item(nasa_mocker):
     return get_item('nasa')
diff --git a/tests/requirements.txt b/tests/requirements.txt
index 81dd49c8..7b3df803 100644
--- a/tests/requirements.txt
+++ b/tests/requirements.txt
@@ -1,3 +1,3 @@
-flake8==4.0.1
-pytest==7.1.2
-responses==0.20.0
+pytest==7.2.2
+responses==0.23.1
+ruff==0.0.261