Skip to content

Commit

Permalink
Update pygithub to v2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lazka committed Oct 16, 2023
1 parent 3e0391e commit d104841
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
15 changes: 3 additions & 12 deletions msys2_autobuild/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}), "
Expand All @@ -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:
Expand Down
27 changes: 22 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 8 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit d104841

Please sign in to comment.