Skip to content

Commit

Permalink
Make it work back to Python 3.7 for prebuilt Giftless compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
athornton committed Jun 30, 2023
1 parent 85c2b40 commit 09738a3
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: check-toml

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.11.5
hooks:
- id: isort
additional_dependencies: [toml]
Expand All @@ -18,6 +18,6 @@ repos:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 5.0.4
hooks:
- id: flake8
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Intended Audience :: Developers",
"Natural Language :: English",
"Operating System :: POSIX",
"Typing :: Typed",
]
requires-python = ">=3.10"
requires-python = ">=3.7,<3.11"
# Use requirements/main.in for runtime dependencies instead.
dependencies = []
dynamic = ["version"]
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coverage[toml]
isort
mypy
pytest
pytest-cov
46 changes: 44 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# This file is autogenerated by pip-compile with Python 3.7
# by the following command:
#
# pip-compile --generate-hashes --output-file=requirements/dev.txt --resolver=backtracking requirements/dev.in
Expand Down Expand Up @@ -72,10 +72,20 @@ exceptiongroup==1.1.1 \
--hash=sha256:232c37c63e4f682982c8b6459f33a8981039e5fb8756b2074364e5055c498c9e \
--hash=sha256:d484c3090ba2889ae2928419117447a14daf3c1231d5e30d0aae34f354f01785
# via pytest
importlib-metadata==6.7.0 \
--hash=sha256:1aaf550d4f73e5d6783e7acb77aec43d49da8017410afae93822cc9cca98c4d4 \
--hash=sha256:cb52082e659e97afc5dac71e79de97d8681de3aa07ff18578330904a9d18e5b5
# via
# pluggy
# pytest
iniconfig==2.0.0 \
--hash=sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3 \
--hash=sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374
# via pytest
isort==5.11.5 \
--hash=sha256:6be1f76a507cb2ecf16c7cf14a37e41609ca082330be4e3436a18ef74add55db \
--hash=sha256:ba1d72fb2595a01c7895a5128f9585a5cc4b6d395f1c8d514989b9a7eb2a8746
# via -r requirements/dev.in
mypy==1.4.1 \
--hash=sha256:01fd2e9f85622d981fd9063bfaef1aed6e336eaacca00892cd2d82801ab7c042 \
--hash=sha256:0dde1d180cd84f0624c5dcaaa89c89775550a675aff96b5848de78fb11adabcd \
Expand Down Expand Up @@ -133,7 +143,39 @@ tomli==2.0.1 \
# coverage
# mypy
# pytest
typed-ast==1.5.4 \
--hash=sha256:0261195c2062caf107831e92a76764c81227dae162c4f75192c0d489faf751a2 \
--hash=sha256:0fdbcf2fef0ca421a3f5912555804296f0b0960f0418c440f5d6d3abb549f3e1 \
--hash=sha256:183afdf0ec5b1b211724dfef3d2cad2d767cbefac291f24d69b00546c1837fb6 \
--hash=sha256:211260621ab1cd7324e0798d6be953d00b74e0428382991adfddb352252f1d62 \
--hash=sha256:267e3f78697a6c00c689c03db4876dd1efdfea2f251a5ad6555e82a26847b4ac \
--hash=sha256:2efae9db7a8c05ad5547d522e7dbe62c83d838d3906a3716d1478b6c1d61388d \
--hash=sha256:370788a63915e82fd6f212865a596a0fefcbb7d408bbbb13dea723d971ed8bdc \
--hash=sha256:39e21ceb7388e4bb37f4c679d72707ed46c2fbf2a5609b8b8ebc4b067d977df2 \
--hash=sha256:3e123d878ba170397916557d31c8f589951e353cc95fb7f24f6bb69adc1a8a97 \
--hash=sha256:4879da6c9b73443f97e731b617184a596ac1235fe91f98d279a7af36c796da35 \
--hash=sha256:4e964b4ff86550a7a7d56345c7864b18f403f5bd7380edf44a3c1fb4ee7ac6c6 \
--hash=sha256:639c5f0b21776605dd6c9dbe592d5228f021404dafd377e2b7ac046b0349b1a1 \
--hash=sha256:669dd0c4167f6f2cd9f57041e03c3c2ebf9063d0757dc89f79ba1daa2bfca9d4 \
--hash=sha256:6778e1b2f81dfc7bc58e4b259363b83d2e509a65198e85d5700dfae4c6c8ff1c \
--hash=sha256:683407d92dc953c8a7347119596f0b0e6c55eb98ebebd9b23437501b28dcbb8e \
--hash=sha256:79b1e0869db7c830ba6a981d58711c88b6677506e648496b1f64ac7d15633aec \
--hash=sha256:7d5d014b7daa8b0bf2eaef684295acae12b036d79f54178b92a2b6a56f92278f \
--hash=sha256:98f80dee3c03455e92796b58b98ff6ca0b2a6f652120c263efdba4d6c5e58f72 \
--hash=sha256:a94d55d142c9265f4ea46fab70977a1944ecae359ae867397757d836ea5a3f47 \
--hash=sha256:a9916d2bb8865f973824fb47436fa45e1ebf2efd920f2b9f99342cb7fab93f72 \
--hash=sha256:c542eeda69212fa10a7ada75e668876fdec5f856cd3d06829e6aa64ad17c8dfe \
--hash=sha256:cf4afcfac006ece570e32d6fa90ab74a17245b83dfd6655a6f68568098345ff6 \
--hash=sha256:ebd9d7f80ccf7a82ac5f88c521115cc55d84e35bf8b446fcd7836eb6b98929a3 \
--hash=sha256:ed855bbe3eb3715fca349c80174cfcfd699c2f9de574d40527b8429acae23a66
# via mypy
typing-extensions==4.7.0 \
--hash=sha256:5d8c9dac95c27d20df12fb1d97b9793ab8b2af8a3a525e68c80e21060c161771 \
--hash=sha256:935ccf31549830cda708b42289d44b6f74084d616a00be651601a4f968e77c82
# via mypy
# via
# importlib-metadata
# mypy
zipp==3.15.0 \
--hash=sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b \
--hash=sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556
# via importlib-metadata
39 changes: 24 additions & 15 deletions requirements/main.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# This file is autogenerated by pip-compile with Python 3.7
# by the following command:
#
# pip-compile --generate-hashes --output-file=requirements/main.txt --resolver=backtracking requirements/main.in
#
blinker==1.6.2 \
--hash=sha256:4afd3de66ef3a9f8067559fb7a1cbe555c17dcbe15971b05d1b625c3e7abe213 \
--hash=sha256:c3d739772abb7bc2860abf5f2ec284223d9ad5c76da018234f6f50d6f31ab1f0
# via flask
certifi==2023.5.7 \
--hash=sha256:0f0d56dc5a6ad56fd4ba36484d6cc34451e1c6548c61daad8c320169f91eddc7 \
--hash=sha256:c6c2e98f5c7869efca1f8916fed228dd91539f9f1b444c314c06eef02980c716
Expand Down Expand Up @@ -190,9 +186,9 @@ figcan==0.0.4 \
--hash=sha256:58f38c21f214cc5e26d631391c219febe96502dbf4389211145ee69a44bc5ebe \
--hash=sha256:c41169803f9885b614fba674a564c7085495c8ed38fff55949362d9f08f48a9f
# via giftless
flask==2.3.2 \
--hash=sha256:77fd4e1249d8c9923de34907236b747ced06e5467ecac1a7bb7115ae0e9670b0 \
--hash=sha256:8c2f9abd47a9e8df7f0c3f091ce9497d011dc3b31effcf4c85a6e2b50f4114ef
flask==2.2.5 \
--hash=sha256:58107ed83443e86067e41eff4631b058178191a355886f8e479e347fa1285fdf \
--hash=sha256:edee9b0a7ff26621bd5a8c10ff484ae28737a2410d99b0bb9a6850c7fb977aa0
# via
# flask-classful
# flask-marshmallow
Expand All @@ -213,6 +209,12 @@ idna==3.4 \
--hash=sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4 \
--hash=sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2
# via requests
importlib-metadata==6.7.0 \
--hash=sha256:1aaf550d4f73e5d6783e7acb77aec43d49da8017410afae93822cc9cca98c4d4 \
--hash=sha256:cb52082e659e97afc5dac71e79de97d8681de3aa07ff18578330904a9d18e5b5
# via
# click
# flask
itsdangerous==2.1.2 \
--hash=sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44 \
--hash=sha256:5dbbc68b317e5e42f327f9021763545dc3fc3bfe22e6deb96aaf1fc38874156a
Expand Down Expand Up @@ -319,9 +321,9 @@ pynacl==1.5.0 \
--hash=sha256:a422368fc821589c228f4c49438a368831cb5bbc0eab5ebe1d7fac9dded6567b \
--hash=sha256:e46dae94e34b085175f8abb3b0aaa7da40767865ac82c928eeb9e57e1ea8a543
# via pygithub
python-dotenv==1.0.0 \
--hash=sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba \
--hash=sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a
python-dotenv==0.21.1 \
--hash=sha256:1c93de8f636cde3ce377292818d0e440b6e45a82f215c3744979151fa8151c49 \
--hash=sha256:41e12e0318bebc859fcc4d97d4db8d20ad21721a6aa5047dd59f090391cb549a
# via giftless
pyyaml==6.0 \
--hash=sha256:01b45c0191e6d66c470b6cf1b9531a771a83c1c4208272ead47a3ae4f2f603bf \
Expand Down Expand Up @@ -372,7 +374,10 @@ requests==2.31.0 \
typing-extensions==4.7.0 \
--hash=sha256:5d8c9dac95c27d20df12fb1d97b9793ab8b2af8a3a525e68c80e21060c161771 \
--hash=sha256:935ccf31549830cda708b42289d44b6f74084d616a00be651601a4f968e77c82
# via giftless
# via
# giftless
# importlib-metadata
# pyjwt
urllib3==2.0.3 \
--hash=sha256:48e7fafa40319d358848e1bc6809b208340fafe2096f1725d05d67443d0483d1 \
--hash=sha256:bee28b5e56addb8226c96f7f13ac28cb4c301dd5ea8a6ca179c0b9835e032825
Expand All @@ -381,9 +386,9 @@ webargs==8.2.0 \
--hash=sha256:6746327faf549533bf30be7333f99541b6c60a85f23acf1bb0bea68498e3bcd7 \
--hash=sha256:99d68940c452e07726485a15fef43f12f8ae6c0c5b391bcba76065d4527fb85d
# via giftless
werkzeug==2.3.6 \
--hash=sha256:935539fa1413afbb9195b24880778422ed620c0fc09670945185cce4d91a8890 \
--hash=sha256:98c774df2f91b05550078891dee5f0eb0cb797a522c757a2452b9cee5b202330
werkzeug==2.2.3 \
--hash=sha256:2e1ccc9417d4da358b9de6f174e3ac094391ea1d4fbef2d667865d819dfd0afe \
--hash=sha256:56433961bc1f12533306c624f3be5e744389ac61d722175d543e1751285da612
# via flask
wrapt==1.15.0 \
--hash=sha256:02fce1852f755f44f95af51f69d22e45080102e9d00258053b79367d07af39c0 \
Expand Down Expand Up @@ -462,3 +467,7 @@ wrapt==1.15.0 \
--hash=sha256:fbec11614dba0424ca72f4e8ba3c420dba07b4a7c206c8c8e4e73f2e98f4c559 \
--hash=sha256:fd69666217b62fa5d7c6aa88e507493a34dec4fa20c5bd925e4bc12fce586639
# via deprecated
zipp==3.15.0 \
--hash=sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b \
--hash=sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556
# via importlib-metadata
4 changes: 2 additions & 2 deletions src/giftless_github_proxy_auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime
import logging
import os
from typing import Any
from typing import Any, Optional

import giftless
import github
Expand Down Expand Up @@ -32,7 +32,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
else:
self._logger.setLevel(logging.INFO)

def __call__(self, request: Request) -> Identity | None:
def __call__(self, request: Request) -> Optional[Identity]:
# Get the repo name
parts = request.path.split("/")
org = parts[0]
Expand Down
6 changes: 4 additions & 2 deletions src/giftless_github_proxy_auth/cache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Dict, Optional

from giftless.auth.identity import Identity


Expand All @@ -8,7 +10,7 @@ class AuthenticationCache:
just an in-memory data structure."""

def __init__(self) -> None:
self._authed: dict[str, Identity] = {}
self._authed: Dict[str, Identity] = {}

async def add(self, token: str, identity: Identity) -> None:
self._authed[token] = identity
Expand All @@ -17,5 +19,5 @@ async def remove(self, token: str) -> None:
if token in self._authed:
del self._authed[token]

async def check(self, token: str) -> Identity | None:
async def check(self, token: str) -> Optional[Identity]:
return self._authed.get(token)
7 changes: 4 additions & 3 deletions src/giftless_github_proxy_auth/identity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
from dataclasses import dataclass
from typing import Dict, Optional

import giftless
from giftless.auth.identity import Permission
Expand All @@ -22,14 +23,14 @@ def __init__(
) -> None:
self.name = name
self._expiration = expiration
self._auth: dict[str, RepoAccess] = {}
self._auth: Dict[str, RepoAccess] = {}

def is_authorized(
self,
organization: str,
repo: str,
permission: Permission,
oid: str | None,
oid: Optional[str],
) -> bool:
# We assume all our stuff is publicly readable. So far, that's true.
if permission != Permission.WRITE:
Expand All @@ -53,7 +54,7 @@ def deauthorize_for_repo(self, repo_str: str) -> None:
can_write=False, checked_time=datetime.datetime.now()
)

def check_repo(self, repo_str: str) -> RepoAccess | None:
def check_repo(self, repo_str: str) -> Optional[RepoAccess]:
"""This lets us check for the unknown state and expiration too."""
state = self._auth.get(repo_str)
if state is None:
Expand Down

0 comments on commit 09738a3

Please sign in to comment.