Update pygithub to v2

It now has its own default retry logic that fits the GH API,
so no longer pass our own and assume it handles things better.

The datetimes are now timezone aware, so we no longer have to fix
them.
This commit is contained in:
Christoph Reiter 2023-10-16 20:19:18 +02:00
parent 3e0391eb26
commit d1048413f8
4 changed files with 34 additions and 25 deletions

View File

@ -20,7 +20,7 @@ from github.GitRelease import GitRelease
from github.GitReleaseAsset import GitReleaseAsset
from github.Repository import Repository
from .config import REQUESTS_RETRY, REQUESTS_TIMEOUT, BuildType, Config
from .config import REQUESTS_TIMEOUT, BuildType, Config
from .utils import PathLike, get_requests_session
@ -70,7 +70,6 @@ def get_github(write: bool = False) -> Github:
kwargs['auth'] = auth
# 100 is the maximum allowed
kwargs['per_page'] = 100
kwargs['retry'] = REQUESTS_RETRY
kwargs['timeout'] = sum(REQUESTS_TIMEOUT)
gh = Github(**kwargs)
if auth is None and not write:
@ -119,7 +118,7 @@ def wait_for_api_limit_reset(
gh = get_github(write=write)
while True:
core = gh.get_rate_limit().core
reset = fixup_datetime(core.reset)
reset = core.reset
now = datetime.now(timezone.utc)
diff = (reset - now).total_seconds()
print(f"{core.remaining} API calls left (write={write}), "
@ -135,18 +134,10 @@ def wait_for_api_limit_reset(
time.sleep(wait)
def fixup_datetime(dt: datetime) -> datetime:
# pygithub returns datetime objects without a timezone
# https://github.com/PyGithub/PyGithub/issues/1905
assert dt.tzinfo is None
return dt.replace(tzinfo=timezone.utc)
def get_asset_mtime_ns(asset: GitReleaseAsset) -> int:
"""Returns the mtime of an asset in nanoseconds"""
updated_at = fixup_datetime(asset.updated_at)
return int(updated_at.timestamp() * (1000 ** 3))
return int(asset.updated_at.timestamp() * (1000 ** 3))
def download_asset(asset: GitReleaseAsset, target_path: str) -> None:

27
poetry.lock generated
View File

@ -486,20 +486,23 @@ files = [
[[package]]
name = "pygithub"
version = "1.59.1"
version = "2.1.1"
description = "Use the full Github API v3"
optional = false
python-versions = ">=3.7"
files = [
{file = "PyGithub-1.59.1-py3-none-any.whl", hash = "sha256:3d87a822e6c868142f0c2c4bf16cce4696b5a7a4d142a7bd160e1bdf75bc54a9"},
{file = "PyGithub-1.59.1.tar.gz", hash = "sha256:c44e3a121c15bf9d3a5cc98d94c9a047a5132a9b01d22264627f58ade9ddc217"},
{file = "PyGithub-2.1.1-py3-none-any.whl", hash = "sha256:4b528d5d6f35e991ea5fd3f942f58748f24938805cb7fcf24486546637917337"},
{file = "PyGithub-2.1.1.tar.gz", hash = "sha256:ecf12c2809c44147bce63b047b3d2e9dac8a41b63e90fcb263c703f64936b97c"},
]
[package.dependencies]
deprecated = "*"
Deprecated = "*"
pyjwt = {version = ">=2.4.0", extras = ["crypto"]}
pynacl = ">=1.4.0"
python-dateutil = "*"
requests = ">=2.14.0"
typing-extensions = ">=4.0.0"
urllib3 = ">=1.26.0"
[[package]]
name = "pyjwt"
@ -569,6 +572,20 @@ tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""}
[package.extras]
testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
[[package]]
name = "python-dateutil"
version = "2.8.2"
description = "Extensions to the standard Python datetime module"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7"
files = [
{file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"},
{file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"},
]
[package.dependencies]
six = ">=1.5"
[[package]]
name = "requests"
version = "2.31.0"
@ -810,4 +827,4 @@ files = [
[metadata]
lock-version = "2.0"
python-versions = "^3.8.1"
content-hash = "202ed4d57da1bb244bc94bb82dc83741e59803ade0e30ff778a23b09f4b65861"
content-hash = "1a59054d550072ef75be47a53d2f5ada881bf2c6d3cfcc88e2a3f996b91df2ad"

View File

@ -6,7 +6,7 @@ authors = ["Christoph Reiter <reiter.christoph@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.8.1"
PyGithub = "^1.58.0"
PyGithub = "^2.1.1"
tabulate = "^0.9.0"
requests = "^2.28.1"
requests-cache = "^1.0.0"

View File

@ -1,22 +1,23 @@
attrs==23.1.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
cattrs==23.1.2 ; python_full_version >= "3.8.1" and python_version < "4.0"
certifi==2023.7.22 ; python_full_version >= "3.8.1" and python_version < "4.0"
cffi==1.15.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
charset-normalizer==3.2.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
cryptography==41.0.3 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
cffi==1.16.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
charset-normalizer==3.3.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
cryptography==41.0.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
deprecated==1.2.14 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
exceptiongroup==1.1.3 ; python_full_version >= "3.8.1" and python_version < "3.11"
idna==3.4 ; python_full_version >= "3.8.1" and python_version < "4.0"
platformdirs==3.10.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
platformdirs==3.11.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
pycparser==2.21 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
pygithub==1.59.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
pygithub==2.1.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
pyjwt[crypto]==2.8.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
pynacl==1.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
python-dateutil==2.8.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
requests-cache==1.1.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
requests==2.31.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
tabulate==0.9.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
typing-extensions==4.7.1 ; python_full_version >= "3.8.1" and python_version < "3.11"
typing-extensions==4.8.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
url-normalize==1.4.3 ; python_full_version >= "3.8.1" and python_version < "4.0"
urllib3==2.0.4 ; python_full_version >= "3.8.1" and python_version < "4.0"
urllib3==2.0.6 ; python_full_version >= "3.8.1" and python_version < "4.0"
wrapt==1.15.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"