Reorganise
This commit is contained in:
parent
2a2a42fe5d
commit
d3e6d7ac42
12 changed files with 206 additions and 178 deletions
47
AGENTS.md
47
AGENTS.md
|
|
@ -11,20 +11,31 @@ Requests for HTTP calls.
|
|||
## Repository layout
|
||||
|
||||
```
|
||||
osm-pt-geojson - Fetch a public transport route relation, list stops, export GeoJSON
|
||||
README.md - User-facing documentation
|
||||
AGENTS.md - This file
|
||||
pyproject.toml - Package metadata and build configuration
|
||||
src/
|
||||
osm_geojson/
|
||||
__init__.py - Top-level package marker
|
||||
pt/
|
||||
__init__.py - Public transport subpackage
|
||||
core.py - Data fetching and processing functions
|
||||
cli.py - Click CLI commands
|
||||
tests/
|
||||
fixtures/ - Saved OSM API responses for offline testing
|
||||
test_osm_pt_geojson.py - Test suite
|
||||
README.md - User-facing documentation
|
||||
AGENTS.md - This file
|
||||
```
|
||||
|
||||
New tools are added as individual scripts at the repo root.
|
||||
`osm_geojson` is the top-level namespace for all tools in this collection. Each
|
||||
tool lives in its own subpackage (e.g. `osm_geojson.pt`), with its CLI entry
|
||||
point registered in `pyproject.toml` under `[project.scripts]`.
|
||||
|
||||
## Code conventions
|
||||
|
||||
- Python 3, shebang `#!/usr/bin/python3`
|
||||
- Python 3.11+
|
||||
- CLI via [Click](https://click.palletsprojects.com/)
|
||||
- HTTP via [Requests](https://requests.readthedocs.io/)
|
||||
- Parse XML with lxml if needed; prefer the OSM JSON API where possible
|
||||
- Scripts have no `.py` extension and are executable
|
||||
- Errors go to stderr; data output goes to stdout
|
||||
- GeoJSON output uses `ensure_ascii=False`
|
||||
- All modules, functions, and test functions must have docstrings
|
||||
|
|
@ -42,10 +53,10 @@ No authentication is required for read-only access. Include a descriptive
|
|||
|
||||
## Type checking
|
||||
|
||||
All scripts use type hints. Run mypy in strict mode to check:
|
||||
All code uses type hints. Run mypy in strict mode to check:
|
||||
|
||||
```
|
||||
mypy --strict osm-pt-geojson
|
||||
mypy --strict src/osm_geojson/
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
|
@ -59,21 +70,6 @@ pytest tests/
|
|||
Tests use the `responses` library to mock HTTP calls and never hit the live OSM
|
||||
API. Fixture data is stored in `tests/fixtures/` as saved API responses.
|
||||
|
||||
Because tool scripts have hyphens in their names and no `.py` extension, they
|
||||
cannot be imported with the normal `importlib.util.spec_from_file_location`.
|
||||
Use `importlib.machinery.SourceFileLoader` instead:
|
||||
|
||||
```python
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
|
||||
_loader = importlib.machinery.SourceFileLoader("osm_pt_geojson", "osm-pt-geojson")
|
||||
_spec = importlib.util.spec_from_loader("osm_pt_geojson", _loader)
|
||||
assert _spec
|
||||
osm = importlib.util.module_from_spec(_spec)
|
||||
_loader.exec_module(osm)
|
||||
```
|
||||
|
||||
### Example relations used during development
|
||||
|
||||
| ID | Description |
|
||||
|
|
@ -83,8 +79,9 @@ _loader.exec_module(osm)
|
|||
|
||||
## Dependencies
|
||||
|
||||
Install with pip:
|
||||
Use a virtual environment. Install the package and test dependencies with:
|
||||
|
||||
```
|
||||
pip install click requests
|
||||
python3 -m venv .venv
|
||||
.venv/bin/pip install -e ".[dev]"
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue