Skip to content

Commit

Permalink
build universal
Browse files Browse the repository at this point in the history
  • Loading branch information
gmweaver committed Jun 5, 2024
1 parent dfc3182 commit 3819dad
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_SKIP: cp36-* cp37-* *musllinux*
CIBW_ARCHS_MACOS: "x86_64 universal2"
CIBW_BEFORE_ALL_LINUX: yum install -y autoconf automake curl libtool sudo
CIBW_BEFORE_ALL_MACOS: brew install autoconf automake curl libtool pkg-config

Expand Down
11 changes: 0 additions & 11 deletions install_libpostal.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

OS=$(uname -s)
ARCH=$(uname -m)

case $OS in
Linux)
Expand All @@ -22,16 +21,6 @@ case $OS in
;;
esac

if [ "$OS" = "Linux" ]; then
sudo apt-get install clang curl autoconf automake libtool pkg-config
elif [ "$OS" = "Darwin" ]; then
if [ "$ARCH" == "arm64" ]; then
arch -arm64 brew install curl autoconf automake libtool pkg-config
else
brew install curl autoconf automake libtool pkg-config
fi
fi

cd $1
git clone https://github.com/openvenues/libpostal
cd libpostal
Expand Down
18 changes: 12 additions & 6 deletions libpypostal/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from enum import Enum
from typing import Dict, List, Optional, Tuple

from libpypostal import _parser # type: ignore # pylint: disable=no-name-in-module


class LibpostalAddressComponent(str, Enum):
"""Libpostal address component."""
Expand All @@ -30,6 +28,16 @@ class LibpostalAddressComponent(str, Enum):
WORLD_REGION = "world_region"


def _parse_address(
address: str, language: str, country_code: str
) -> List[Tuple[str, str]]:
from libpypostal import _parser # type: ignore # pylint: disable=no-name-in-module,import-outside-toplevel

return _parser.parse_address( # pylint: disable=c-extension-no-member
address, language=language, country=country_code
)


def parse_address(
address: str, language: Optional[str] = None, country_code: Optional[str] = None
) -> Dict[str, List[str]]:
Expand All @@ -46,10 +54,8 @@ def parse_address(
possibility of multiple matches. Address components not found in the input are
set to empty lists.
"""
address_component_tuples: List[
Tuple[str, str]
] = _parser.parse_address( # pylint: disable=c-extension-no-member
address, language=language, country=country_code
address_component_tuples = _parse_address(
address, language=language, country_code=country_code
)

parsed_address_components: Dict[str, List[str]] = {}
Expand Down
Empty file added tests/__init__.py
Empty file.
93 changes: 93 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# pylint: disable=missing-module-docstring,missing-function-docstring,
from unittest.mock import MagicMock, patch

from libpypostal import parser


@patch("libpypostal._parse_address")
def test_parse_address_single_match_each_component(
mock__parser_parse_address: MagicMock,
) -> None:
test_address = "123 Bayes Way, Beverly Hills, CA 90210 US"
mock__parser_parse_address.return_value = [
("123", "house_number"),
("bayes way", "road"),
("beverly hills", "city"),
("ca", "state"),
("90210", "postcode"),
("us", "country"),
]
expected = {
"house_number": ["123"],
"road": ["bayes way"],
"city": ["beverly hills"],
"state": ["ca"],
"postcode": ["90210"],
"country": ["us"],
"category": [],
"city_district": [],
"country_region": [],
"entrance": [],
"house": [],
"island": [],
"level": [],
"near": [],
"po_box": [],
"staircase": [],
"state_district": [],
"suburb": [],
"unit": [],
"world_region": [],
}

actual = parser.parse_address(test_address)

assert actual == expected
mock__parser_parse_address.assert_called_once_with(
test_address, language=None, country=None
)


@patch("libpypostal._parse_address")
def test_parse_address_multiple_matches_for_component(
mock__parser_parse_address: MagicMock,
) -> None:
test_address = "123 Bayes Way, Beverly Hills, CA 90210 California US"
mock__parser_parse_address.return_value = [
("123", "house_number"),
("bayes way", "road"),
("beverly hills", "city"),
("ca", "state"),
("california", "state"),
("90210", "postcode"),
("us", "country"),
]
expected = {
"house_number": ["123"],
"road": ["bayes way"],
"city": ["beverly hills"],
"state": ["ca", "california"],
"postcode": ["90210"],
"country": ["us"],
"category": [],
"city_district": [],
"country_region": [],
"entrance": [],
"house": [],
"island": [],
"level": [],
"near": [],
"po_box": [],
"staircase": [],
"state_district": [],
"suburb": [],
"unit": [],
"world_region": [],
}

actual = parser.parse_address(test_address)

assert actual == expected
mock__parser_parse_address.assert_called_once_with(
test_address, language=None, country=None
)

0 comments on commit 3819dad

Please sign in to comment.