Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyproject.toml #9

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Build
name: tests

on:
push:
branches: [ master ]
branches:
- '*'
pull_request:
branches: [ master ]
branches:
- '*'

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install pytest types-setuptools mypy
- name: Run mypy
python -m pip install ".[dev]"
- name: Run ruff linter
run: |
mypy iceaddr/*.py
ruff src/iceaddr
- name: Test with pytest
run: |
python -m pytest

python -m pytest -vvv



Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __pycache__/
*.py[cod]
*$py.class/
/dist/
/*.egg-info
*.egg-info
*.shp
p3*/
/stadfangaskra.db
Expand All @@ -17,3 +17,6 @@ venv
*.zip
*.csv
.vscode
*.pyc
.coverage
.coverage.*
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# iceaddr

[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-370/)
[![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/downloads/release/python-380/)
[![Release](https://shields.io/github/v/release/sveinbjornt/iceaddr?display_name=tag)]()
[![PyPI](https://img.shields.io/pypi/v/iceaddr)]()
[![Build](https://github.com/sveinbjornt/iceaddr/actions/workflows/python-package.yml/badge.svg)]()

### Look up Icelandic street addresses, postcodes and placenames

`iceaddr` is a Python 3.7+ package to look up information about Icelandic streets, addresses, placenames,
`iceaddr` is a Python >=3.8 package to look up information about Icelandic streets, addresses, placenames,
landmarks, locations and postcodes. The underlying data is contained in a local SQLite database assembled
from the following sources:

Expand Down Expand Up @@ -118,7 +118,7 @@ in the database:
```python
>>> from iceaddr import nearest_addr
>>> addr = nearest_addr(64.148446, -21.944933)[0]
>>> print("{0} {1}".format(addr["heiti_nf"], addr["husnr"]))
>>> print(f"{addr['heiti_nf']} {addr['husnr']}")
Öldugata 2
```

Expand Down Expand Up @@ -243,7 +243,7 @@ Landakotsvöllur

## Build process

To build your own version of the package, you need to have Python 3.7+ installed.
To build your own version of the package, you need to have Python >=3.8 installed.
Then, after optionally creating a virtual environment, run the following command
from the repository root to install dependencies:

Expand All @@ -269,6 +269,7 @@ python setup.py install

## Version History

* 0.5.7: Updated address and placename data. Now requires Python 3.8+ (18/09/2024)
* 0.5.6: Updated address and placename data. (11/08/2023)
* 0.5.5: Updated address and placename data. Removed ISN93 coords. Now requires Python 3.7+ (11/12/2022)
* 0.5.4: Updated address and placename data (09/11/2022)
Expand Down
12 changes: 6 additions & 6 deletions add_placename_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

from typing import List, Tuple

from pprint import pprint
from pprint import pprint # type: ignore
import sqlite3
from pathlib import Path

import fiona
import fiona # type: ignore

from iceaddr.dist import in_iceland

Expand All @@ -30,7 +30,7 @@
DEFAULT_DBNAME = "iceaddr.db"


def center_point(coords: List[Tuple]) -> Tuple[float, float]:
def center_point(coords: List[Tuple[float, float]]) -> Tuple[float, float]:
"""Find the center point of a given set of coordinates."""
x: float = 0
y: float = 0
Expand Down Expand Up @@ -83,7 +83,7 @@ def delete_table(dbpath: str) -> sqlite3.Connection:
return dbconn


def add_placename_additions(dbc) -> None:
def add_placename_additions(dbc: sqlite3.Connection) -> None:
"""Read manual placename additions from text file, insert into "ornefni" DB table."""
print("Inserting placename additions")
f = open("placename_additions.txt", "r")
Expand Down Expand Up @@ -114,7 +114,7 @@ def add_placename_additions(dbc) -> None:
dbc.commit()


def add_placenames_from_is50v(dbc) -> None:
def add_placenames_from_is50v(dbc: sqlite3.Connection) -> None:
"""Read IS50V geo layers from file, add all placenames ("örnefni") to DB."""
if not Path(GPKG_FILE).exists():
print(f"Could not find file {GPKG_FILE}")
Expand Down Expand Up @@ -154,7 +154,7 @@ def add_placenames_from_is50v(dbc) -> None:
# Special handling of flakes - use center point
elif type(c) is list:
if not c:
# print("Faulty flake: {0}".format(n))
# print(f"Faulty flake: {n}")
# pprint(i)
# raise
continue
Expand Down
14 changes: 8 additions & 6 deletions build_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

"""

from typing import Iterator, Dict
from typing import Iterator, Dict, Any

from builtins import input

Expand All @@ -23,7 +23,7 @@
from urllib.request import urlopen
from iceaddr.dist import in_iceland

import humanize
import humanize # type: ignore


STADFONG_REMOTE_URL = "https://fasteignaskra.is/Stadfangaskra.csv"
Expand Down Expand Up @@ -76,13 +76,15 @@ def create_db(path: str) -> sqlite3.Connection:
return dbconn


def read_rows(dsv_file: TextIOWrapper, delimiter: str = ",") -> Iterator:
def read_rows(
dsv_file: TextIOWrapper, delimiter: str = ","
) -> Iterator[Dict[Any, Any]]:
reader = csv.DictReader(dsv_file, delimiter=delimiter)
for row in reader:
yield row


def insert_address_entry(e: Dict, conn: sqlite3.Connection) -> None:
def insert_address_entry(e: Dict[Any, Any], conn: sqlite3.Connection) -> None:
# The stadfong datafile is quite dirty so we need to
# sanitise values before inserting into the database

Expand Down Expand Up @@ -164,8 +166,8 @@ def main() -> None:
print("\tInserting: %d\r" % cnt, end="")
sys.stdout.flush()

bytesize = os.stat(db_path).st_size
human_size = humanize.naturalsize(bytesize)
bytesize: int = os.stat(db_path).st_size
human_size = humanize.naturalsize(bytesize) # type: ignore

print("\nCreated database with %d entries (%s)" % (cnt, human_size))

Expand Down
14 changes: 6 additions & 8 deletions build_postcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,29 @@ def main() -> None:
# the dative form (þgf.). Try to lemmatise to nominative (nf.) using Reynir.
postcode = int(r["Póstnúmer"])
if postcode not in pc_keys:
logging.warning(
"Postcode '{0}' did not already exist in data.".format(postcode)
)
logging.warning(f"Postcode '{postcode}' did not already exist in data.")
changed = True

tp = r["Tegund"]
p_dat = _clean_name(r["Staður"])
p_nom = NounPhrase(p_dat).nominative
if not p_nom:
logging.warning("Unable to decline placename '{0}'".format(p_dat))
logging.warning(f"Unable to decline placename '{p_dat}'")
p_nom = p_dat

if pc[postcode]["stadur_nf"] != p_nom:
pc[postcode]["stadur_nf"] = p_nom
print("{0} --> {1}".format(pc[postcode]["stadur_nf"], p_nom))
print(f"{pc[postcode]['stadur_nf']} --> {p_nom}")
changed = True

if pc[postcode]["stadur_tgf"] != p_dat:
pc[postcode]["stadur_tgf"] = p_dat
print("{0} --> {1}".format(pc[postcode]["stadur_tgf"], p_dat))
print(f"{pc[postcode]['stadur_tgf']} --> {p_dat}")
changed = True

if pc[postcode]["tegund"] != tp:
pc[postcode]["tegund"] = tp
print("{0} --> {1}".format(pc[postcode]["tegund"], tp))
print(f"{pc[postcode]['tegund']} --> {tp}")
changed = True

if not changed:
Expand All @@ -78,5 +76,5 @@ def main() -> None:


if __name__ == "__main__":
""" Command line invocation. """
"""Command line invocation."""
main()
Loading