Replace Flake8 with Ruff (#447)
This commit is contained in:
commit
d505d57fc4
11
.github/workflows/deploy.yml
vendored
11
.github/workflows/deploy.yml
vendored
|
@ -30,12 +30,14 @@ jobs:
|
||||||
# Upload to Test PyPI on every commit on main.
|
# Upload to Test PyPI on every commit on main.
|
||||||
release-test-pypi:
|
release-test-pypi:
|
||||||
name: Publish in-dev package to test.pypi.org
|
name: Publish in-dev package to test.pypi.org
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: |
|
||||||
|
github.repository_owner == 'pylast'
|
||||||
|
&& github.event_name == 'push'
|
||||||
|
&& github.ref == 'refs/heads/main'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build-package
|
needs: build-package
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
# IMPORTANT: this permission is mandatory for trusted publishing
|
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@ -53,12 +55,13 @@ jobs:
|
||||||
# Upload to real PyPI on GitHub Releases.
|
# Upload to real PyPI on GitHub Releases.
|
||||||
release-pypi:
|
release-pypi:
|
||||||
name: Publish released package to pypi.org
|
name: Publish released package to pypi.org
|
||||||
if: github.event.action == 'published'
|
if: |
|
||||||
|
github.repository_owner == 'pylast'
|
||||||
|
&& github.event.action == 'published'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build-package
|
needs: build-package
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
# IMPORTANT: this permission is mandatory for trusted publishing
|
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
3
.github/workflows/labels.yml
vendored
3
.github/workflows/labels.yml
vendored
|
@ -1,5 +1,8 @@
|
||||||
name: Sync labels
|
name: Sync labels
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
|
3
.github/workflows/lint.yml
vendored
3
.github/workflows/lint.yml
vendored
|
@ -2,6 +2,9 @@ name: Lint
|
||||||
|
|
||||||
on: [push, pull_request, workflow_dispatch]
|
on: [push, pull_request, workflow_dispatch]
|
||||||
|
|
||||||
|
env:
|
||||||
|
FORCE_COLOR: 1
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
|
|
1
.github/workflows/require-pr-label.yml
vendored
1
.github/workflows/require-pr-label.yml
vendored
|
@ -10,6 +10,7 @@ jobs:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
issues: write
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: mheap/github-action-required-labels@v5
|
- uses: mheap/github-action-required-labels@v5
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v3.15.0
|
rev: v0.2.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: ruff
|
||||||
args: [--py38-plus]
|
args: [--fix, --exit-non-zero-on-fix]
|
||||||
|
|
||||||
- repo: https://github.com/psf/black-pre-commit-mirror
|
- repo: https://github.com/psf/black-pre-commit-mirror
|
||||||
rev: 23.12.1
|
rev: 24.1.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
|
|
||||||
|
@ -15,24 +15,7 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: blacken-docs
|
- id: blacken-docs
|
||||||
args: [--target-version=py38]
|
args: [--target-version=py38]
|
||||||
additional_dependencies: [black==23.3.0]
|
additional_dependencies: [black]
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/isort
|
|
||||||
rev: 5.13.2
|
|
||||||
hooks:
|
|
||||||
- id: isort
|
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/flake8
|
|
||||||
rev: 6.1.0
|
|
||||||
hooks:
|
|
||||||
- id: flake8
|
|
||||||
additional_dependencies: [flake8-2020, 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
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.5.0
|
rev: v4.5.0
|
||||||
|
@ -42,19 +25,19 @@ repos:
|
||||||
- id: check-json
|
- id: check-json
|
||||||
- id: check-toml
|
- id: check-toml
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
|
- id: debug-statements
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: requirements-txt-fixer
|
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
exclude: .github/(ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE).md
|
exclude: .github/(ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE).md
|
||||||
|
|
||||||
- repo: https://github.com/tox-dev/pyproject-fmt
|
- repo: https://github.com/tox-dev/pyproject-fmt
|
||||||
rev: 1.5.3
|
rev: 1.7.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyproject-fmt
|
- id: pyproject-fmt
|
||||||
additional_dependencies: [tox]
|
additional_dependencies: [tox]
|
||||||
|
|
||||||
- repo: https://github.com/abravalheri/validate-pyproject
|
- repo: https://github.com/abravalheri/validate-pyproject
|
||||||
rev: v0.15
|
rev: v0.16
|
||||||
hooks:
|
hooks:
|
||||||
- id: validate-pyproject
|
- id: validate-pyproject
|
||||||
|
|
||||||
|
@ -63,5 +46,10 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: tox-ini-fmt
|
- id: tox-ini-fmt
|
||||||
|
|
||||||
|
- repo: meta
|
||||||
|
hooks:
|
||||||
|
- id: check-hooks-apply
|
||||||
|
- id: check-useless-excludes
|
||||||
|
|
||||||
ci:
|
ci:
|
||||||
autoupdate_schedule: quarterly
|
autoupdate_schedule: quarterly
|
||||||
|
|
|
@ -59,5 +59,28 @@ version.source = "vcs"
|
||||||
[tool.hatch.version.raw-options]
|
[tool.hatch.version.raw-options]
|
||||||
local_scheme = "no-local-version"
|
local_scheme = "no-local-version"
|
||||||
|
|
||||||
[tool.isort]
|
[tool.ruff.lint]
|
||||||
profile = "black"
|
select = [
|
||||||
|
"C4", # flake8-comprehensions
|
||||||
|
"E", # pycodestyle errors
|
||||||
|
"EM", # flake8-errmsg
|
||||||
|
"F", # pyflakes errors
|
||||||
|
"I", # isort
|
||||||
|
"ISC", # flake8-implicit-str-concat
|
||||||
|
"LOG", # flake8-logging
|
||||||
|
"PGH", # pygrep-hooks
|
||||||
|
"RUF100", # unused noqa (yesqa)
|
||||||
|
"UP", # pyupgrade
|
||||||
|
"W", # pycodestyle warnings
|
||||||
|
"YTT", # flake8-2020
|
||||||
|
]
|
||||||
|
extend-ignore = [
|
||||||
|
"E203", # Whitespace before ':'
|
||||||
|
"E221", # Multiple spaces before operator
|
||||||
|
"E226", # Missing whitespace around arithmetic operator
|
||||||
|
"E241", # Multiple spaces after ','
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff.lint.isort]
|
||||||
|
known-first-party = ["pylast"]
|
||||||
|
required-imports = ["from __future__ import annotations"]
|
||||||
|
|
|
@ -628,7 +628,6 @@ class _Network:
|
||||||
|
|
||||||
|
|
||||||
class LastFMNetwork(_Network):
|
class LastFMNetwork(_Network):
|
||||||
|
|
||||||
"""A Last.fm network object
|
"""A Last.fm network object
|
||||||
|
|
||||||
api_key: a provided API_KEY
|
api_key: a provided API_KEY
|
||||||
|
@ -1243,8 +1242,10 @@ class _Chartable(_BaseObject):
|
||||||
from_date value to the to_date value.
|
from_date value to the to_date value.
|
||||||
chart_kind should be one of "album", "artist" or "track"
|
chart_kind should be one of "album", "artist" or "track"
|
||||||
"""
|
"""
|
||||||
|
import sys
|
||||||
|
|
||||||
method = ".getWeekly" + chart_kind.title() + "Chart"
|
method = ".getWeekly" + chart_kind.title() + "Chart"
|
||||||
chart_type = eval(chart_kind.title()) # string to type
|
chart_type = getattr(sys.modules[__name__], chart_kind.title())
|
||||||
|
|
||||||
params = self._get_params()
|
params = self._get_params()
|
||||||
if from_date and to_date:
|
if from_date and to_date:
|
||||||
|
@ -1356,11 +1357,11 @@ class _Taggable(_BaseObject):
|
||||||
new_tags.append(tag)
|
new_tags.append(tag)
|
||||||
|
|
||||||
for i in range(0, len(old_tags)):
|
for i in range(0, len(old_tags)):
|
||||||
if not c_old_tags[i] in c_new_tags:
|
if c_old_tags[i] not in c_new_tags:
|
||||||
to_remove.append(old_tags[i])
|
to_remove.append(old_tags[i])
|
||||||
|
|
||||||
for i in range(0, len(new_tags)):
|
for i in range(0, len(new_tags)):
|
||||||
if not c_new_tags[i] in c_old_tags:
|
if c_new_tags[i] not in c_old_tags:
|
||||||
to_add.append(new_tags[i])
|
to_add.append(new_tags[i])
|
||||||
|
|
||||||
self.remove_tags(to_remove)
|
self.remove_tags(to_remove)
|
||||||
|
@ -2778,7 +2779,8 @@ def _collect_nodes(
|
||||||
main.getAttribute("totalPages") or main.getAttribute("totalpages")
|
main.getAttribute("totalPages") or main.getAttribute("totalpages")
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise PyLastError("No total pages attribute")
|
msg = "No total pages attribute"
|
||||||
|
raise PyLastError(msg)
|
||||||
|
|
||||||
for node in main.childNodes:
|
for node in main.childNodes:
|
||||||
if not node.nodeType == xml.dom.Node.TEXT_NODE and (
|
if not node.nodeType == xml.dom.Node.TEXT_NODE and (
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
from .test_pylast import TestPyLastWithLastFm
|
from .test_pylast import TestPyLastWithLastFm
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
from .test_pylast import TestPyLastWithLastFm
|
from .test_pylast import TestPyLastWithLastFm
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
from .test_pylast import TestPyLastWithLastFm
|
from .test_pylast import TestPyLastWithLastFm
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from flaky import flaky
|
from flaky import flaky
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
from .test_pylast import TestPyLastWithLastFm
|
from .test_pylast import TestPyLastWithLastFm
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import calendar
|
import calendar
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
import inspect
|
import inspect
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -25,7 +27,7 @@ def test_get_cache_key(artist) -> None:
|
||||||
|
|
||||||
@pytest.mark.parametrize("obj", [pylast.Artist("B\xe9l", mock_network())])
|
@pytest.mark.parametrize("obj", [pylast.Artist("B\xe9l", mock_network())])
|
||||||
def test_cast_and_hash(obj) -> None:
|
def test_cast_and_hash(obj) -> None:
|
||||||
assert type(str(obj)) is str
|
assert isinstance(str(obj), str)
|
||||||
assert isinstance(hash(obj), int)
|
assert isinstance(hash(obj), int)
|
||||||
|
|
||||||
|
|
||||||
|
|
9
tox.ini
9
tox.ini
|
@ -15,7 +15,14 @@ pass_env =
|
||||||
PYLAST_PASSWORD_HASH
|
PYLAST_PASSWORD_HASH
|
||||||
PYLAST_USERNAME
|
PYLAST_USERNAME
|
||||||
commands =
|
commands =
|
||||||
pytest -v -s -W all --cov pylast --cov tests --cov-report term-missing --cov-report xml --random-order {posargs}
|
{envpython} -m pytest -v -s -W all \
|
||||||
|
--cov pylast \
|
||||||
|
--cov tests \
|
||||||
|
--cov-report html \
|
||||||
|
--cov-report term-missing \
|
||||||
|
--cov-report xml \
|
||||||
|
--random-order \
|
||||||
|
{posargs}
|
||||||
|
|
||||||
[testenv:lint]
|
[testenv:lint]
|
||||||
skip_install = true
|
skip_install = true
|
||||||
|
|
Loading…
Reference in a new issue