Skip to content

Commit 89e6e02

Browse files
authored
Merge pull request #19 from josteinl/f/support_several_character_set_encodings
Update the lock file
2 parents cda7c6d + b31c776 commit 89e6e02

File tree

12 files changed

+1184
-847
lines changed

12 files changed

+1184
-847
lines changed

.github/workflows/branch.yaml

+7-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ jobs:
66
strategy:
77
fail-fast: false
88
matrix:
9-
python-version: ['3.9', '3.10', '3.11']
10-
poetry-version: ['1.6.1']
9+
python-version: ['3.11', '3.12', '3.13']
10+
poetry-version: ['2.0.1']
1111
os: [ubuntu-latest]
1212
runs-on: ${{ matrix.os }}
1313
steps:
@@ -29,8 +29,8 @@ jobs:
2929
strategy:
3030
fail-fast: false
3131
matrix:
32-
python-version: ['3.9', '3.10', '3.11']
33-
poetry-version: ['1.6.1']
32+
python-version: ['3.11', '3.12', '3.13']
33+
poetry-version: ['2.0.1']
3434
os: [ubuntu-latest]
3535
runs-on: ${{ matrix.os }}
3636
steps:
@@ -44,17 +44,13 @@ jobs:
4444
poetry-version: ${{ matrix.poetry-version }}
4545
- name: Install dependencies
4646
run: poetry install
47-
- name: Run black
48-
run: poetry run black . --check
49-
# - name: Run isort
50-
# run: poetry run isort . --check-only --profile black
51-
# - name: Run flake8
52-
# run: poetry run flake8 .
47+
- name: Run ruff
48+
run: poetry run ruff format --check
5349
- name: Run mypy
5450
run: poetry run mypy .
5551
- name: Run bandit
5652
run: poetry run bandit .
5753
- name: Run safety
5854
run: poetry run safety check
5955
- name: Check for acceptable licenses
60-
run: poetry run pip-licenses --allow-only="MIT License;BSD License;Python Software Foundation License;Apache Software License;Mozilla Public License 2.0 (MPL 2.0)"
56+
run: poetry run pip-licenses --allow-only="MIT License;BSD License;Python Software Foundation License;Apache Software License;Mozilla Public License 2.0 (MPL 2.0);The Unlicense (Unlicense);ISC License (ISCL)"

.github/workflows/release.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
python-version: ['3.11']
13-
poetry-version: ['1.6.1']
12+
python-version: ['3.13']
13+
poetry-version: ['2.0.1']
1414
os: [ubuntu-latest]
1515
runs-on: ${{ matrix.os }}
1616
steps:

CHANGES.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Python KOF Parser Package
22

3+
## Version 0.1.2
4+
_2025-01-17_
5+
6+
Add
7+
8+
- Add support for all EPSG SRIDs (that the coordinate-projector package supports).
9+
310
## Version 0.1.1
411
_2023-11-09_
512

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
44
[![security: safety](https://img.shields.io/badge/security-safety-yellow.svg)](https://github.com/pyupio/safety)
5-
[![code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
5+
[![code style](https://img.shields.io/badge/style-ruff-41B5BE)](https://github.com/astral-sh/ruff)
66
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
7-
[![python](https://img.shields.io/badge/Python-3.11-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org)
7+
[![python](https://img.shields.io/badge/Python-3.12-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org)
88

99

1010
Python package for parsing and generating KOF files.
@@ -90,9 +90,9 @@ print(kof_string)
9090

9191
Before you start, install:
9292

93-
- Python 3.9 or higher
94-
- Poetry 1.6.1
95-
- black code formatter
93+
- Python 3.11 or higher
94+
- Poetry 2
95+
- Ruff formatter
9696

9797
## Clone this repository
9898

poetry.lock

+1,133-802
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ src = ["src", "tests"]
1919

2020
[tool.poetry]
2121
name = "kof-parser"
22-
version = "0.1.1"
22+
version = "0.1.2"
2323
description = "A KOF file parser. Follows Norkart's KOF 2.0 specification from 2005."
2424
license = "MIT"
2525
authors = ["Magnus Mariero <[email protected]>", "Jostein Leira <[email protected]>"]
@@ -38,13 +38,12 @@ packages = [
3838

3939

4040
[tool.poetry.dependencies]
41-
python = ">=3.9,<4"
42-
pydantic = "^2.4.2"
43-
coordinate-projector = ">=0.0.9"
41+
python = ">=3.11,<4"
42+
pydantic = "^2.10"
43+
coordinate-projector = "^0.0.11"
4444
charset-normalizer = "*"
4545

4646
[tool.poetry.group.dev.dependencies]
47-
black = "*"
4847
pytest = "*"
4948
pytest-cov = "*"
5049
mypy = "*"

src/kof_parser/kof.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Common super class for the KOFReader() and KOFWriter() classes
33
"""
4+
45
import csv
56
from pathlib import Path
67
from typing import Dict, Optional

src/kof_parser/model.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from typing import Optional
2-
31
from pydantic import BaseModel, Field
42

53

64
class Location(BaseModel):
75
name: str = ""
8-
methods: list[str] = []
9-
point_easting: Optional[float] = None
10-
point_northing: Optional[float] = None
11-
point_z: Optional[float] = Field(None, ge=-10000, le=10000)
12-
srid: Optional[int] = None
6+
methods: list[str] = Field(default_factory=list)
7+
point_easting: float | None = None
8+
point_northing: float | None = None
9+
point_z: float | None = Field(None, ge=-10000, le=10000)
10+
srid: int | None = None
11+
12+
def __repr__(self):
13+
return f"<{self.__class__.__name__} {self.name} ({self.point_easting}, {self.point_northing}, {self.point_z})>"

src/kof_parser/parser.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
This is the parser service.
33
"""
4+
45
from io import BytesIO, TextIOWrapper
56
from typing import Optional, Any
67

src/kof_parser/writer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import List, Optional
2-
from datetime import datetime
2+
from datetime import datetime, UTC
33
from uuid import UUID
44

55
from kof_parser import Kof
@@ -36,7 +36,7 @@ def create_admin_block(self, project_name: str, srid: int, swap_easting_northing
3636
# 00 Oppdrag Dato Ver K.sys Komm $11100000000 Observatør
3737
# 01 EXP 31012022 2 22 0000 $22100000000 NN
3838
"""
39-
date = datetime.utcnow().strftime("%d%m%Y")
39+
date = datetime.now(UTC).strftime("%d%m%Y")
4040
version = "1"
4141
sosi_code = self.get_code(srid=srid) or ""
4242
municipality = ""
@@ -73,7 +73,7 @@ def create_kof_header_lines(project_id: UUID, project_name, srid: int) -> str:
7373
header = " 00 KOF Export from NGI Field Manager\n"
7474
header += f" 00 Project: {project_id}. Name: {project_name}\n"
7575
header += f" 00 Spatial Reference ID (SRID): {srid}\n"
76-
header += f" 00 Export date (UTC): {datetime.utcnow()}\n"
76+
header += f" 00 Export date (UTC): {datetime.now(UTC)}\n"
7777

7878
return header
7979

tests/test_parse.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_parse(self):
1515
assert location.srid
1616

1717
@pytest.mark.parametrize(
18-
"file_name, number_of_locations, ex_e, ex_n, ex_z, kof_srid, proj_srid",
18+
"file_name, number_of_locations, expected_easting, expected_northing, expected_z, kof_srid, proj_srid",
1919
[
2020
# No transformations
2121
("tests/data/UTM32_EN.kof", 1, 594137.802, 6589107.923, 0.000, 25832, 25832),
@@ -39,15 +39,17 @@ def test_parse(self):
3939
# Transformation from the source data ETRS89/UTM 32N -> UTM 33 (SRID 25833, SOSI 23)
4040
("tests/data/Innmålt_UTM32.kof", 1, 5696353.09, 535410.87, 50.029, None, 25833),
4141
("tests/data/Innmålt_UTM32.kof", 1, 5696353.09, 535410.87, 50.029, 25832, 25833),
42-
# Transformation from the source data ETRS89/UTM 32N -> ED50 UTM 31 (SRID 23031, SOSI 31)
43-
("tests/data/Innmålt_UTM32.kof", 1, 7712335.00, 680539.85, 50.029, None, 23031),
44-
("tests/data/Innmålt_UTM32.kof", 1, 7712335.00, 680539.85, 50.029, 25832, 23031),
42+
# Transformation from the source data ETRS89/UTM 32N -> ED50 UTM 31 (SRID 23031, SOSI 31 NB: 10 m accuracy)
43+
("tests/data/Innmålt_UTM32.kof", 1, 7712388.471459307, 680330.5913208205, 50.029, None, 23031),
44+
("tests/data/Innmålt_UTM32.kof", 1, 7712388.471459307, 680330.5913208205, 50.029, 25832, 23031),
4545
("tests/data/15-5-18-Fossegata_linux.kof", 6, 6569635.303, 624579.208, 73.838, None, 23031),
4646
("tests/data/15-5-18-Fossegata_windows.kof", 6, 6569635.303, 624579.208, 73.838, None, 23031),
4747
("tests/data/KOF_from_ArcGIS.kof", 131, 83711.914, 1193605.427, 5, 5110, 5110),
4848
],
4949
)
50-
def test_upload_kof_with_proj_and_meta(self, file_name, number_of_locations, ex_e, ex_n, ex_z, kof_srid, proj_srid):
50+
def test_upload_kof_with_proj_and_meta(
51+
self, file_name, number_of_locations, expected_easting, expected_northing, expected_z, kof_srid, proj_srid
52+
):
5153
"""
5254
Test uploading kof file
5355
@@ -61,9 +63,9 @@ def test_upload_kof_with_proj_and_meta(self, file_name, number_of_locations, ex_
6163
assert len(locations) == number_of_locations
6264

6365
location = locations[0]
64-
assert location.point_easting == pytest.approx(ex_e)
65-
assert location.point_northing == pytest.approx(ex_n)
66-
assert location.point_z == ex_z
66+
assert location.point_easting == pytest.approx(expected_easting)
67+
assert location.point_northing == pytest.approx(expected_northing)
68+
assert location.point_z == expected_z
6769
assert location.srid == proj_srid
6870

6971
@pytest.mark.parametrize("file", ["tests/data/import_template.kof", open("tests/data/import_template.kof", "rb")])
@@ -105,7 +107,6 @@ def test_upload_kof(self, file):
105107
assert method == MethodType.PZ.value
106108

107109
def test_err_file_containing_tabs(self):
108-
109110
srid = 5110
110111
parser = KOFParser()
111112

tests/test_write.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ def test_write_all_method_types(self):
5555
[location1, location2] = locations
5656
assert len(location1.methods) == 0
5757
assert len(location2.methods) == len(MethodType) + 3 - 7
58-
assert (
59-
len([method for method in location2.methods if method == "OTHER"]) == 0
60-
), "There are seven methods we do not have a tema code for and are therefore mapped to 2430 OTHER"
58+
assert len([method for method in location2.methods if method == "OTHER"]) == 0, (
59+
"There are seven methods we do not have a tema code for and are therefore mapped to 2430 OTHER"
60+
)

0 commit comments

Comments
 (0)