diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 0fc0cadc..00000000 --- a/.flake8 +++ /dev/null @@ -1,8 +0,0 @@ -[flake8] -# E722 - do not use bare 'except' -# W504 - Either W503 (Line break after Operand) or W503 ( -# Line break before operand needs to be ignored for line lengths -# greater than max-line-length. Best practice shows W504 -ignore = E722, W504 -exclude = optimizely/lib/pymmh3.py,*virtualenv*,tests/testapp/application.py -max-line-length = 120 diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 24d95e6a..20894bbb 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -33,17 +33,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: '3.12' - # flake8 version should be same as the version in requirements/test.txt - # to avoid lint errors on CI - - name: pip install flak8 - run: pip install flake8>=4.1.0 - - name: Lint with flake8 + - name: Install dependencies for linting run: | - flake8 - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + python -m pip install --upgrade pip + pip install -r requirements/test.txt + - name: Lint with Ruff + run: ruff check . integration_tests: uses: optimizely/python-sdk/.github/workflows/integration_test.yml@master diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d14002e1..9c149710 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ Development process 2. Please follow the [commit message guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines) for each commit message. 3. Make sure to add tests! -4. Run `flake8` to ensure there are no lint errors. +4. Run `ruff check .` to ensure there are no lint errors. 5. `git push` your changes to GitHub. 6. Open a PR from your fork into the master branch of the original repo. @@ -34,12 +34,12 @@ Pull request acceptance criteria - Tests are located in `/tests` with one file per class. - Please don't change the `__version__`. We'll take care of bumping the version when we next release. -- Lint your code with Flake8 before submitting. +- Lint your code with Ruff before submitting. Style ----- -We enforce Flake8 rules. +We enforce Ruff linting rules (Flake8-equivalent: pycodestyle + Pyflakes). License ------- diff --git a/optimizely/helpers/validator.py b/optimizely/helpers/validator.py index b9e4fcc5..59328331 100644 --- a/optimizely/helpers/validator.py +++ b/optimizely/helpers/validator.py @@ -193,7 +193,7 @@ def is_user_profile_valid(user_profile: dict[str, Any]) -> bool: if not user_profile: return False - if not type(user_profile) is dict: + if type(user_profile) is not dict: return False if UserProfile.USER_ID_KEY not in user_profile: @@ -203,7 +203,7 @@ def is_user_profile_valid(user_profile: dict[str, Any]) -> bool: return False experiment_bucket_map = user_profile.get(UserProfile.EXPERIMENT_BUCKET_MAP_KEY) - if not type(experiment_bucket_map) is dict: + if type(experiment_bucket_map) is not dict: return False for decision in experiment_bucket_map.values(): diff --git a/requirements/test.txt b/requirements/test.txt index c2e086c8..c54f5bfa 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,5 +1,5 @@ coverage -flake8 >= 4.0.1 +ruff >= 0.15.0 funcsigs >= 0.4 pytest >= 6.2.0 pytest-cov diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..5365a7b4 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,38 @@ +# Ruff configuration +# https://docs.astral.sh/ruff/configuration/ + +line-length = 120 +target-version = "py39" + +exclude = [ + ".git", + ".venv", + "__pycache__", + "build", + "dist", + "*.egg-info", + "*virtualenv*", + "optimizely/lib/pymmh3.py", + "tests/testapp/application.py", +] + +[lint] +# Flake8-equivalent rules: +# E, W = pycodestyle (style errors & warnings) +# F = Pyflakes (logic errors, undefined names, unused imports) +select = ["E", "W", "F"] + +# Match current flake8 ignores +# E722 - do not use bare 'except' +ignore = ["E722"] + +# Allow autofix for all rules +fixable = ["ALL"] +unfixable = [] + +[lint.per-file-ignores] +# Ignore unused imports in __init__ files +"__init__.py" = ["F401"] + +[lint.isort] +known-first-party = ["optimizely"]