From 1c5d20813e00981d5b346bd0bc9a61c121ea8cb2 Mon Sep 17 00:00:00 2001 From: Simon Sawicki Date: Mon, 22 Jan 2024 03:13:05 +0100 Subject: [PATCH] Add ruff linter --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/workflows/quick-test.yml | 8 ++++---- CONTRIBUTING.md | 4 ++-- Makefile | 2 +- pyproject.toml | 28 ++++++++++++++++++++++++++-- setup.cfg | 27 --------------------------- 6 files changed, 34 insertions(+), 37 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index c4d3e812e..a4566ceec 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -28,7 +28,7 @@ # PLEASE FOLLOW THE GUIDE BELOW ### Before submitting a *pull request* make sure you have: - [ ] At least skimmed through [contributing guidelines](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#developer-instructions) including [yt-dlp coding conventions](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#yt-dlp-coding-conventions) - [ ] [Searched](https://github.com/yt-dlp/yt-dlp/search?q=is%3Apr&type=Issues) the bugtracker for similar pull requests -- [ ] Checked the code with [flake8](https://pypi.python.org/pypi/flake8) and [ran relevant tests](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#developer-instructions) +- [ ] Checked the code with [ruff](https://docs.astral.sh/ruff/) and [ran relevant tests](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#developer-instructions) ### In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under [Unlicense](http://unlicense.org/). Check all of the following options that apply: - [ ] I am the original author of this code and I am willing to release it under [Unlicense](http://unlicense.org/) diff --git a/.github/workflows/quick-test.yml b/.github/workflows/quick-test.yml index 3114e7bdd..5834f9eb3 100644 --- a/.github/workflows/quick-test.yml +++ b/.github/workflows/quick-test.yml @@ -20,16 +20,16 @@ jobs: run: | python3 -m yt_dlp -v || true python3 ./devscripts/run_tests.py core - flake8: + linter: name: Linter if: "!contains(github.event.head_commit.message, 'ci skip all')" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - - name: Install flake8 + - name: Install dev dependencies run: python3 ./devscripts/install_deps.py -o --include dev - name: Make lazy extractors run: python3 ./devscripts/make_lazy_extractors.py - - name: Run flake8 - run: flake8 . + - name: Run ruff + run: ruff check . --output-format github diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 248917bf5..653ddd885 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -221,9 +221,9 @@ ## Adding support for a new site 1. Run `python devscripts/run_tests.py YourExtractor`. This *may fail* at first, but you can continually re-run it until you're done. Upon failure, it will output the missing fields and/or correct values which you can copy. If you decide to add more than one test, the tests will then be named `YourExtractor`, `YourExtractor_1`, `YourExtractor_2`, etc. Note that tests with an `only_matching` key in the test's dict are not included in the count. You can also run all the tests in one go with `YourExtractor_all` 1. Make sure you have at least one test for your extractor. Even if all videos covered by the extractor are expected to be inaccessible for automated testing, tests should still be added with a `skip` parameter indicating why the particular test is disabled from running. 1. Have a look at [`yt_dlp/extractor/common.py`](yt_dlp/extractor/common.py) for possible helper methods and a [detailed description of what your extractor should and may return](yt_dlp/extractor/common.py#L119-L440). Add tests and code for as many as you want. -1. Make sure your code follows [yt-dlp coding conventions](#yt-dlp-coding-conventions) and check the code with [flake8](https://flake8.pycqa.org/en/latest/index.html#quickstart): +1. Make sure your code follows [yt-dlp coding conventions](#yt-dlp-coding-conventions) and check the code with [ruff](https://docs.astral.sh/ruff/tutorial/#getting-started): - $ flake8 yt_dlp/extractor/yourextractor.py + $ ruff check yt_dlp/extractor/yourextractor.py 1. Make sure your code works under all [Python](https://www.python.org/) versions supported by yt-dlp, namely CPython and PyPy for Python 3.8 and above. Backward compatibility is not required for even older versions of Python. 1. When the tests pass, [add](https://git-scm.com/docs/git-add) the new files, [commit](https://git-scm.com/docs/git-commit) them and [push](https://git-scm.com/docs/git-push) the result, like this: diff --git a/Makefile b/Makefile index 2f36c0cd1..14e5dd20d 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ uninstall: rm -f $(DESTDIR)$(SHAREDIR)/fish/vendor_completions.d/yt-dlp.fish codetest: - flake8 . + ruff check . test: $(PYTHON) -m pytest diff --git a/pyproject.toml b/pyproject.toml index 5ef013279..6d05ccaea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,8 +62,7 @@ build = [ "wheel", ] dev = [ - "flake8", - "isort", + "ruff==0.2.1", "pytest", ] pyinstaller = ["pyinstaller>=6.3"] @@ -118,3 +117,28 @@ artifacts = ["/yt_dlp/extractor/lazy_extractors.py"] [tool.hatch.version] path = "yt_dlp/version.py" pattern = "_pkg_version = '(?P[^']+)'" + +[tool.ruff] +required-version = "0.2.1" +line-length = 120 + +[tool.ruff.lint] +ignore = [ + "E402", # module level import not at top of file + "E501", # line too long + "E731", # do not assign a lambda expression, use a def + "E741", # ambiguous variable name +] +select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes + # "I", # import order +] + +[tool.ruff.lint.per-file-ignores] +"devscripts/lazy_load_template.py" = ["F401"] + +[tool.ruff.lint.isort] +known-first-party = ["test"] +relative-imports-order = "closest-to-furthest" diff --git a/setup.cfg b/setup.cfg index aeb4cee58..291960c5c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,19 +1,3 @@ -[flake8] -exclude = build,venv,.tox,.git,.pytest_cache -ignore = E402,E501,E731,E741,W503 -max_line_length = 120 -per_file_ignores = - devscripts/lazy_load_template.py: F401 - - -[autoflake] -ignore-init-module-imports = true -ignore-pass-after-docstring = true -remove-all-unused-imports = true -remove-duplicate-keys = true -remove-unused-variables = true - - [tool:pytest] addopts = -ra -v --strict-markers markers = @@ -32,14 +16,3 @@ commands = pytest {posargs:"-m not download"} passenv = HOME # For test_compat_expanduser setenv = # PYTHONWARNINGS = error # Catches PIP's warnings too - - -[isort] -py_version = 38 -multi_line_output = VERTICAL_HANGING_INDENT -line_length = 80 -reverse_relative = true -ensure_newline_before_comments = true -include_trailing_comma = true -known_first_party = - test