python-osw-validation 0.3.2__py3-none-any.whl → 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_osw_validation/__init__.py +10 -3
- python_osw_validation/extracted_data_validator.py +2 -1
- python_osw_validation/helpers.py +16 -3
- python_osw_validation/version.py +1 -1
- {python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.3.dist-info}/METADATA +1 -1
- {python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.3.dist-info}/RECORD +9 -9
- {python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.3.dist-info}/WHEEL +0 -0
- {python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.3.dist-info}/licenses/LICENSE +0 -0
- {python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.3.dist-info}/top_level.txt +0 -0
|
@@ -9,7 +9,12 @@ import jsonschema_rs
|
|
|
9
9
|
from .zipfile_handler import ZipFileHandler
|
|
10
10
|
from .extracted_data_validator import ExtractedDataValidator, OSW_DATASET_FILES
|
|
11
11
|
from .version import __version__
|
|
12
|
-
from .helpers import
|
|
12
|
+
from .helpers import (
|
|
13
|
+
_add_additional_properties_hint,
|
|
14
|
+
_feature_index_from_error,
|
|
15
|
+
_pretty_message,
|
|
16
|
+
_rank_for,
|
|
17
|
+
)
|
|
13
18
|
|
|
14
19
|
SCHEMA_PATH = os.path.join(os.path.dirname(__file__), 'schema')
|
|
15
20
|
DEFAULT_DATASET_SCHEMAS = {
|
|
@@ -211,9 +216,10 @@ class OSWValidation:
|
|
|
211
216
|
# Validate the folder structure
|
|
212
217
|
validator = ExtractedDataValidator(self.extracted_dir)
|
|
213
218
|
if not validator.is_valid():
|
|
219
|
+
upload_name = os.path.basename(self.zipfile_path) if self.zipfile_path else self.extracted_dir
|
|
214
220
|
self.log_errors(
|
|
215
221
|
message=validator.error,
|
|
216
|
-
filename=
|
|
222
|
+
filename=upload_name,
|
|
217
223
|
feature_index=None
|
|
218
224
|
)
|
|
219
225
|
return ValidationResult(False, self.errors, self.issues)
|
|
@@ -526,7 +532,8 @@ class OSWValidation:
|
|
|
526
532
|
for err in validator.iter_errors(geojson_data):
|
|
527
533
|
# legacy list (for backward compatibility)
|
|
528
534
|
if legacy_count < max_errors:
|
|
529
|
-
|
|
535
|
+
raw_msg = _add_additional_properties_hint(getattr(err, "message", "") or "")
|
|
536
|
+
self.errors.append(f"Validation error: {raw_msg}")
|
|
530
537
|
legacy_count += 1
|
|
531
538
|
else:
|
|
532
539
|
# We've reached the legacy cap; stop work to match original performance
|
|
@@ -104,8 +104,9 @@ class ExtractedDataValidator:
|
|
|
104
104
|
)
|
|
105
105
|
if unsupported_files:
|
|
106
106
|
allowed_fmt = ", ".join(allowed_keys)
|
|
107
|
+
allowed_names = f"*.{{{allowed_fmt}}}.geojson"
|
|
107
108
|
self.error = (f"Unsupported .geojson files present: {', '.join(unsupported_files)}. "
|
|
108
|
-
f"Allowed file
|
|
109
|
+
f"Allowed file names are {allowed_names}")
|
|
109
110
|
return False
|
|
110
111
|
|
|
111
112
|
required_files = [key for key, value in OSW_DATASET_FILES.items() if value['required']]
|
python_osw_validation/helpers.py
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
import re
|
|
3
3
|
|
|
4
|
+
_ADDITIONAL_PROPERTIES_RE = re.compile(
|
|
5
|
+
r"Additional properties are not allowed \('(?P<tag>[^']+)' was unexpected\)"
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _add_additional_properties_hint(msg: str) -> str:
|
|
10
|
+
match = _ADDITIONAL_PROPERTIES_RE.search(msg)
|
|
11
|
+
if not match:
|
|
12
|
+
return msg
|
|
13
|
+
tag = match.group("tag")
|
|
14
|
+
return f"{msg}. If you want to carry this tag, change it to ext:{tag}"
|
|
15
|
+
|
|
4
16
|
def _feature_index_from_error(err) -> Optional[int]:
|
|
5
17
|
"""
|
|
6
18
|
Return the index after 'features' in the instance path, else None.
|
|
@@ -46,7 +58,7 @@ def _pretty_message(err, schema) -> str:
|
|
|
46
58
|
kind = _err_kind(err)
|
|
47
59
|
|
|
48
60
|
if kind == "Enum":
|
|
49
|
-
return _clean_enum_message(err)
|
|
61
|
+
return _add_additional_properties_hint(_clean_enum_message(err))
|
|
50
62
|
|
|
51
63
|
if kind == "AnyOf":
|
|
52
64
|
# Follow schema_path to the anyOf node; union of 'required' keys in branches.
|
|
@@ -73,12 +85,13 @@ def _pretty_message(err, schema) -> str:
|
|
|
73
85
|
|
|
74
86
|
if required:
|
|
75
87
|
props = ", ".join(sorted(required))
|
|
76
|
-
return f"must include one of: {props}"
|
|
88
|
+
return _add_additional_properties_hint(f"must include one of: {props}")
|
|
77
89
|
except Exception:
|
|
78
90
|
pass
|
|
79
91
|
|
|
80
92
|
# Default: first line from library message
|
|
81
|
-
|
|
93
|
+
default_msg = (getattr(err, "message", "") or "").split("\n")[0]
|
|
94
|
+
return _add_additional_properties_hint(default_msg)
|
|
82
95
|
|
|
83
96
|
|
|
84
97
|
def _rank_for(err) -> tuple:
|
python_osw_validation/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '0.3.
|
|
1
|
+
__version__ = '0.3.3'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
python_osw_validation/__init__.py,sha256=
|
|
2
|
-
python_osw_validation/extracted_data_validator.py,sha256=
|
|
3
|
-
python_osw_validation/helpers.py,sha256=
|
|
4
|
-
python_osw_validation/version.py,sha256=
|
|
1
|
+
python_osw_validation/__init__.py,sha256=uN18FHlSF22X1ch1bxFnxV7PRFLZl2Ks8ZsHbmKfOso,24939
|
|
2
|
+
python_osw_validation/extracted_data_validator.py,sha256=bVkHGocRPrdyut-Kr4Nzl7frBRHWSxUCSeF23Jk1Ju8,6206
|
|
3
|
+
python_osw_validation/helpers.py,sha256=w8UdJlX4zdTDTMthvllyPa8yg8oOueaCZ07bCDeky30,3660
|
|
4
|
+
python_osw_validation/version.py,sha256=on4Bj4mGEjEjyUkQExxprhOoEopcv_sPapsEnNxyelE,22
|
|
5
5
|
python_osw_validation/zipfile_handler.py,sha256=jXnP-8O5AAOBapuNF3-XdFVM1MHiPaWpl_wlbX-aqhY,2631
|
|
6
6
|
python_osw_validation/schema/opensidewalks.edges.schema-0.3.json,sha256=Egp--i6ahiUDKY55g_fuv71HkVPtnQN5OW8L_okRa8o,79638
|
|
7
7
|
python_osw_validation/schema/opensidewalks.lines.schema-0.3.json,sha256=MLfoELBR3DC5Zv7Pa5waoCUCqUBGK7LaX7kcOXJ3DmA,9622
|
|
@@ -10,8 +10,8 @@ python_osw_validation/schema/opensidewalks.points.schema-0.3.json,sha256=dIvItG6
|
|
|
10
10
|
python_osw_validation/schema/opensidewalks.polygons.schema-0.3.json,sha256=K8KmsXze39hukqWfFYFBMncRNwVo95_xJo1v6IWUk-M,16438
|
|
11
11
|
python_osw_validation/schema/opensidewalks.schema-0.3.json,sha256=Yq8WyvUEr_0nxfSSLFlGYc7vMQeKL6yS1qjltq-5JPk,204728
|
|
12
12
|
python_osw_validation/schema/opensidewalks.zones.schema-0.3.json,sha256=JCqoCJj-dCuPVPHWSUQhRJMebaJ9IrzHWwTVAC6j7dY,11281
|
|
13
|
-
python_osw_validation-0.3.
|
|
14
|
-
python_osw_validation-0.3.
|
|
15
|
-
python_osw_validation-0.3.
|
|
16
|
-
python_osw_validation-0.3.
|
|
17
|
-
python_osw_validation-0.3.
|
|
13
|
+
python_osw_validation-0.3.3.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
|
14
|
+
python_osw_validation-0.3.3.dist-info/METADATA,sha256=N5l0zU83nNkqmVHvCYUlUo8El72QzjQp2fEEWt6j8cA,7540
|
|
15
|
+
python_osw_validation-0.3.3.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
|
16
|
+
python_osw_validation-0.3.3.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
|
|
17
|
+
python_osw_validation-0.3.3.dist-info/RECORD,,
|
|
File without changes
|
{python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.3.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.3.dist-info}/top_level.txt
RENAMED
|
File without changes
|