Skip to content

Commit be6e890

Browse files
colsiljulienr
authored andcommitted
Make the library compatible with older python versions
The main issues were mostly typing annotations, so by importing annotations from __future__ and doing some conditional imports we can maintain backwards compatibility for longer
1 parent c859958 commit be6e890

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

.github/workflows/lint_test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: ['3.10', '3.12']
13+
python-version: ['3.7', '3.10', '3.12']
1414

1515
steps:
1616
- uses: actions/checkout@v2
@@ -38,6 +38,8 @@ jobs:
3838
# therefore fail on warnings that could be ignored by readthedocs and
3939
# lead to half-broken docs
4040
- name: build docs
41+
# This should make the version in .readthedocs.yaml in the repository root
42+
if: matrix.python-version == '3.12'
4143
run: |
4244
cd docs
4345
python -m pip install -r requirements.txt

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
# read the contents of your README file
4+
import sys
45
from pathlib import Path
5-
66
from setuptools import find_packages, setup
77

88
this_directory = Path(__file__).parent
99
long_description = (this_directory / "README.md").read_text()
1010

11-
lint_deps = ["flake8", "mypy==1.8.0", "types-requests"]
11+
if sys.version_info >= (3, 8):
12+
lint_deps = ["flake8", "mypy==1.8.0", "types-requests"]
13+
else:
14+
lint_deps = ["flake8", "mypy==1.4.1", "types-requests"]
1215
test_deps = ["pytest==7.1", "responses==0.22", "httpretty"]
1316

1417
setup(

src/picterra/base_client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
from __future__ import annotations
2+
13
import json
24
import logging
35
import os
6+
import sys
47
import time
58
from collections.abc import Callable
6-
from typing import Any, Generic, Iterator, Literal, TypedDict, TypeVar
9+
if sys.version_info >= (3, 8):
10+
from typing import Literal, TypedDict
11+
else:
12+
from typing_extensions import Literal, TypedDict
13+
from typing import Any, Generic, Iterator, TypeVar
714
from urllib.parse import urlencode, urljoin
815

916
import requests

src/picterra/detector_platform_client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55
Note that that Detector platform is a separate product from the Plots Analysis platform and so
66
an API key which is valid for one may encounter permissions issues if used with the other
77
"""
8+
from __future__ import annotations
9+
810
import json
911
import logging
12+
import sys
1013
import tempfile
1114
import warnings
12-
from typing import Any, Literal
15+
if sys.version_info >= (3, 8):
16+
from typing import Literal
17+
else:
18+
from typing_extensions import Literal
19+
from typing import Any
1320

1421
import requests
1522

src/picterra/plots_analysis_platform_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
an API key which is valid for one may encounter permissions issues if used with the other
77
"""
88
import datetime
9-
from typing import Literal
9+
import sys
10+
11+
if sys.version_info >= (3, 8):
12+
from typing import Literal
13+
else:
14+
from typing_extensions import Literal
1015

1116
import requests
1217
from requests.exceptions import RequestException

0 commit comments

Comments
 (0)