From 80c885de59ceb01e2854884367a97a2aa763048b Mon Sep 17 00:00:00 2001 From: Albert King Date: Sun, 31 Mar 2024 08:44:36 +0800 Subject: [PATCH] Dev (#110) * Chore: update actions/setup-python@v4 to actions/setup-python@v5 * Chore: add ruff * Chore: remove black deps * Chore: add ruff deps * Chore: add ruff * Fix: add ruff format * Chore: add ruff and remove black --- .github/workflows/main.yml | 4 +- .github/workflows/schedule.yml | 4 +- pyproject.toml | 79 +++++++++++++++++++++++++++++++++- requirements.txt | 4 +- setup.cfg | 16 ++----- 5 files changed, 87 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f37f6cd..eb930b9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: - name: Install tox run: python -m pip install tox - - name: Run black + - name: Run ruff run: tox -e format lint: @@ -33,7 +33,7 @@ jobs: - name: Install tox run: python -m pip install tox - - name: Run flake8 + - name: Run ruff run: tox -e lint typecheck: diff --git a/.github/workflows/schedule.yml b/.github/workflows/schedule.yml index 5df6bbc..bac6208 100644 --- a/.github/workflows/schedule.yml +++ b/.github/workflows/schedule.yml @@ -18,7 +18,7 @@ jobs: - name: Install tox run: python -m pip install tox - - name: Run black + - name: Run ruff run: tox -e format lint: @@ -34,7 +34,7 @@ jobs: - name: Install tox run: python -m pip install tox - - name: Run flake8 + - name: Run ruff run: tox -e lint typecheck: diff --git a/pyproject.toml b/pyproject.toml index 0f38e95..40a1273 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,81 @@ requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" -[tool.black] +[tool.ruff] +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", +] + +# Same as Black. line-length = 79 -target-version = ["py39", "py310", "py311", "py312"] +indent-width = 4 + +# Assume Python 3.12 +target-version = "py312" + +[tool.ruff.lint] +# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. +# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or +# McCabe complexity (`C901`) by default. +select = ["E4", "E7", "E9", "F"] +ignore = [] + +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[tool.ruff.format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" + +# Enable auto-formatting of code examples in docstrings. Markdown, +# reStructuredText code/literal blocks and doctests are all supported. +# +# This is currently disabled by default, but it is planned for this +# to be opt-out in the future. +docstring-code-format = false + +# Set the line length limit used when formatting code snippets in +# docstrings. +# +# This only has an effect when the `docstring-code-format` setting is +# enabled. +docstring-code-line-length = "dynamic" diff --git a/requirements.txt b/requirements.txt index 899219c..49598b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ akshare>=1.10.1 alpaca-py>=0.7.2 -black>=22.10.0 diskcache>=5.4.0 flake8>=5.0.4 flake8-bugbear>=22.10.25 @@ -22,4 +21,5 @@ scikit-learn>=1.2.1 Sphinx>=5.3.0 sphinx_rtd_theme>=1.1.1 sphinx-intl>=2.1.0 -yfinance>=0.1.84 \ No newline at end of file +yfinance>=0.1.84 +ruff>=0.3.4 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 179989a..744cc9e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,13 +40,6 @@ pretty = True namespace_packages = True check_untyped_defs = True -[flake8] -per-file-ignores = - src/pybroker/*.py:E203,E402 - src/pybroker/__init__.py:F401,E402 - tests/*.py:E203,E402 - tests/test_*:E203,E402,F403,F405 - [tox:tox] envlist = py39,py310,py311,py312 isolated_build = True @@ -70,17 +63,16 @@ commands = [testenv:format] skip_install = True deps = - black + ruff commands = - black {posargs:--check --diff src tests} + ruff {posargs:--fix src tests} [testenv:lint] skip_install = True deps = - flake8 - flake8-bugbear + ruff commands = - flake8 {posargs:src tests} + ruff {posargs:src tests} [testenv:docs] deps =