From 398dd8eee0ac8691efffa9685c90994be0d828ee Mon Sep 17 00:00:00 2001 From: rht Date: Sat, 21 Jan 2023 00:19:02 -0500 Subject: [PATCH] ci: Replace flake8 with Ruff --- .flake8 | 8 -------- .github/workflows/build_lint.yml | 11 ++++++----- CONTRIBUTING.rst | 6 +++--- mesa/visualization/UserParam.py | 2 +- pyproject.toml | 13 +++++++++++++ setup.py | 2 +- 6 files changed, 24 insertions(+), 18 deletions(-) delete mode 100644 .flake8 create mode 100644 pyproject.toml diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 8e554855083..00000000000 --- a/.flake8 +++ /dev/null @@ -1,8 +0,0 @@ -[flake8] -# Ignore list taken from https://github.com/psf/black/blob/master/.flake8 -# E203 Whitespace before ':' -# E266 Too many leading '#' for block comment -# E501 Line too long (82 > 79 characters) -# W503 Line break occurred before a binary operator -ignore = E203, E266, E501, W503 -exclude = docs, build diff --git a/.github/workflows/build_lint.yml b/.github/workflows/build_lint.yml index 5d87a4b6880..b8eb7dd0fbb 100644 --- a/.github/workflows/build_lint.yml +++ b/.github/workflows/build_lint.yml @@ -60,7 +60,7 @@ jobs: name: Codecov uses: codecov/codecov-action@v3 - lint-flake: + lint-ruff: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -68,10 +68,11 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3.10" - - run: pip install flake8 - - name: Lint with flake8 - # Use settings from mesas .flake8 file - run: flake8 . --count --show-source --statistics + - run: pip install ruff + - name: Lint with ruff + # Include `--format=github` to enable automatic inline annotations. + # Use settings from pyproject.toml. + run: ruff . --format=github --extend-exclude mesa/cookiecutter-mesa/* lint-black: runs-on: ubuntu-latest diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 5ed0feef7e0..f65b7baa1c0 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -68,11 +68,11 @@ If you're changing previous Mesa features, please make sure of the following: - Additional features or rewrites of current features are accompanied by tests. - New features are demonstrated in a model, so folks can understand more easily. -To ensure that your submission will not break the build, you will need to install Flake8 and pytest. +To ensure that your submission will not break the build, you will need to install Ruff and pytest. .. code-block:: bash - pip install flake8 pytest pytest-cov + pip install ruff pytest pytest-cov We test by implementing simple models and through traditional unit tests in the tests/ folder. The following only covers unit tests coverage. Ensure that your test coverage has not gone down. If it has and you need help, we will offer advice on how to structure tests for the contribution. @@ -91,7 +91,7 @@ You should no longer have to worry about code formatting. If still in doubt you .. code-block:: bash - flake8 . --ignore=F403,E501,E123,E128,W504,W503 --exclude=docs,build + ruff . .. _`PEP8` : https://www.python.org/dev/peps/pep-0008 diff --git a/mesa/visualization/UserParam.py b/mesa/visualization/UserParam.py index 0a1c6ac7560..b7180006585 100644 --- a/mesa/visualization/UserParam.py +++ b/mesa/visualization/UserParam.py @@ -92,7 +92,7 @@ def __init__( valid = True if self.param_type == self.NUMBER: - valid = not (self.value is None) + valid = self.value is not None elif self.param_type == self.SLIDER: valid = not ( diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000000..dcc4868cd50 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[tool.ruff] +# Ignore list taken from https://github.com/psf/black/blob/master/.flake8 +# E203 Whitespace before ':' +# E266 Too many leading '#' for block comment +# E501 Line too long (82 > 79 characters) +# W503 Line break occurred before a binary operator +# But we don't specify them because ruff's Black already +# checks for it. +# See https://github.com/charliermarsh/ruff/issues/1842#issuecomment-1381210185 +extend-ignore = ["E501"] +extend-exclude = ["docs", "build"] +# Hardcode to Python 3.10. +target-version = "py310" diff --git a/setup.py b/setup.py index 8a59a0f83f2..df49210c0a0 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ requires = ["click", "cookiecutter", "networkx", "numpy", "pandas", "tornado", "tqdm"] extras_require = { - "dev": ["black", "coverage", "flake8", "pytest >= 4.6", "pytest-cov", "sphinx"], + "dev": ["black", "ruff", "coverage", "pytest >= 4.6", "pytest-cov", "sphinx"], "docs": ["sphinx", "ipython"], }