Skip to content

Commit c837bcc

Browse files
chore: migrate to ruff instead of pycodestyle and isort
1 parent 1d995d9 commit c837bcc

8 files changed

Lines changed: 30 additions & 31 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ upgrade: ## update the requirements/*.txt files with the latest packages satisfy
5858
quality: ## check coding style with pycodestyle and pylint
5959
tox -e quality
6060

61-
format: ## format code with black and isort
61+
format: ## format code with black and isort. Enable ruff to fix E (pycodestyle) and I (isort) issues
6262
ruff format openedx_authz tests --line-length 120
63-
ruff check --select I --fix --line-length 120
63+
ruff check --select E,I --fix --line-length 120
6464

6565
pii_check: ## check for PII annotations on all Django models
6666
tox -e pii_check

openedx_authz/api/roles.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ def get_permissions_for_active_roles_in_scope(
114114
permissions and scopes.
115115
"""
116116
enforcer = AuthzEnforcer.get_enforcer()
117-
filtered_policy = enforcer.get_filtered_grouping_policy(
118-
GroupingPolicyIndex.SCOPE.value, scope.namespaced_key
119-
)
117+
filtered_policy = enforcer.get_filtered_grouping_policy(GroupingPolicyIndex.SCOPE.value, scope.namespaced_key)
120118

121119
if role:
122120
filtered_policy = [
@@ -141,9 +139,7 @@ def get_role_definitions_in_scope(scope: ScopeData) -> list[RoleData]:
141139
list[Role]: A list of roles.
142140
"""
143141
enforcer = AuthzEnforcer.get_enforcer()
144-
policy_filtered = enforcer.get_filtered_policy(
145-
PolicyIndex.SCOPE.value, scope.namespaced_key
146-
)
142+
policy_filtered = enforcer.get_filtered_policy(PolicyIndex.SCOPE.value, scope.namespaced_key)
147143

148144
permissions_per_role = defaultdict(
149145
lambda: {
@@ -185,9 +181,7 @@ def get_all_roles_in_scope(scope: ScopeData) -> list[list[str]]:
185181
list[list[str]]: A list of policies in the specified scope.
186182
"""
187183
enforcer = AuthzEnforcer.get_enforcer()
188-
return enforcer.get_filtered_grouping_policy(
189-
GroupingPolicyIndex.SCOPE.value, scope.namespaced_key
190-
)
184+
return enforcer.get_filtered_grouping_policy(GroupingPolicyIndex.SCOPE.value, scope.namespaced_key)
191185

192186

193187
def assign_role_to_subject_in_scope(subject: SubjectData, role: RoleData, scope: ScopeData) -> bool:
@@ -232,9 +226,7 @@ def unassign_role_from_subject_in_scope(subject: SubjectData, role: RoleData, sc
232226
bool: True if the role was unassigned successfully, False otherwise.
233227
"""
234228
enforcer = AuthzEnforcer.get_enforcer()
235-
return enforcer.delete_roles_for_user_in_domain(
236-
subject.namespaced_key, role.namespaced_key, scope.namespaced_key
237-
)
229+
return enforcer.delete_roles_for_user_in_domain(subject.namespaced_key, role.namespaced_key, scope.namespaced_key)
238230

239231

240232
def batch_unassign_role_from_subjects_in_scope(subjects: list[SubjectData], role: RoleData, scope: ScopeData) -> None:

openedx_authz/settings/common.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ def plugin_settings(settings):
2121
if casbin_adapter_app not in settings.INSTALLED_APPS:
2222
settings.INSTALLED_APPS.append(casbin_adapter_app)
2323
# Add Casbin configuration
24-
settings.CASBIN_MODEL = os.path.join(
25-
ROOT_DIRECTORY, "engine", "config", "model.conf"
26-
)
24+
settings.CASBIN_MODEL = os.path.join(ROOT_DIRECTORY, "engine", "config", "model.conf")
2725
if not hasattr(settings, "CASBIN_AUTO_LOAD_POLICY_INTERVAL"):
2826
settings.CASBIN_AUTO_LOAD_POLICY_INTERVAL = 5

requirements/dev.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ pycasbin==2.2.0
223223
# via
224224
# -r requirements/quality.txt
225225
# casbin-django-orm-adapter
226-
pycodestyle==2.14.0
227-
# via -r requirements/quality.txt
228226
pycparser==2.23
229227
# via
230228
# -r requirements/quality.txt

requirements/quality.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@
55
-r test.txt # Core and testing dependencies for this package
66

77
edx-lint # edX pylint rules and plugins
8-
isort # to standardize order of imports
9-
pycodestyle # PEP 8 compliance validation
108
pydocstyle # PEP 257 compliance validation
119
ruff # Fast Python linter and formatter

requirements/quality.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ iniconfig==2.1.0
122122
# -r requirements/test.txt
123123
# pytest
124124
isort==6.0.1
125-
# via
126-
# -r requirements/quality.in
127-
# pylint
125+
# via pylint
128126
jinja2==3.1.6
129127
# via
130128
# -r requirements/test.txt
@@ -157,8 +155,6 @@ pycasbin==2.2.0
157155
# via
158156
# -r requirements/test.txt
159157
# casbin-django-orm-adapter
160-
pycodestyle==2.14.0
161-
# via -r requirements/quality.in
162158
pycparser==2.23
163159
# via
164160
# -r requirements/test.txt

ruff.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Ruff configuration for openedx-authz
2+
# See https://docs.astral.sh/ruff/configuration/
3+
4+
line-length = 120
5+
6+
[lint]
7+
# E: pycodestyle errors
8+
# I: isort import sorting
9+
select = ["E", "I"]
10+
11+
exclude = [
12+
".git",
13+
".tox",
14+
"migrations",
15+
"__pycache__",
16+
"*.pyc",
17+
]

tox.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ envlist = py{311,312}-django{42,52}
55
; D001 = Line too long
66
ignore = D001
77

8-
[pycodestyle]
9-
exclude = .git,.tox,migrations
10-
max-line-length = 120
8+
[ruff]
9+
# Configuration moved to ruff.toml
10+
# select = E (pycodestyle errors), I (isort)
11+
# max-line-length = 120
1112

1213
[pydocstyle]
1314
; D101 = Missing docstring in public class
@@ -75,9 +76,8 @@ commands =
7576
touch tests/__init__.py
7677
pylint openedx_authz tests test_utils manage.py setup.py
7778
rm tests/__init__.py
78-
pycodestyle openedx_authz tests manage.py setup.py
79+
ruff check openedx_authz tests test_utils manage.py setup.py
7980
pydocstyle openedx_authz tests manage.py setup.py
80-
isort --check-only --diff tests test_utils openedx_authz manage.py setup.py
8181
make selfcheck
8282

8383
[testenv:pii_check]

0 commit comments

Comments
 (0)