From 32a8dc03419168d226477f6fab1f1f938909d91d Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Thu, 5 Feb 2026 21:06:36 +0600 Subject: [PATCH 1/9] Add Ruff configuration file --- ruff.toml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ruff.toml diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..891e5cf8 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,38 @@ +# Ruff configuration +# https://docs.astral.sh/ruff/configuration/ + +line-length = 120 +target-version = "py38" + +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"] \ No newline at end of file From 13435e5b517db28f9655122c52f9e5d5792c45f5 Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Thu, 5 Feb 2026 21:08:52 +0600 Subject: [PATCH 2/9] Update target version in Ruff configuration to Python 3.9 --- ruff.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruff.toml b/ruff.toml index 891e5cf8..d3fc8058 100644 --- a/ruff.toml +++ b/ruff.toml @@ -2,7 +2,7 @@ # https://docs.astral.sh/ruff/configuration/ line-length = 120 -target-version = "py38" +target-version = "py39" exclude = [ ".git", From 17a19252dd23b8a16975e5ec6593fdc4daae3100 Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Mon, 9 Feb 2026 18:16:21 +0600 Subject: [PATCH 3/9] Replace Flake8 with Ruff for linting in CI and update contribution guidelines --- .github/workflows/python.yml | 15 ++++----------- CONTRIBUTING.md | 6 +++--- requirements/test.txt | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 24d95e6a..37800f3e 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -33,17 +33,10 @@ 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 - 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 + - name: Install Ruff + run: pip install ruff>=0.15.0 + - 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/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 From 84dfe2ece4b2169a139b85554e520953df353665 Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Mon, 9 Feb 2026 18:17:06 +0600 Subject: [PATCH 4/9] Remove Flake8 configuration file as part of replacing Flake8 with Ruff --- .flake8 | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .flake8 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 From 82c6acfe244a0665f485dfc65c0c670cb9d8c12c Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Mon, 9 Feb 2026 18:17:47 +0600 Subject: [PATCH 5/9] ruff autofix --- optimizely/helpers/validator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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(): From 1ddd98dee3268a4421dcda25126e39676379fc04 Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Mon, 9 Feb 2026 18:22:58 +0600 Subject: [PATCH 6/9] testing ruff fail in ci --- optimizely/helpers/validator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/optimizely/helpers/validator.py b/optimizely/helpers/validator.py index 59328331..b9e4fcc5 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 type(user_profile) is not dict: + if not type(user_profile) is 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 type(experiment_bucket_map) is not dict: + if not type(experiment_bucket_map) is dict: return False for decision in experiment_bucket_map.values(): From a7115f42e1195fbb48f8d0deb96b7e5cfee5d7a8 Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Mon, 9 Feb 2026 18:35:12 +0600 Subject: [PATCH 7/9] Fix formatting in ruff.toml by ensuring newline at end of file --- ruff.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruff.toml b/ruff.toml index d3fc8058..5365a7b4 100644 --- a/ruff.toml +++ b/ruff.toml @@ -35,4 +35,4 @@ unfixable = [] "__init__.py" = ["F401"] [lint.isort] -known-first-party = ["optimizely"] \ No newline at end of file +known-first-party = ["optimizely"] From 5c96d0214390d46f62cb7d4e1af21c0d30a98497 Mon Sep 17 00:00:00 2001 From: Farhan Anjum Date: Mon, 9 Feb 2026 18:54:37 +0600 Subject: [PATCH 8/9] Update .github/workflows/python.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/python.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 37800f3e..20894bbb 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -33,8 +33,10 @@ jobs: uses: actions/setup-python@v4 with: python-version: '3.12' - - name: Install Ruff - run: pip install ruff>=0.15.0 + - name: Install dependencies for linting + run: | + python -m pip install --upgrade pip + pip install -r requirements/test.txt - name: Lint with Ruff run: ruff check . From 38237230392eb4d0ef9271df4e0608a54ecaf2ea Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Tue, 10 Feb 2026 19:44:41 +0600 Subject: [PATCH 9/9] ruff fix --- optimizely/helpers/validator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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():