Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d6bc2ef
key word only
chinedu117 Feb 19, 2023
0e5f075
Geography SRID 4326
chinedu117 Feb 19, 2023
14cbc00
Creates opencdms types
chinedu117 Feb 19, 2023
ddcec81
Set location to wkb
chinedu117 Feb 19, 2023
f509baa
Install pygeoapi
chinedu117 Feb 19, 2023
6eb317d
Adds observation dto
chinedu117 Feb 19, 2023
1b3d9a4
pygeoapi Adds CDMSProvider
chinedu117 Feb 19, 2023
7170373
Pygeoapi config
chinedu117 Feb 19, 2023
33190b3
opencdms test data
chinedu117 Feb 19, 2023
de63f12
Edits makefile config
chinedu117 Feb 19, 2023
59dc3a5
Updates makefile
chinedu117 Feb 21, 2023
501aade
Updates requirements
chinedu117 Feb 28, 2023
352543f
port as env variable
chinedu117 Feb 28, 2023
f63eabb
Unpin requirements
chinedu117 Feb 28, 2023
5833777
default port
chinedu117 Feb 28, 2023
e72658f
Updates model def
chinedu117 Feb 28, 2023
646740a
updates cdm test
chinedu117 Feb 28, 2023
4f52960
setup test
chinedu117 Feb 28, 2023
15f35a1
Avoid name conflict
chinedu117 Mar 2, 2023
832b8b1
Update schema
chinedu117 Mar 2, 2023
e9be550
compatible with py 3.9
chinedu117 Mar 2, 2023
c2bbdc0
Adds tests
chinedu117 Mar 2, 2023
2254250
Removes unused dependencies
chinedu117 Mar 2, 2023
17a7ec4
Removes dtos
chinedu117 Mar 2, 2023
1a996de
Pyyaml
chinedu117 Mar 2, 2023
571b585
Configure pygeoapi
chinedu117 Mar 2, 2023
0171208
Remove debug
chinedu117 Mar 2, 2023
c681f79
Refactors test
chinedu117 Mar 2, 2023
a7b77ec
Adds convenient cli commands
chinedu117 Mar 2, 2023
5aa467f
Create seeder function
chinedu117 Mar 2, 2023
016434d
Adds helper make commands
chinedu117 Mar 2, 2023
8665f96
Updates readme
chinedu117 Mar 2, 2023
c9ab7ee
corrects timezone abbr
chinedu117 Mar 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT

### Export container ports ###
export CDM_DB_PORT=35432
export PYGEOAPI_CONFIG=$(PWD)/pygeoapi-config.yml
export PYGEOAPI_OPENAPI=$(PWD)/pygeoapi-openapi.yml
define PRINT_HELP_PYSCRIPT
import re, sys

Expand All @@ -33,7 +37,7 @@ clean-build: ## remove build artifacts
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.egg' -exec rm -fr {} +

clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
Expand All @@ -50,9 +54,16 @@ clean-test: ## remove test and coverage artifacts
lint: ## check style with flake8
flake8 opencdms tests

test: ## run tests quickly with the default Python
startdb: ## Step up db containers needed for tests
opencdms-test-data startdb --containers opencdmsdb
sleep 20

test: startdb ## run tests quickly with the default Python
pytest

stop-db: ## Bring down docker containers after test
opencdms-test-data stopdb

test-all: ## run tests on every Python version with tox
tox

Expand Down Expand Up @@ -83,3 +94,15 @@ dist: clean ## builds source and wheel package

install: clean ## install the package to the active Python's site-packages
python setup.py install

install-dev: install ## Install dev dependencies
pip install -r requirements_dev.txt

pygeoapi: ## Start pygeoapi default server
pygeoapi serve

seed-db: startdb ## Seed database with random data
opencdms seed-db

clear-db: ## Drops test database
opencdms clear-db
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,36 @@ The [opencdms-test-data](https://github.com/opencdms/opencdms-test-data) reposit
It is expected that SQLAlchemy objects, Panda's [DataFrames](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html) and JSON will be key data types for exchanging data.

<!-- Geospatial dependencies like [PostGIS](http://postgis.net/), [GeoAlchemy2](https://github.com/geoalchemy/geoalchemy2) and [SpatiaLite](https://en.wikipedia.org/wiki/SpatiaLite) may be introduced in the future if required. -->


### Launching Pygeoapi for development

1. Install the package.
```
make install-dev
```
2. Launch developement database

```
make start-db
```
3. Seed the database with test data.
```
make seed-db
```
4. Launch Pygeoapi server
```
make pygeoapi
```
5. Visit localhost:5000

6. To stop the server, press CTRL+C

7. Clear the test database
```
make clear-db
```
8. Remove the database container
```
make stop-db
```
8 changes: 8 additions & 0 deletions cdms_pygeoapi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pygeoapi.provider.postgresql import PostgreSQLProvider


class CDMSProvider(PostgreSQLProvider):
def __init__(self, provider_def):
super().__init__(provider_def=provider_def)
self.conn_dic = provider_def["data"]
self.get_fields()
78 changes: 78 additions & 0 deletions opencdms/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Console script for opencdms."""
import pathlib
import sys
import click
import yaml
from opencdms.utils import seeder

@click.group()
def main(args=None):
"""Console script for opencdms."""
# See click documentation at https://click.palletsprojects.com/
pass


@click.command(name="seed-db")
def seed_db():
""" Creates tables and populates them with random data"""
click.echo("Generating random data....")
seeder.up()
click.echo("Successfully inserted random data into DB")

@click.command(name="clear-db")
def clear_db():
""" Drops all tables in cdms testdata base"""
click.echo("Dropping database ...")
seeder.down()
click.echo("Successfully cleared database")

@click.command(name="relocate-schema")
@click.argument("filepath")
@click.argument("resource")
def relocate_schema(filepath, resource):
"""
Relocates local definitions to the document root of OpenAPI config file
"""
if not pathlib.Path(filepath).exists():
click.echo("OpenAPI config file does not exist.", err=True)
return

with open(filepath, "r") as stream:
openapi_config = yaml.load(stream, yaml.Loader)
root_definitions = openapi_config.get("definitions", {})
path_config = openapi_config.get("paths", {}).get(
f"/collections/{resource}/items/{{featureId}}"
)
put_request_definitions = (
path_config.get("put", {})
.get("requestBody", {})
.get("content", {})
.get("application/json", {})
.get("schema", {})
.get("definitions", {})
)
get_responses_definitions = (
path_config.get("get", {})
.get("responses", {})
.get("200", {})
.get("content", {})
.get("application/json", {})
.get("schema", {})
.get("definitions", {})
)
openapi_config["definitions"] = {
**root_definitions,
**put_request_definitions,
**get_responses_definitions,
}

with open(filepath, "w") as stream:
yaml.dump(openapi_config, stream)


main.add_command(relocate_schema)
main.add_command(seed_db)
main.add_command(clear_db)

if __name__ == "__main__":
sys.exit(main()) # pragma: no cover
13 changes: 13 additions & 0 deletions opencdms/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import os


class OpenCDMSConfig:
CDM_DB_HOST = os.getenv("CDM_DB_HOST", "127.0.0.1")
CDM_DB_PORT = os.getenv("CDM_DB_PORT", 5432)
CDM_DB_USER = os.getenv("CDM_DB_USER", "postgres")
CDM_DB_PASS = os.getenv("CDM_DB_PASSWORD", "password")
CDM_DB_NAME = os.getenv("CDM_DB_NAME", "postgres")
CDM_DB_ENGINE = os.getenv("CDM_DB_ENGINE", "postgresql")
CDM_DB_DRIVER = os.getenv("CDM_DB_DRIVER", "psycopg2")
config = OpenCDMSConfig()
Loading