python-osw-validation 0.3.4__py3-none-any.whl → 0.3.6__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.
@@ -112,21 +112,21 @@ class OSWValidation:
112
112
  return set()
113
113
 
114
114
  def _schema_key_from_text(self, text: Optional[str]) -> Optional[str]:
115
- """Return dataset key (edges/nodes/points/lines/polygons/zones) if mentioned in text."""
115
+ """Return dataset key from exact filename suffixes only."""
116
116
  if not text:
117
117
  return None
118
- lower = text.lower()
119
- aliases = {
120
- "edges": ("edge", "edges"),
121
- "lines": ("line", "lines", "linestring"),
122
- "nodes": ("node", "nodes"),
123
- "points": ("point", "points"),
124
- "polygons": ("polygon", "polygons", "area"),
125
- "zones": ("zone", "zones"),
126
- }
127
- for key, variants in aliases.items():
128
- if any(alias in lower for alias in variants):
118
+
119
+ basename = os.path.basename(text).lower()
120
+ stem, _ = os.path.splitext(basename)
121
+ for key in self.dataset_schema_paths:
122
+ if (
123
+ stem == key
124
+ or stem == f"{key}.osw"
125
+ or stem.endswith(f".{key}")
126
+ or stem.endswith(f".{key}.osw")
127
+ ):
129
128
  return key
129
+
130
130
  return None
131
131
 
132
132
  def _contains_disallowed_features_for_02(self, geojson_data: Dict[str, Any]) -> set:
@@ -48,6 +48,20 @@ _FILENAME_TO_KEY = {
48
48
  }
49
49
 
50
50
 
51
+ def _matches_dataset_filename(basename: str, dataset_key: str) -> bool:
52
+ lower_name = basename.lower()
53
+ if not lower_name.endswith(".geojson"):
54
+ return False
55
+
56
+ stem = lower_name[:-len(".geojson")]
57
+ return (
58
+ stem == dataset_key
59
+ or stem == f"{dataset_key}.osw"
60
+ or stem.endswith(f".{dataset_key}")
61
+ or stem.endswith(f".{dataset_key}.osw")
62
+ )
63
+
64
+
51
65
  class ExtractedDataValidator:
52
66
  def __init__(self, extracted_dir: str):
53
67
  self.extracted_dir = extracted_dir
@@ -100,7 +114,7 @@ class ExtractedDataValidator:
100
114
 
101
115
  allowed_keys = tuple(OSW_DATASET_FILES.keys())
102
116
  unsupported_files = sorted(
103
- {bn for bn in basenames if not any(key in bn for key in allowed_keys)}
117
+ {bn for bn in basenames if not any(_matches_dataset_filename(bn, key) for key in allowed_keys)}
104
118
  )
105
119
  if unsupported_files:
106
120
  allowed_fmt = ", ".join(allowed_keys)
@@ -121,7 +135,7 @@ class ExtractedDataValidator:
121
135
  file_count = 0
122
136
  for filename in geojson_files:
123
137
  base_name = os.path.basename(filename)
124
- if required_file in base_name and base_name.endswith('.geojson'):
138
+ if _matches_dataset_filename(base_name, required_file):
125
139
  file_count += 1
126
140
  save_filename = filename
127
141
  if file_count == 0:
@@ -138,7 +152,7 @@ class ExtractedDataValidator:
138
152
  file_count = 0
139
153
  for filename in geojson_files:
140
154
  base_name = os.path.basename(filename)
141
- if optional_file in base_name and base_name.endswith('.geojson'):
155
+ if _matches_dataset_filename(base_name, optional_file):
142
156
  file_count += 1
143
157
  save_filename = filename
144
158
  if file_count == 1:
@@ -1 +1 @@
1
- __version__ = '0.3.4'
1
+ __version__ = '0.3.6'
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: python_osw_validation
3
+ Version: 0.3.6
4
+ Summary: Python library for OSW validation
5
+ Home-page: https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
6
+ Author: Sujata Misra
7
+ Author-email: sujatam@gaussiansolutions.com
8
+ Project-URL: Documentation, https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/blob/main/README.md
9
+ Project-URL: GitHub, https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
10
+ Project-URL: Changelog, https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/blob/main/CHANGELOG.md
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: jsonschema_rs==0.33.0
18
+ Requires-Dist: zipfile36==0.1.3
19
+ Requires-Dist: geopandas==0.14.4
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: description
24
+ Dynamic: description-content-type
25
+ Dynamic: home-page
26
+ Dynamic: license-file
27
+ Dynamic: project-url
28
+ Dynamic: requires-dist
29
+ Dynamic: requires-python
30
+ Dynamic: summary
31
+
32
+ # TDEI python lib OSW validation package
33
+
34
+ This package validates OSW GeoJSON datasets packaged as a ZIP file.
35
+
36
+ ## System requirements
37
+
38
+ | Software | Version |
39
+ |----------|---------|
40
+ | Python | >= 3.10 |
41
+
42
+ ## What this package does?
43
+
44
+ - Extracts the provided ZIP file
45
+ - Finds supported OSW dataset files inside the extracted directory
46
+ - Validates each file (`edges`, `lines`, `nodes`, `points`, `polygons`, and `zones`) against the matching schema
47
+ - Runs cross-file integrity checks such as duplicate `_id` detection and edge or zone references back to nodes
48
+ - Returns a `ValidationResult` object with `is_valid`, `errors`, and `issues`
49
+
50
+ Any subset of the six supported dataset files may be present. By default, no individual dataset file is required.
51
+
52
+ ## Starting a new project with template
53
+
54
+ - Add `python-osw-validation` package as dependency in your `requirements.txt`
55
+ - or `pip install python-osw-validation`
56
+ - Start using the packages in your code.
57
+
58
+ ## Initialize and Configuration
59
+
60
+ ```python
61
+ from python_osw_validation import OSWValidation
62
+
63
+ validator = OSWValidation(zipfile_path='<Zip file path>')
64
+ result = validator.validate()
65
+ print(result.is_valid)
66
+ print(result.errors) # returns up to the first 20 high-level errors by default
67
+ print(result.issues) # per-file or per-feature issues
68
+
69
+ result = validator.validate(max_errors=10)
70
+ print(result.is_valid)
71
+ print(result.errors) # returns up to the first 10 high-level errors
72
+ ```
73
+
74
+ You can also override schemas:
75
+
76
+ ```python
77
+ from python_osw_validation import OSWValidation
78
+
79
+ validator = OSWValidation(
80
+ zipfile_path='<Zip file path>',
81
+ schema_paths={
82
+ 'nodes': 'path/to/opensidewalks.nodes.schema-0.3.json',
83
+ 'edges': 'path/to/opensidewalks.edges.schema-0.3.json',
84
+ },
85
+ )
86
+ ```
87
+
88
+ ## Supported filenames
89
+
90
+ The validator accepts dataset files whose names end with one of these exact suffixes:
91
+
92
+ - `.edges.geojson`
93
+ - `.lines.geojson`
94
+ - `.nodes.geojson`
95
+ - `.points.geojson`
96
+ - `.polygons.geojson`
97
+ - `.zones.geojson`
98
+
99
+ It also accepts the legacy form:
100
+
101
+ - `.edges.OSW.geojson`
102
+ - `.lines.OSW.geojson`
103
+ - `.nodes.OSW.geojson`
104
+ - `.points.OSW.geojson`
105
+ - `.polygons.OSW.geojson`
106
+ - `.zones.OSW.geojson`
107
+
108
+ Examples:
109
+
110
+ - `gs_metaline_falls_uga.nodes.geojson` is valid
111
+ - `gs_yarrow_point.edges.geojson` is valid
112
+ - `roadEdges.geojson` is invalid
113
+
114
+ If a dataset uses canonical OSW 0.3 names that start with `opensidewalks.`, then only these exact names are allowed:
115
+
116
+ - `opensidewalks.edges.geojson`
117
+ - `opensidewalks.lines.geojson`
118
+ - `opensidewalks.nodes.geojson`
119
+ - `opensidewalks.points.geojson`
120
+ - `opensidewalks.polygons.geojson`
121
+ - `opensidewalks.zones.geojson`
122
+
123
+ ### Testing
124
+
125
+ All unit tests are under `tests/unit_tests`.
126
+
127
+ - To execute the tests:
128
+
129
+ `pip install -r requirements.txt`
130
+
131
+ `python -m unittest discover -v tests/unit_tests`
132
+
133
+ - To execute code coverage:
134
+
135
+ `coverage run --source=src/python_osw_validation -m unittest discover -v tests/unit_tests`
136
+
137
+ `coverage html`
138
+
139
+ `coverage report`
140
+
141
+ After running coverage, open `htmlcov/index.html` to inspect the report in a browser.
142
+
143
+ ## Use locally
144
+ To use the library locally, use the [example.py](./src/example.py) code
145
+
146
+ ## Deployment
147
+
148
+ - The library can be pushed to [TestPyPI](https://test.pypi.org/project/python-osw-validation/) or [PyPI](https://pypi.org/project/python-osw-validation/)
149
+
150
+ ### Deploy to TestPyPI
151
+
152
+ - On every push to `dev` branch, a workflow is triggered which publishes the updated version to TestPyPI
153
+
154
+ ### Deploy to PyPI
155
+
156
+ - This happens whenever a tag or release is created with `*.*.*` notation, for example `0.0.8`
157
+ - To change the version, update [version.py](./src/python_osw_validation/version.py)
158
+ - To release a new version:
159
+ - Go to the GitHub repository
160
+ - Under [releases](https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/releases), click on `Draft a new release`
161
+ - Under `choose a new tag`, add a new tag `v*.*.*`, then generate release notes
162
+ - Choose `main` branch for release
163
+ - Publish the release.
164
+ - This release triggers a workflow to generate the new package version.
165
+ - The new package will be available at https://pypi.org/project/python-osw-validation/
@@ -1,7 +1,7 @@
1
- python_osw_validation/__init__.py,sha256=uN18FHlSF22X1ch1bxFnxV7PRFLZl2Ks8ZsHbmKfOso,24939
2
- python_osw_validation/extracted_data_validator.py,sha256=bVkHGocRPrdyut-Kr4Nzl7frBRHWSxUCSeF23Jk1Ju8,6206
1
+ python_osw_validation/__init__.py,sha256=kvbtnQc0YTV4DDfVlomCuV2sW_tLkvh58aIFF9cXo0I,24824
2
+ python_osw_validation/extracted_data_validator.py,sha256=gEGYLaM_QkK6NrrhVYmNx-jMaNHXC4PbDGf1zKwJre4,6605
3
3
  python_osw_validation/helpers.py,sha256=w8UdJlX4zdTDTMthvllyPa8yg8oOueaCZ07bCDeky30,3660
4
- python_osw_validation/version.py,sha256=Yyz9rKJSsP7kA7oh3l-XTxOFzEuuSR9Ly7oYXA1hfFM,22
4
+ python_osw_validation/version.py,sha256=EptYWB4vmy2J8e2vmqb4NqLJhNPAiPzUcbQU_V76sXE,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=3s-VXiMPv0_wv3yU2iGw8iKjE3Ec1w6QKkUsQURp2II,9470
@@ -10,8 +10,8 @@ python_osw_validation/schema/opensidewalks.points.schema-0.3.json,sha256=WYmlC4Q
10
10
  python_osw_validation/schema/opensidewalks.polygons.schema-0.3.json,sha256=VzDpHv1ZVT42cAk9n3gsFZjS7WcflQzSbjN-aNIVTYM,16286
11
11
  python_osw_validation/schema/opensidewalks.schema-0.3.json,sha256=vyyGzPpqLxr1e5wFfNKzlA1sr6tmhHKM7ntaTk8z5k8,278489
12
12
  python_osw_validation/schema/opensidewalks.zones.schema-0.3.json,sha256=JCqoCJj-dCuPVPHWSUQhRJMebaJ9IrzHWwTVAC6j7dY,11281
13
- python_osw_validation-0.3.4.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
14
- python_osw_validation-0.3.4.dist-info/METADATA,sha256=8CtgMg2udEyl54LHh3MvI7BSSGzigdPy8SwHLg4N7Ls,7540
15
- python_osw_validation-0.3.4.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
16
- python_osw_validation-0.3.4.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
17
- python_osw_validation-0.3.4.dist-info/RECORD,,
13
+ python_osw_validation-0.3.6.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
14
+ python_osw_validation-0.3.6.dist-info/METADATA,sha256=cFhXo_yHejrsgDf0kZNyVufHchiQj-QKizv-_5gGeE0,5256
15
+ python_osw_validation-0.3.6.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
16
+ python_osw_validation-0.3.6.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
17
+ python_osw_validation-0.3.6.dist-info/RECORD,,
@@ -1,161 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: python_osw_validation
3
- Version: 0.3.4
4
- Summary: Python library for OSW validation
5
- Home-page: https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
6
- Author: Sujata Misra
7
- Author-email: sujatam@gaussiansolutions.com
8
- Project-URL: Documentation, https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/blob/main/README.md
9
- Project-URL: GitHub, https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
10
- Project-URL: Changelog, https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/blob/main/CHANGELOG.md
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.10
15
- Description-Content-Type: text/markdown
16
- License-File: LICENSE
17
- Requires-Dist: jsonschema_rs==0.26.1
18
- Requires-Dist: zipfile36==0.1.3
19
- Requires-Dist: geopandas==0.14.4
20
- Dynamic: author
21
- Dynamic: author-email
22
- Dynamic: classifier
23
- Dynamic: description
24
- Dynamic: description-content-type
25
- Dynamic: home-page
26
- Dynamic: license-file
27
- Dynamic: project-url
28
- Dynamic: requires-dist
29
- Dynamic: requires-python
30
- Dynamic: summary
31
-
32
- # TDEI python lib OSW validation package
33
-
34
- This package validates the OSW geojson file. Package requires a OSW zip file path
35
-
36
- ## System requirements
37
-
38
- | Software | Version |
39
- |----------|---------|
40
- | Python | 3.10.x |
41
-
42
- ## What this package does?
43
-
44
- - It unzip the provided zip files
45
- - Check for the required nodes and edges geojson files inside the unzipped folder
46
- - Validate each file (edges, lines, nodes, points, polygons and zones) against the matching schema (0.3 defaults live in `src/python_osw_validation/schema`)
47
- - Return true or false according to validation
48
- - you can check the error if it returned false.
49
-
50
- ## Starting a new project with template
51
-
52
- - Add `python-osw-validation` package as dependency in your `requirements.txt`
53
- - or `pip install python-osw-validation`
54
- - Start using the packages in your code.
55
-
56
- ## Initialize and Configuration
57
-
58
- ```python
59
- from python_osw_validation import OSWValidation
60
-
61
- validator = OSWValidation(zipfile_path='<Zip file path>')
62
- result = validator.validate()
63
- print(result.is_valid)
64
- print(result.errors) # will return first 20 errors by default if there are errors
65
-
66
- result = validator.validate(max_errors=10)
67
- print(result.is_valid)
68
- print(result.errors) # will return first 10 errors depending on the max_errors parameter
69
-
70
- ```
71
-
72
- ### Testing
73
-
74
- The project is configured with `python` to figure out the coverage of the unit tests. All the tests are in `tests`
75
- folder.
76
-
77
- - To execute the tests, please follow the commands:
78
-
79
- `pip install -r requirements.txt`
80
-
81
- `python -m unittest discover -v tests/unit_tests`
82
-
83
- - To execute the code coverage, please follow the commands:
84
-
85
- `coverage run --source=src/python_osw_validation -m unittest discover -v tests/unit_tests`
86
-
87
- `coverage html` // Can be run after 1st command
88
-
89
- `coverage report` // Can be run after 1st command
90
-
91
- - After the commands are run, you can check the coverage report in `htmlcov/index.html`. Open the file in any browser,
92
- and it shows complete coverage details
93
- - The terminal will show the output of coverage like this
94
-
95
- ```shell
96
-
97
- > coverage run --source=src/python_osw_validation -m unittest discover -v tests/unit_tests
98
- test_duplicate_files (test_extracted_data_validator.TestExtractedDataValidator) ... ok
99
- test_empty_directory (test_extracted_data_validator.TestExtractedDataValidator) ... ok
100
- test_invalid_directory (test_extracted_data_validator.TestExtractedDataValidator) ... ok
101
- test_missing_optional_file (test_extracted_data_validator.TestExtractedDataValidator) ... ok
102
- test_no_geojson_files (test_extracted_data_validator.TestExtractedDataValidator) ... ok
103
- test_valid_data_at_root (test_extracted_data_validator.TestExtractedDataValidator) ... ok
104
- test_valid_data_inside_folder (test_extracted_data_validator.TestExtractedDataValidator) ... ok
105
- test_edges_invalid_zipfile (test_osw_validation.TestOSWValidation) ... ok
106
- test_edges_invalid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
107
- test_edges_invalid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
108
- test_external_extension_file_inside_zipfile (test_osw_validation.TestOSWValidation) ... ok
109
- test_external_extension_file_inside_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
110
- test_external_extension_file_inside_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
111
- test_extra_field_zipfile (test_osw_validation.TestOSWValidation) ... ok
112
- test_id_missing_zipfile (test_osw_validation.TestOSWValidation) ... ok
113
- test_invalid_geometry_zipfile (test_osw_validation.TestOSWValidation) ... ok
114
- test_invalid_zipfile (test_osw_validation.TestOSWValidation) ... ok
115
- test_invalid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
116
- test_invalid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
117
- test_minimal_zipfile (test_osw_validation.TestOSWValidation) ... ok
118
- test_minimal_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
119
- test_minimal_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
120
- test_missing_identifier_zipfile (test_osw_validation.TestOSWValidation) ... ok
121
- test_no_entity_zipfile (test_osw_validation.TestOSWValidation) ... ok
122
- test_nodes_invalid_zipfile (test_osw_validation.TestOSWValidation) ... ok
123
- test_nodes_invalid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
124
- test_nodes_invalid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
125
- test_points_invalid_zipfile (test_osw_validation.TestOSWValidation) ... ok
126
- test_points_invalid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
127
- test_points_invalid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
128
- test_valid_zipfile (test_osw_validation.TestOSWValidation) ... ok
129
- test_valid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
130
- test_valid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
131
- test_wrong_datatypes_zipfile (test_osw_validation.TestOSWValidation) ... ok
132
- test_extract_invalid_zip (test_zipfile_handler.TestZipFileHandler) ... ok
133
- test_extract_valid_zip (test_zipfile_handler.TestZipFileHandler) ... ok
134
- test_remove_extracted_files (test_zipfile_handler.TestZipFileHandler) ... ok
135
-
136
- ----------------------------------------------------------------------
137
- Ran 37 tests in 1284.068s
138
-
139
- OK
140
- ```
141
-
142
- ## Use locally:
143
- To use the library locally, use the [example.py](./src/example.py) code
144
-
145
- ## Deployment:
146
-
147
- - The library can be pushed to [TestPy](https://test.pypi.org/project/python-osw-validation/) or [PYPI](https://pypi.org/project/python-osw-validation/)
148
- ### Deploy to TestPy
149
- - On every push to `dev` branch, a workflow is triggered which publishes the updated version to TestPy
150
-
151
- ### Deploy to PyPI
152
- - This happens whenever a tag/release is created with `*.*.*` notation (eg. 0.0.8)
153
- - To change the version, change the version at [version.py](./src/python_osw_validation/version.py)
154
- - To release a new version:
155
- - Go to Github link of this repository
156
- - Under [releases](https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/releases), click on `Draft a new release`
157
- - Under `choose a new tag`, add a new tag `v*.*.*` , Generate Release notes
158
- - Choose `main` branch for release
159
- - Publish the release.
160
- - This release triggers a workflow to generate the new version of the Package.
161
- - The new package will be available at https://pypi.org/project/python-osw-validation/