Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

15 changes: 5 additions & 10 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
-------
Expand Down
4 changes: 2 additions & 2 deletions optimizely/helpers/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage
flake8 >= 4.0.1
ruff >= 0.15.0
funcsigs >= 0.4
pytest >= 6.2.0
pytest-cov
Expand Down
38 changes: 38 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -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"]