Skip to content

Commit

Permalink
make compatible with python 3.7
Browse files Browse the repository at this point in the history
fixed errors and can now build on amazon linux container
  • Loading branch information
thehappycheese committed Feb 11, 2022
1 parent e6747db commit d9cdd75
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ Cargo.lock
.env/
__pycache__/
.pytest_cache/

*-checkpoint.*
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "megalinref"
description = "Find SLK and Road Number from lat/lon (and vice versa) using Main Roads Western Australia open data portal data."
readme = "readme.md"
requires-python = ">=3.9"
requires-python = ">=3.7"
author = "Nicholas Archer"
dependencies = ["pandas", "requests", "arcgis2geojson"]

Expand Down
24 changes: 13 additions & 11 deletions python/megalinref/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from typing import Dict
from .megalinref import (
SLKLookup,
Cwy as _internal_cwy,
NetworkType as _internal_network_type,
)
from ._data_handling import download_fresh_data_as_json

Cwy:dict[str, int] = {
"Left": _internal_cwy["Left"],
"Single": _internal_cwy["Single"],
"Right": _internal_cwy["Right"],
"L": _internal_cwy["Left"],
"S": _internal_cwy["Single"],
"R": _internal_cwy["Right"],
Cwy:Dict[str, int] = {
"Left": _internal_cwy["L"],
"Single": _internal_cwy["S"],
"Right": _internal_cwy["R"],
"L": _internal_cwy["L"],
"S": _internal_cwy["S"],
"R": _internal_cwy["R"],

"All": (
_internal_cwy["Left"] |
_internal_cwy["Single"] |
_internal_cwy["Right"]
_internal_cwy["L"] |
_internal_cwy["S"] |
_internal_cwy["R"]
),
}
"""
Expand All @@ -41,7 +42,8 @@



NetworkType:dict[str, int] = {

NetworkType:Dict[str, int] = {
"State Road": _internal_network_type["State Road"],
"Local Road": _internal_network_type["Local Road"],
"Miscellaneous Road": _internal_network_type["Miscellaneous Road"],
Expand Down
6 changes: 3 additions & 3 deletions python/megalinref/_data_handling.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from typing import Any, Optional
from typing import Any, Optional, Dict
import requests
from arcgis2geojson import arcgis2geojson
import math

DATA_SOURCE_URL = "https://mrgis.mainroads.wa.gov.au/arcgis/rest/services/OpenData/RoadAssets_DataPortal/MapServer/17/query?where=1%3D1&outFields=ROAD,START_SLK,END_SLK,CWY,NETWORK_TYPE,START_TRUE_DIST,END_TRUE_DIST&outSR=4326&f=json"


def download_fresh_data_as_json(url:str=DATA_SOURCE_URL, chunk_limit:Optional[int]=None) -> dict[str, Any]:
def download_fresh_data_as_json(url:str=DATA_SOURCE_URL, chunk_limit:Optional[int]=None) -> Dict[str, Any]:

response = requests.request("GET", f"{url}&returnCountOnly=true")
record_count = response.json()["count"]

print(f"Downloading {record_count} records" + (":" if chunk_limit is None else f", {chunk_limit=}:"))
print(f"Downloading {record_count} records" + (":" if chunk_limit is None else f", chunk_limit={chunk_limit}:"))
if chunk_limit is not None:
print("." * min(chunk_limit, math.floor(record_count/1000)))
else:
Expand Down
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ python -m venv .env
.\.env\Scripts\activate
```

or on linux

```bash
. .env/bin/activate
```

Next we need a build tool called maturin (see documentation [PyO3/maturin](https://github.com/PyO3/maturin)) installed into the virtual environment.

```console
Expand All @@ -125,6 +131,16 @@ pip install pytest

### 5.2. Build using `maturin`

To build on Amazon Linux Container:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
sudo yum update
sudo yum groupinstall "Development Tools"
```

For windows follow the guidance to install Rust on the Rust website.

build for testing using

```console
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn megalinref(py: Python, module: &PyModule) -> PyResult<()> {
("State Road", NetworkType::State_Road as u8),
("Local Road", NetworkType::Local_Road as u8),
("Miscellaneous Road", NetworkType::Miscellaneous_Road as u8),
("Main Roads Controlled_Path", NetworkType::Main_Roads_Controlled_Path as u8),
("Main Roads Controlled Path", NetworkType::Main_Roads_Controlled_Path as u8),
("Proposed Road", NetworkType::Proposed_Road as u8),
("Crossover", NetworkType::Crossover as u8),
]).to_object(py)
Expand Down

0 comments on commit d9cdd75

Please sign in to comment.