Skip to content

Commit

Permalink
Upgrading osdatahub to work with Python 3.12, 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbraybrook committed Nov 18, 2024
1 parent 30cbd19 commit 54c0965
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 100 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [1.2.12] - 2024/11/18
- Resolved issues on installation on later python versions

- Added Support for Python 3.12, 3.13
- Updated Typeguard Version
- Updated Packages to latest versions
- Fixed typing on GeoJson Outputs -> Feature Collection to Dict.

## [1.2.11] - 2024/07/08
- Package Resupported - Supported under new team [jmbraybrook]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[build-system]
requires = ["setuptools>=65.5.1"]
requires = ["setuptools>=75.5.0"]
build-backend = "setuptools.build_meta"

12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
geojson~=3.0.1
requests~=2.31.0
typeguard~=2.13.0
shapely~=2.0.0
tqdm~=4.65.0
setuptools~=67.7.2
geojson~=3.1.0
requests~=2.32.3
typeguard~=4.4.1
shapely~=2.0.6
tqdm~=4.67.0
setuptools~=75.5.0

16 changes: 9 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = osdatahub
version = 1.2.11
version = 1.2.12
author = OS Data Science
author_email = datascience@os.uk
classifiers =
Expand All @@ -12,6 +12,8 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Topic :: Utilities
Topic :: Scientific/Engineering :: GIS
description = osdatahub is Ordnance Survey's (OS) Python API wrapper, designed to make data from the OS Data Hub APIs readily accessible to developers.
Expand All @@ -33,12 +35,12 @@ url = https://github.com/OrdnanceSurvey/osdatahub
[options]
include_package_data = True
install_requires =
geojson~=3.0.1
requests~=2.31.0
typeguard~=2.13.0
shapely~=2.0.0
tqdm~=4.65.0
setuptools~=67.7.2
geojson~=3.1.0
requests~=2.32.3
typeguard~=4.4.1
shapely~=2.0.6
tqdm~=4.67.0
setuptools~=75.5.0
python_requires = >=3.7
package_dir=
=src
Expand Down
4 changes: 2 additions & 2 deletions src/osdatahub/DownloadsAPI/data_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def product_list(self, version_id: str, return_downloadobj: bool = False) -> Uni
def download(self,
version_id: str,
output_dir: Union[str, Path] = ".",
file_name: str = None,
file_name: Union[str, None] = None,
overwrite: bool = False,
processes: int = None) -> list:
processes: Union[int, None] = None) -> list:
"""
Downloads Data Package files to your local machine
Expand Down
12 changes: 9 additions & 3 deletions src/osdatahub/DownloadsAPI/downloads_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def __init__(self, url: str, file_name: str, size: int):
self.file_name = file_name
self.size = size

def download(self, output_dir: Union[str, Path], overwrite: bool = False, pbar: tqdm = None) -> str:
def download(self,
output_dir: Union[str, Path],
overwrite: bool = False,
pbar: Union[tqdm, None] = None) -> str:
"""
Downloads file to given directory
Expand Down Expand Up @@ -179,8 +182,11 @@ def product_list(self):
pass

@staticmethod
def _download(download_list: Union[list, _DownloadObj], output_dir: Union[str, Path], overwrite: bool = False,
download_multiple: bool = False, processes: int = None) -> list:
def _download(download_list: Union[list, _DownloadObj],
output_dir: Union[str, Path],
overwrite: bool = False,
download_multiple: bool = False,
processes: Union[int, None] = None) -> list:
"""
Downloads product/datapackage to the given directory. Can download a single format or can download multiple
formats in parallel
Expand Down
21 changes: 13 additions & 8 deletions src/osdatahub/DownloadsAPI/opendata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ class OpenDataDownload(_DownloadsAPIBase):

# TODO: change name
@typechecked
def product_list(self, file_name: str = None, file_format: str = None, file_subformat: str = None,
area: str = None, return_downloadobj: bool = False) -> Union[list, dict]:
def product_list(self,
file_name: Union[str, None] = None,
file_format: Union[str, None] = None,
file_subformat: Union[str, None] = None,
area: Union[str, None] = None,
return_downloadobj: bool = False) -> Union[list, dict]:
"""
Returns a list of possible downloads for a specific OS OpenData Product based on given filters
Expand Down Expand Up @@ -60,14 +64,15 @@ def product_list(self, file_name: str = None, file_format: str = None, file_subf
else:
return response.json()

def download(self, output_dir: Union[str, Path] = ".",
file_name: str = None,
file_format: str = None,
file_subformat: str = None,
area: str = None,
def download(self,
output_dir: Union[str, Path] = ".",
file_name: Union[str, None] = None,
file_format: Union[str, None] = None,
file_subformat: Union[str, None] = None,
area: Union[str, None] = None,
download_multiple: bool = False,
overwrite: bool = False,
processes: int = None) -> list:
processes: Union[int, None] = None) -> list:
"""
Downloads Product files to your local machine
Expand Down
10 changes: 6 additions & 4 deletions src/osdatahub/FeaturesAPI/features_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import requests
from geojson import FeatureCollection
from typeguard import check_argument_types
from typeguard import typechecked

import osdatahub
from osdatahub.extent import Extent
Expand Down Expand Up @@ -82,6 +82,7 @@ def product(self, product_name: str):
def xml_filter(self):
return self.__construct_filter()

@typechecked
def query(self, limit: int = 100) -> FeatureCollection:
"""Run a query of the OS Features API
Expand All @@ -92,7 +93,7 @@ def query(self, limit: int = 100) -> FeatureCollection:
Returns:
FeatureCollection: The results of the query in GeoJSON format
"""
assert check_argument_types()

params = self.__params
data = GrowList()
n_required = min(limit, 100)
Expand Down Expand Up @@ -138,14 +139,15 @@ def __params(self) -> dict:
"typeName": self.product.name,
"filter": self.__construct_filter(),
}


@typechecked
def add_filters(self, *xml_filters: Filter) -> None:
"""Add XML filter strings to the final query
Args:
xml_filters (str): Valid OGC XML filter objects
"""
assert check_argument_types()

self.filters.extend(xml_filters)


Expand Down
26 changes: 12 additions & 14 deletions src/osdatahub/NGD/ngd_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
from typing import Union

import requests
from geojson import Feature, FeatureCollection
from typeguard import check_argument_types
from typeguard import typechecked

import osdatahub
from osdatahub import Extent
from osdatahub.NGD.crs import get_crs


def _merge_geojsons(gj1: FeatureCollection, gj2: FeatureCollection) -> FeatureCollection:
def _merge_geojsons(gj1: Union[dict], gj2: Union[dict]) -> Union[dict]:
"""
Combines 2 geojsons from NGD api into a single valid geojson
Expand Down Expand Up @@ -84,16 +83,17 @@ def get_collections(cls) -> dict:
response = osdatahub.get(cls.__ENDPOINT, proxies=osdatahub.get_proxies())
response.raise_for_status()
return response.json()


@typechecked
def query(self,
extent: Extent = None,
crs: Union[str, int] = None,
start_datetime: datetime = None,
end_datetime: datetime = None,
cql_filter: str = None,
filter_crs: Union[str, int] = None,
extent: Union[Extent, None] = None,
crs: Union[str, int, None] = None,
start_datetime: Union[datetime, None] = None,
end_datetime: Union[datetime, None] = None,
cql_filter: Union[str, None] = None,
filter_crs: Union[str, int, None] = None,
max_results: int = 100,
offset: int = 0) -> FeatureCollection:
offset: int = 0) -> Union[dict]:
"""
Retrieves features from a Collection
Expand Down Expand Up @@ -123,7 +123,6 @@ def query(self,
FeatureCollection: The results of the query in GeoJSON format
"""

assert check_argument_types()
assert max_results > 0, f"Argument max_results must be greater than 0 but was {max_results}"
assert offset >= 0, f"Argument offset must be greater than 0 but was {offset}"
params = {}
Expand Down Expand Up @@ -183,7 +182,6 @@ def query(self,
raise e

resp_json = response.json()

data = _merge_geojsons(data, resp_json)

if resp_json["numberReturned"] < limit:
Expand All @@ -193,7 +191,7 @@ def query(self,

return data

def query_feature(self, feature_id: str, crs: Union[str, int] = None) -> Feature:
def query_feature(self, feature_id: str, crs: Union[str, int] = None) -> dict:
"""
Retrieves a single feature from a collection
Expand Down
27 changes: 16 additions & 11 deletions src/osdatahub/NamesAPI/names_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from collections.abc import Iterable
from typing import Union

import requests
from geojson import FeatureCollection
from typeguard import check_argument_types
from typeguard import typechecked

import osdatahub
from osdatahub.errors import raise_http_error
Expand Down Expand Up @@ -38,9 +36,13 @@ def __init__(self, key: str):
def __endpoint(self, api_name: str) -> str:
return self.__ENDPOINT + api_name + f"?key={self.key}"

def find(self, text: str, limit: int = 100,
bounds: Extent = None, bbox_filter: Extent = None,
local_type: Union[Iterable, str] = None) -> FeatureCollection:
@typechecked
def find(self,
text: str,
limit: int = 100,
bounds: Union[Extent, None] = None,
bbox_filter: Union[Extent, None] = None,
local_type: Union[Iterable, str, None] = None) -> dict:
"""A free text query of the OS Names API
Args:
Expand All @@ -57,7 +59,6 @@ def find(self, text: str, limit: int = 100,
Returns:
FeatureCollection: The results of the query in GeoJSON format
"""
assert check_argument_types()
data = GrowList()
params = {"query": text}

Expand All @@ -84,7 +85,11 @@ def find(self, text: str, limit: int = 100,
raise_http_error(response)
return addresses_to_geojson(data.values, "EPSG:27700")

def nearest(self, point: tuple, radius: float = 100, local_type: Union[Iterable, str] = None) -> FeatureCollection:
@typechecked
def nearest(self,
point: tuple,
radius: float = 100,
local_type: Union[Iterable, str, None] = None) -> dict:
"""Takes a pair of coordinates (X, Y) as an input
to determine the closest name.
Expand All @@ -98,7 +103,6 @@ def nearest(self, point: tuple, radius: float = 100, local_type: Union[Iterable,
Returns:
FeatureCollection: The results of the query in GeoJSON format
"""
assert check_argument_types()
data = GrowList()
if not all([str(p).isnumeric() for p in point]):
raise TypeError("All values in argument \"point\" must be numeric")
Expand All @@ -117,7 +121,9 @@ def nearest(self, point: tuple, radius: float = 100, local_type: Union[Iterable,
return addresses_to_geojson(data.values, crs="EPSG:27700")

@staticmethod
def __format_fq(bbox_filter: Extent = None, local_type: Union[str, Iterable] = None) -> list:
@typechecked
def __format_fq(bbox_filter: Union[Extent, None] = None,
local_type: Union[str, Iterable, None] = None) -> list:
"""
Formats optional fq arguments for Names API query
Expand All @@ -130,7 +136,6 @@ def __format_fq(bbox_filter: Extent = None, local_type: Union[str, Iterable] = N
Returns:
list of fq filtering arguments
"""
assert check_argument_types()
fq_args = []
if local_type:
# check that all given local types are valid
Expand Down
Loading

0 comments on commit 54c0965

Please sign in to comment.