python-osw-validation 0.2.13__py3-none-any.whl → 0.2.15__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.
@@ -202,8 +202,15 @@ class OSWValidation:
202
202
  continue
203
203
  is_valid, duplicates = self.are_ids_unique(gdf)
204
204
  if not is_valid:
205
+ total_duplicates = len(duplicates)
206
+ displayed = ', '.join(map(str, duplicates[:max_errors]))
207
+ if total_duplicates > max_errors:
208
+ message = (f"Duplicate _id's found in {osw_file}: showing first {max_errors} "
209
+ f"of {total_duplicates} duplicates: {displayed}")
210
+ else:
211
+ message = f"Duplicate _id's found in {osw_file}: {displayed}"
205
212
  self.log_errors(
206
- message=f"Duplicate _id's found in {osw_file} : {duplicates}",
213
+ message=message,
207
214
  filename=osw_file,
208
215
  feature_index=None
209
216
  )
@@ -238,11 +245,11 @@ class OSWValidation:
238
245
  if unmatched:
239
246
  unmatched_list = list(unmatched)
240
247
  num_unmatched = len(unmatched_list)
241
- limit = min(num_unmatched, 20)
248
+ limit = min(num_unmatched, max_errors)
242
249
  displayed_unmatched = ', '.join(map(str, unmatched_list[:limit]))
243
250
  self.log_errors(
244
251
  message=(f"All _u_id's in edges should be part of _id's mentioned in nodes. "
245
- f"Showing {'20' if num_unmatched > 20 else 'all'} out of {num_unmatched} "
252
+ f"Showing {max_errors if num_unmatched > max_errors else 'all'} out of {num_unmatched} "
246
253
  f"unmatched _u_id's: {displayed_unmatched}"),
247
254
  filename='All',
248
255
  feature_index=None
@@ -253,11 +260,11 @@ class OSWValidation:
253
260
  if unmatched:
254
261
  unmatched_list = list(unmatched)
255
262
  num_unmatched = len(unmatched_list)
256
- limit = min(num_unmatched, 20)
263
+ limit = min(num_unmatched, max_errors)
257
264
  displayed_unmatched = ', '.join(map(str, unmatched_list[:limit]))
258
265
  self.log_errors(
259
266
  message=(f"All _v_id's in edges should be part of _id's mentioned in nodes. "
260
- f"Showing {'20' if num_unmatched > 20 else 'all'} out of {num_unmatched} "
267
+ f"Showing {max_errors if num_unmatched > max_errors else 'all'} out of {num_unmatched} "
261
268
  f"unmatched _v_id's: {displayed_unmatched}"),
262
269
  filename='All',
263
270
  feature_index=None
@@ -268,11 +275,11 @@ class OSWValidation:
268
275
  if unmatched:
269
276
  unmatched_list = list(unmatched)
270
277
  num_unmatched = len(unmatched_list)
271
- limit = min(num_unmatched, 20)
278
+ limit = min(num_unmatched, max_errors)
272
279
  displayed_unmatched = ', '.join(map(str, unmatched_list[:limit]))
273
280
  self.log_errors(
274
281
  message=(f"All _w_id's in zones should be part of _id's mentioned in nodes. "
275
- f"Showing {'20' if num_unmatched > 20 else 'all'} out of {num_unmatched} "
282
+ f"Showing {max_errors if num_unmatched > max_errors else 'all'} out of {num_unmatched} "
276
283
  f"unmatched _w_id's: {displayed_unmatched}"),
277
284
  filename='All',
278
285
  feature_index=None
@@ -295,10 +302,10 @@ class OSWValidation:
295
302
  ids_series = invalid_geojson['_id'] if '_id' in invalid_geojson.columns else invalid_geojson.index
296
303
  invalid_ids = list(set(ids_series))
297
304
  num_invalid = len(invalid_ids)
298
- limit = min(num_invalid, 20)
305
+ limit = min(num_invalid, max_errors)
299
306
  displayed_invalid = ', '.join(map(str, invalid_ids[:limit]))
300
307
  self.log_errors(
301
- message=(f"Showing {'20' if num_invalid > 20 else 'all'} out of {num_invalid} "
308
+ message=(f"Showing {max_errors if num_invalid > max_errors else 'all'} out of {num_invalid} "
302
309
  f"invalid {osw_file} geometries, id's of invalid geometries: {displayed_invalid}"),
303
310
  filename='All',
304
311
  feature_index=None
@@ -323,11 +330,11 @@ class OSWValidation:
323
330
  try:
324
331
  invalid_ids = list(set(invalid_geojson.get('_id', invalid_geojson.index)))
325
332
  num_invalid = len(invalid_ids)
326
- limit = min(num_invalid, 20)
333
+ limit = min(num_invalid, max_errors)
327
334
  displayed_invalid = ', '.join(map(str, invalid_ids[:limit]))
328
335
  self.log_errors(
329
336
  message=(f"Invalid geometries found in extension file `{file_name}`. "
330
- f"Showing {limit if num_invalid > 20 else 'all'} of {num_invalid} "
337
+ f"Showing {max_errors if num_invalid > max_errors else 'all'} of {num_invalid} "
331
338
  f"invalid geometry IDs: {displayed_invalid}"),
332
339
  filename=file_name,
333
340
  feature_index=None
@@ -388,8 +395,28 @@ class OSWValidation:
388
395
  gc.collect()
389
396
 
390
397
  def load_osw_file(self, graph_geojson_path: str) -> Dict[str, Any]:
391
- with open(graph_geojson_path, 'r') as file:
392
- return json.load(file)
398
+ try:
399
+ with open(graph_geojson_path, 'r') as file:
400
+ return json.load(file)
401
+ except json.JSONDecodeError as e:
402
+ filename = os.path.basename(graph_geojson_path)
403
+ self.log_errors(
404
+ message=(
405
+ f"Failed to parse '{filename}' as valid JSON. "
406
+ f"{e.msg} (line {e.lineno}, column {e.colno}, char {e.pos})."
407
+ ),
408
+ filename=filename,
409
+ feature_index=None,
410
+ )
411
+ raise
412
+ except OSError as e:
413
+ filename = os.path.basename(graph_geojson_path)
414
+ self.log_errors(
415
+ message=f"Unable to read file '{filename}': {e.strerror or e}",
416
+ filename=filename,
417
+ feature_index=None,
418
+ )
419
+ raise
393
420
 
394
421
  def validate_osw_errors(self, file_path: str, max_errors: int) -> bool:
395
422
  """Validate one OSW GeoJSON against the appropriate schema (streaming).
@@ -399,7 +426,12 @@ class OSWValidation:
399
426
  before returning, pushes a single human-friendly message per feature
400
427
  into `self.issues` (like your sample: "must include one of: ...").
401
428
  """
402
- geojson_data = self.load_osw_file(file_path)
429
+ try:
430
+ geojson_data = self.load_osw_file(file_path)
431
+ except json.JSONDecodeError:
432
+ return False
433
+ except OSError:
434
+ return False
403
435
  schema_path = self.pick_schema_for_file(file_path, geojson_data)
404
436
  schema = self.load_osw_schema(schema_path)
405
437
  validator = jsonschema_rs.Draft7Validator(schema)
@@ -2,6 +2,7 @@
2
2
  "title": "root",
3
3
  "type": "object",
4
4
  "required": [
5
+ "$schema",
5
6
  "type",
6
7
  "features"
7
8
  ],
@@ -2,6 +2,7 @@
2
2
  "title": "root",
3
3
  "type": "object",
4
4
  "required": [
5
+ "$schema",
5
6
  "type",
6
7
  "features"
7
8
  ],
@@ -2,6 +2,7 @@
2
2
  "title": "root",
3
3
  "type": "object",
4
4
  "required": [
5
+ "$schema",
5
6
  "type",
6
7
  "features"
7
8
  ],
@@ -1 +1 @@
1
- __version__ = '0.2.13'
1
+ __version__ = '0.2.15'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-osw-validation
3
- Version: 0.2.13
3
+ Version: 0.2.15
4
4
  Summary: Python library for OSW validation
5
5
  Home-page: https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
6
6
  Author: Sujata Misra
@@ -0,0 +1,14 @@
1
+ python_osw_validation/__init__.py,sha256=_OtFJzHGX3kzomOdnywHE4-6WrGjcyT43ida-xX4JKc,21091
2
+ python_osw_validation/extracted_data_validator.py,sha256=wZyCk8NlJv10cj_GrRTAiwm4cBhTAeDethjzJU-amoI,3877
3
+ python_osw_validation/helpers.py,sha256=afTFF7J14QBWqhxy1pO20Db_EQeWSO2Br5eteiy7xNg,3160
4
+ python_osw_validation/version.py,sha256=n8L-CG7GwxdcaK3gVXpLPrQnpjUiTjhwgxpdZpr4XUY,22
5
+ python_osw_validation/zipfile_handler.py,sha256=jXnP-8O5AAOBapuNF3-XdFVM1MHiPaWpl_wlbX-aqhY,2631
6
+ python_osw_validation/schema/Linestring_schema.json,sha256=MVhOD_WLXH2BmAyQ4VZ3bX1XjTDrYIUJiIq8ucKDm1I,73727
7
+ python_osw_validation/schema/Point_schema.json,sha256=vMBB599mnlT2c1hhndkPRG89SwV0SS29lapRTv7JnpI,6779
8
+ python_osw_validation/schema/Polygon_schema.json,sha256=0oebkGSGCHefzDB3zaDrRakSI4OcK7qECrnDDv_m8BE,11086
9
+ python_osw_validation/schema/opensidewalks.schema.json,sha256=i0iJwb_4Tq20BVUpkpgyM_7fm4SW_d_HNXKw0xul7OA,240987
10
+ python_osw_validation-0.2.15.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
11
+ python_osw_validation-0.2.15.dist-info/METADATA,sha256=_BUFdDvo8Boh3eVo9lbEiBVWWN4ZINlbwa-9_a6eb1s,7232
12
+ python_osw_validation-0.2.15.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
13
+ python_osw_validation-0.2.15.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
14
+ python_osw_validation-0.2.15.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- python_osw_validation/__init__.py,sha256=07DnRGgPYKLUYzrLVY67FtKzWxmFiP9GRBNRTBtbY-Q,19663
2
- python_osw_validation/extracted_data_validator.py,sha256=wZyCk8NlJv10cj_GrRTAiwm4cBhTAeDethjzJU-amoI,3877
3
- python_osw_validation/helpers.py,sha256=afTFF7J14QBWqhxy1pO20Db_EQeWSO2Br5eteiy7xNg,3160
4
- python_osw_validation/version.py,sha256=BzaUqLuMDa5m8WXD6rxGwHtx-G5rl0QutUD88ULNrkQ,22
5
- python_osw_validation/zipfile_handler.py,sha256=jXnP-8O5AAOBapuNF3-XdFVM1MHiPaWpl_wlbX-aqhY,2631
6
- python_osw_validation/schema/Linestring_schema.json,sha256=prQqlQo78HSN0EVKHQBuv2PYKKVbcAwK6FXkHlVx8h0,73712
7
- python_osw_validation/schema/Point_schema.json,sha256=2U5A9eUKqfdBj1NP0IqCYAR_dVpfRP_LPWBd6mTH2Ns,6764
8
- python_osw_validation/schema/Polygon_schema.json,sha256=ACjnP3vSsqAEz5-iFuo7LqTodoNe14hwgvZ5KJiYFRc,11071
9
- python_osw_validation/schema/opensidewalks.schema.json,sha256=i0iJwb_4Tq20BVUpkpgyM_7fm4SW_d_HNXKw0xul7OA,240987
10
- python_osw_validation-0.2.13.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
11
- python_osw_validation-0.2.13.dist-info/METADATA,sha256=Zfb2SjCBCFfcqe3qlEip3zPPMFLhu2o1cralVFaKZjk,7232
12
- python_osw_validation-0.2.13.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
13
- python_osw_validation-0.2.13.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
14
- python_osw_validation-0.2.13.dist-info/RECORD,,