Skip to content

Commit

Permalink
tests: Update PyJWT requirements
Browse files Browse the repository at this point in the history
- PyJWT < 2.10.0 is required due to
  jpadilla/pyjwt#1017
- increase leeway for mwoauth.identify function because the default
  value of 10.0 seconds is too low sometimes
- add __repr__ method for LoginManager

Bug: T380270
Change-Id: Ie7fadb26f5a3947343feb302f58098d266af2fee
  • Loading branch information
xqt committed Nov 30, 2024
1 parent fa47da3 commit 9c8ba1f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/oauth_tests-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ jobs:
python -m pip install --upgrade pip
pip --version
pip install coverage
# tomli required for coverage due to T380697
pip install "tomli; python_version < '3.11'"
pip install "importlib_metadata ; python_version < '3.8'"
pip install mwparserfromhell
# PyJWT added due to T380270
pip install "PyJWT != 2.10.0 ; python_version > '3.8'"
pip install "PyJWT != 2.10.0, != 2.10.1 ; python_version > '3.8'"
pip install mwoauth
pip install packaging
pip install requests
Expand Down
17 changes: 13 additions & 4 deletions pywikibot/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,12 @@ def access_token(self) -> tuple[str, str] | None:

@property
def identity(self) -> dict[str, Any] | None:
"""Get identifying information about a user via an authorized token."""
"""Get identifying information about a user via an authorized token.
.. versionchanged:: 9.6
*leeway* parameter for ``mwoauth.identify`` function was
increased to 30.0 seconds.
"""
if self.access_token is None:
pywikibot.error('Access token not set')
return None
Expand All @@ -601,8 +606,12 @@ def identity(self) -> dict[str, Any] | None:
access_token = mwoauth.AccessToken(*self.access_token)
try:
identity = mwoauth.identify(self.site.base_url(self.site.path()),
consumer_token, access_token)
return identity
consumer_token,
access_token,
leeway=30.0)
except Exception as e:
pywikibot.error(e)
return None
else:
return identity

return None
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ wikitextparser>=0.47.5
# mwoauth 0.2.4 is needed because it supports getting identity information
# about the user
# Due to T380270 PyJWT must be set
PyJWT != 2.10.0; python_version > '3.8'
PyJWT != 2.10.0, != 2.10.1; python_version > '3.8'
mwoauth>=0.2.4,!=0.3.1

# interwiki_graph.py module and category_graph.py script:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'Pillow>=10.4; python_version >= "3.13"',
],
'mwoauth': [
'PyJWT != 2.10.0; python_version > "3.8"', # T380270
'PyJWT != 2.10.0, != 2.10.1; python_version > "3.8"', # T380270
'mwoauth!=0.3.1,>=0.2.4',
],
'html': ['beautifulsoup4>=4.7.1'],
Expand Down

0 comments on commit 9c8ba1f

Please sign in to comment.