Browse Source

Cope with Protocol not being available on Python 3.8

Jelmer Vernooij 2 years ago
parent
commit
d1ba2d4778
5 changed files with 26 additions and 9 deletions
  1. 5 6
      .github/workflows/pythontest.yml
  2. 6 1
      dulwich/object_store.py
  3. 7 1
      dulwich/pack.py
  4. 7 1
      dulwich/server.py
  5. 1 0
      setup.cfg

+ 5 - 6
.github/workflows/pythontest.yml

@@ -31,19 +31,17 @@ jobs:
       - name: Install dependencies
         run: |
           python -m pip install --upgrade pip
-          pip install -U pip coverage flake8 fastimport paramiko urllib3
+          pip install -U ".[fastimport,paramiko,https]"
       - name: Install gpg on supported platforms
-        run: pip install -U gpg
+        run: pip install -U ".[pgp]"
         if: "matrix.os != 'windows-latest' && matrix.python-version != 'pypy3'"
-      - name: Install mypy
-        run: |
-          pip install -U mypy types-paramiko types-requests
-        if: "matrix.python-version != 'pypy3'"
       - name: Style checks
         run: |
+          pip install -U flake8
           python -m flake8
       - name: Typing checks
         run: |
+          pip install -U mypy types-paramiko types-requests
           python -m mypy dulwich
         if: "matrix.python-version != 'pypy3'"
       - name: Build
@@ -51,4 +49,5 @@ jobs:
           python setup.py build_ext -i
       - name: Coverage test suite run
         run: |
+          pip install -U coverage
           python -m coverage run -p -m unittest dulwich.tests.test_suite

+ 6 - 1
dulwich/object_store.py

@@ -28,7 +28,12 @@ import stat
 import sys
 import warnings
 
-from typing import Callable, Dict, List, Optional, Tuple, Protocol, Iterator, Set, Iterable, Sequence, cast
+from typing import Callable, Dict, List, Optional, Tuple, Iterator, Set, Iterable, Sequence, cast
+
+try:
+    from typing import Protocol
+except ImportError:  # python << 3.8
+    from typing_extensions import Protocol  # type: ignore
 
 from dulwich.errors import (
     NotTreeError,

+ 7 - 1
dulwich/pack.py

@@ -50,7 +50,13 @@ from itertools import chain
 
 import os
 import sys
-from typing import Optional, Callable, Tuple, List, Deque, Union, Protocol, Iterable, Iterator, Dict, TypeVar, Generic, Sequence, Set
+from typing import Optional, Callable, Tuple, List, Deque, Union, Iterable, Iterator, Dict, TypeVar, Generic, Sequence, Set
+
+try:
+    from typing import Protocol
+except ImportError:  # python << 3.8
+    from typing_extensions import Protocol   # type: ignore
+
 import warnings
 
 from hashlib import sha1

+ 7 - 1
dulwich/server.py

@@ -48,7 +48,13 @@ import os
 import socket
 import sys
 import time
-from typing import List, Tuple, Dict, Optional, Iterable, Set, Protocol as TypingProtocol
+from typing import List, Tuple, Dict, Optional, Iterable, Set
+
+try:
+    from typing import Protocol as TypingProtocol
+except ImportError:  # python < 3.8
+    from typing_extensions import Protocol as TypingProtocol  # type: ignore
+
 import zlib
 
 import socketserver

+ 1 - 0
setup.cfg

@@ -52,6 +52,7 @@ packages =
 include_package_data = True
 install_requires =
     urllib3>=1.25
+    typing_extensions;python_version<="3.7"
 zip_safe = False
 scripts =
     bin/dul-receive-pack