Skip to content

Commit 327efd8

Browse files
authored
fix: small bugs, use ruff as linter, added annotations
* fix: ruffing up * test: linting done * fix: tests and code * fix: new docs * docs: updated conf * docs: update
1 parent f0a82a6 commit 327efd8

30 files changed

Lines changed: 6303 additions & 3791 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ main2.py
108108
s3air-authz-config.json
109109
.vscode
110110
_build
111-
111+
.ruff_cache
112+
.DS_Store
112113

113114
test.py

.readthedocs.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
version: 2
22

3+
sphinx:
4+
configuration: docs/source/conf.py
5+
36
build:
4-
os: "ubuntu-22.04"
7+
os: "ubuntu-24.04"
58
tools:
6-
python: "3.12"
9+
python: "3.13"
710
jobs:
811
post_create_environment:
912
- python -m pip install poetry

docs/source/conf.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# python-keycloak documentation build configuration file, created by
54
# sphinx-quickstart on Tue Aug 15 11:02:59 2017.
@@ -101,12 +100,12 @@
101100
# The theme to use for HTML and HTML Help pages. See the documentation for
102101
# a list of builtin themes.
103102
#
104-
html_theme = "sphinx_rtd_theme"
103+
html_theme = "sphinx_book_theme"
105104

106105
# Theme options are theme-specific and customize the look and feel of a theme
107106
# further. For a list of options available for each theme, see the
108107
# documentation.
109-
#
108+
110109
# html_theme_options = {}
111110

112111
# Add any paths that contain custom static files (such as style sheets) here,
@@ -169,7 +168,7 @@
169168
"python-keycloak Documentation",
170169
"Marcos Pereira",
171170
"manual",
172-
)
171+
),
173172
]
174173

175174

@@ -194,5 +193,5 @@
194193
"python-keycloak",
195194
"One line description of project.",
196195
"Miscellaneous",
197-
)
196+
),
198197
]

poetry.lock

Lines changed: 536 additions & 513 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ deprecation = ">=2.1.0"
3737
jwcrypto = ">=1.5.4"
3838
httpx = ">=0.23.2"
3939
async-property = ">=0.2.2"
40+
aiofiles = ">=24.1.0"
4041

4142
[tool.poetry.group.docs.dependencies]
4243
alabaster = ">=0.7.0"
4344
commonmark = ">=0.9.1"
4445
recommonmark = ">=0.7.1"
4546
Sphinx = ">=7.0.0"
46-
sphinx-rtd-theme = ">=1.0.0"
47-
readthedocs-sphinx-ext = ">=2.1.9"
4847
m2r2 = ">=0.3.2"
4948
sphinx-autoapi = ">=3.0.0"
5049
setuptools = ">=70.0.0"
50+
sphinx-book-theme = ">=1.1.3"
5151

5252
[tool.poetry.group.dev.dependencies]
5353
tox = ">=4.0.0"
@@ -56,17 +56,14 @@ pytest-cov = ">=3.0.0"
5656
pytest-asyncio = ">=0.23.7"
5757
wheel = ">=0.38.4"
5858
pre-commit = ">=3.5.0"
59-
isort = ">=5.10.1"
60-
black = ">=22.3.0"
61-
flake8 = ">=7.0.0"
62-
flake8-docstrings = ">=1.6.0"
6359
commitizen = ">=2.28.0"
6460
cryptography = ">=42.0.0"
6561
codespell = ">=2.1.0"
6662
darglint = ">=1.8.1"
6763
twine = ">=4.0.2"
6864
freezegun = ">=1.2.2"
6965
docutils = "<0.21"
66+
ruff = ">=0.9.3"
7067

7168
[[tool.poetry.source]]
7269
name = "PyPI"
@@ -76,15 +73,29 @@ priority = "primary"
7673
requires = ["poetry-core>=1.0.0"]
7774
build-backend = "poetry.core.masonry.api"
7875

79-
[tool.black]
76+
[tool.ruff]
8077
line-length = 99
8178

82-
[tool.isort]
83-
line_length = 99
84-
profile = "black"
79+
[tool.ruff.lint]
80+
select = ["ALL"]
81+
ignore = [
82+
"BLE001",
83+
"C901",
84+
"D203",
85+
"D212",
86+
"FBT001",
87+
"FBT002",
88+
"FBT003",
89+
"N818",
90+
"PLR0912",
91+
"PLR0913",
92+
"PLR0915",
93+
"TRY003",
94+
]
8595

86-
[tool.darglint]
87-
enable = "DAR104"
96+
[tool.ruff.lint.per-file-ignores]
97+
"tests/*" = ["ARG001","PLR2004", "PT011", "S101", "SLF001"]
98+
"docs/*" = ["A001", "EXE001", "ERA001"]
8899

89100
[tool.pytest.ini_options]
90101
asyncio_default_fixture_loop_scope = "function"

src/keycloak/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# The MIT License (MIT)
43
#
@@ -46,8 +45,8 @@
4645
from .openid_connection import KeycloakOpenIDConnection
4746

4847
__all__ = [
49-
"__version__",
5048
"ConnectionManager",
49+
"KeycloakAdmin",
5150
"KeycloakAuthenticationError",
5251
"KeycloakAuthorizationConfigError",
5352
"KeycloakConnectionError",
@@ -56,13 +55,13 @@
5655
"KeycloakError",
5756
"KeycloakGetError",
5857
"KeycloakInvalidTokenError",
58+
"KeycloakOpenID",
59+
"KeycloakOpenIDConnection",
5960
"KeycloakOperationError",
6061
"KeycloakPostError",
6162
"KeycloakPutError",
6263
"KeycloakRPTNotFound",
6364
"KeycloakSecretNotFound",
64-
"KeycloakAdmin",
65-
"KeycloakOpenID",
66-
"KeycloakOpenIDConnection",
6765
"KeycloakUMA",
66+
"__version__",
6867
]

src/keycloak/_version.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# The MIT License (MIT)
43
#

src/keycloak/authorization/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# The MIT License (MIT)
43
#
@@ -32,31 +31,34 @@
3231

3332

3433
class Authorization:
35-
"""Keycloak Authorization (policies, roles, scopes and resources).
34+
"""
35+
Keycloak Authorization (policies, roles, scopes and resources).
3636
3737
https://keycloak.gitbooks.io/documentation/authorization_services/index.html
3838
3939
"""
4040

41-
def __init__(self):
41+
def __init__(self) -> None:
4242
"""Init method."""
4343
self.policies = {}
4444

4545
@property
46-
def policies(self):
47-
"""Get policies.
46+
def policies(self) -> dict:
47+
"""
48+
Get policies.
4849
4950
:returns: Policies
5051
:rtype: dict
5152
"""
5253
return self._policies
5354

5455
@policies.setter
55-
def policies(self, value):
56+
def policies(self, value: dict) -> None:
5657
self._policies = value
5758

58-
def load_config(self, data):
59-
"""Load policies, roles and permissions (scope/resources).
59+
def load_config(self, data: dict) -> None:
60+
"""
61+
Load policies, roles and permissions (scope/resources).
6062
6163
:param data: keycloak authorization data (dict)
6264
:type data: dict

src/keycloak/authorization/permission.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# The MIT License (MIT)
43
#
@@ -25,7 +24,8 @@
2524

2625

2726
class Permission:
28-
"""Base permission class.
27+
"""
28+
Base permission class.
2929
3030
Consider this simple and very common permission:
3131
@@ -56,8 +56,9 @@ class Permission:
5656
5757
"""
5858

59-
def __init__(self, name, type, logic, decision_strategy):
60-
"""Init method.
59+
def __init__(self, name: str, type: str, logic: str, decision_strategy: str) -> None: # noqa: A002
60+
"""
61+
Init method.
6162
6263
:param name: Name
6364
:type name: str
@@ -75,96 +76,104 @@ def __init__(self, name, type, logic, decision_strategy):
7576
self.resources = []
7677
self.scopes = []
7778

78-
def __repr__(self):
79-
"""Repr method.
79+
def __repr__(self) -> str:
80+
"""
81+
Repr method.
8082
8183
:returns: Class representation
8284
:rtype: str
8385
"""
84-
return "<Permission: %s (%s)>" % (self.name, self.type)
86+
return f"<Permission: {self.name} ({self.type})>"
8587

86-
def __str__(self):
87-
"""Str method.
88+
def __str__(self) -> str:
89+
"""
90+
Str method.
8891
8992
:returns: Class string representation
9093
:rtype: str
9194
"""
92-
return "Permission: %s (%s)" % (self.name, self.type)
95+
return f"Permission: {self.name} ({self.type})"
9396

9497
@property
95-
def name(self):
96-
"""Get name.
98+
def name(self) -> str:
99+
"""
100+
Get name.
97101
98102
:returns: name
99103
:rtype: str
100104
"""
101105
return self._name
102106

103107
@name.setter
104-
def name(self, value):
108+
def name(self, value: str) -> None:
105109
self._name = value
106110

107111
@property
108-
def type(self):
109-
"""Get type.
112+
def type(self) -> str:
113+
"""
114+
Get type.
110115
111116
:returns: type
112117
:rtype: str
113118
"""
114119
return self._type
115120

116121
@type.setter
117-
def type(self, value):
122+
def type(self, value: str) -> None:
118123
self._type = value
119124

120125
@property
121-
def logic(self):
122-
"""Get logic.
126+
def logic(self) -> str:
127+
"""
128+
Get logic.
123129
124130
:returns: Logic
125131
:rtype: str
126132
"""
127133
return self._logic
128134

129135
@logic.setter
130-
def logic(self, value):
136+
def logic(self, value: str) -> str:
131137
self._logic = value
132138

133139
@property
134-
def decision_strategy(self):
135-
"""Get decision strategy.
140+
def decision_strategy(self) -> str:
141+
"""
142+
Get decision strategy.
136143
137144
:returns: Decision strategy
138145
:rtype: str
139146
"""
140147
return self._decision_strategy
141148

142149
@decision_strategy.setter
143-
def decision_strategy(self, value):
150+
def decision_strategy(self, value: str) -> None:
144151
self._decision_strategy = value
145152

146153
@property
147-
def resources(self):
148-
"""Get resources.
154+
def resources(self) -> list:
155+
"""
156+
Get resources.
149157
150158
:returns: Resources
151159
:rtype: list
152160
"""
153161
return self._resources
154162

155163
@resources.setter
156-
def resources(self, value):
164+
def resources(self, value: list) -> None:
157165
self._resources = value
158166

159167
@property
160-
def scopes(self):
161-
"""Get scopes.
168+
def scopes(self) -> list:
169+
"""
170+
Get scopes.
162171
163172
:returns: Scopes
164173
:rtype: list
165174
"""
166175
return self._scopes
167176

168177
@scopes.setter
169-
def scopes(self, value):
178+
def scopes(self, value: list) -> None:
170179
self._scopes = value

0 commit comments

Comments
 (0)