From cfd3646fc3b7a73e49b2c0bdbcee14d7bd0ba899 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 15 Feb 2016 18:29:43 +0100 Subject: [PATCH] Basic structure of the extension & package --- CONTRIBUTING.md | 38 ++++++++++++++++ DEPLOYING.md | 17 +++++++ README.md | 18 +++++++- pg/.gitignore | 3 ++ pg/Makefile | 22 +++++++++ pg/README.md | 7 +++ pg/crankshaft.control | 5 ++ pg/sql/poc_xyz.sql | 5 ++ pg/test/expected/01_install_test.out | 4 ++ pg/test/expected/02_poc_xyz_test.out | 6 +++ pg/test/results/01_install_test.out | 4 ++ pg/test/results/02_poc_xyz_test.out | 6 +++ pg/test/sql/01_install_test.sql | 5 ++ pg/test/sql/02_poc_xyz_test.sql | 1 + python/.gitignore | 1 + python/README.md | 9 ++++ python/crankshaft/crankshaft/__init__.py | 1 + python/crankshaft/crankshaft/poc/__init__.py | 1 + python/crankshaft/crankshaft/poc/xyz.py | 3 ++ python/crankshaft/setup.py | 48 ++++++++++++++++++++ python/crankshaft/test/test_poc.py | 9 ++++ 21 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 CONTRIBUTING.md create mode 100644 DEPLOYING.md create mode 100644 pg/.gitignore create mode 100644 pg/Makefile create mode 100644 pg/README.md create mode 100644 pg/crankshaft.control create mode 100644 pg/sql/poc_xyz.sql create mode 100644 pg/test/expected/01_install_test.out create mode 100644 pg/test/expected/02_poc_xyz_test.out create mode 100644 pg/test/results/01_install_test.out create mode 100644 pg/test/results/02_poc_xyz_test.out create mode 100644 pg/test/sql/01_install_test.sql create mode 100644 pg/test/sql/02_poc_xyz_test.sql create mode 100644 python/.gitignore create mode 100644 python/README.md create mode 100644 python/crankshaft/crankshaft/__init__.py create mode 100644 python/crankshaft/crankshaft/poc/__init__.py create mode 100644 python/crankshaft/crankshaft/poc/xyz.py create mode 100644 python/crankshaft/setup.py create mode 100644 python/crankshaft/test/test_poc.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0bc8a53 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,38 @@ +# Contributing guide + +## How to add new functions + +Try to put as little logic in the SQL extension as possible and +just use it as a wrapper to the Python module functionality. + +### Python + +... + +### SQL + +* Generate a **new subfolder version** for `sql` and `test` folders to define the new functions and tests + * Use symlinks to avoid file duplication between versions that don't update them + * Add or upgrade your SQL server functions + * Create tests for the client and server functions -- at least, to check that those are created + +* Generate the **upgrade and downgrade files** for the extension for both client and server + +* Update the control files and the Makefiles to generate the complete SQL file for the new created version + * These new version file (`crankshaft--X.Y.Z.sql`) + must be pushed and frozen. You should add it to the `.gitignore` file. + +* Update the public docs! ;-) + +## Naming things + +# SQL + +Use snake case (i.e. `snake_case` and not `CamelCase`) for all +functions. Prefix functions intended for public use with `cdb_` +and private functions (to be used only internally inside +the extension) with `_cdb_`. + +# Python + +... diff --git a/DEPLOYING.md b/DEPLOYING.md new file mode 100644 index 0000000..69e91b8 --- /dev/null +++ b/DEPLOYING.md @@ -0,0 +1,17 @@ +# Deployment + +... + +Deployment + +``` +# Install python module +sudo pip install {{path}}/python/crankshaft --upgrade + +# Install extension +cd {{path}}/pg && sudo PGUSER=postgres make all install +``` + +Installing the extension in user databases: + +... diff --git a/README.md b/README.md index 662bee5..56930f5 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ -# crankshaft \ No newline at end of file +# crankshaft + +CartoDB Spatial Analysis extension for PostgreSQL. + +## Code organization + +* *pg* contains the PostgreSQL extension source code +* *python* Python module + +FIXME: should it be `./extension` and `./lib/python' ? + +## Requirements + +* pip + +* sudo pip install nose +* CREATE LANGUAGE 'plpythonu'; diff --git a/pg/.gitignore b/pg/.gitignore new file mode 100644 index 0000000..d6e8587 --- /dev/null +++ b/pg/.gitignore @@ -0,0 +1,3 @@ +dist/ +test/regression.diffs +test/regression.out diff --git a/pg/Makefile b/pg/Makefile new file mode 100644 index 0000000..acc6bf3 --- /dev/null +++ b/pg/Makefile @@ -0,0 +1,22 @@ +EXTENSION = crankshaft +EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/") + +DATA = dist/$(EXTENSION)--$(EXTVERSION).sql + +SOURCES_DATA_DIR = sql +SOURCES_DATA = $(wildcard sql/$(EXTVERSION)/*.sql) + +dist/$(EXTENSION)--$(EXTVERSION).sql: $(SOURCES_DATA) + rm -f $@ + cat $(SOURCES_DATA_DIR)/*.sql >> $@ + +dist/$(EXTENSION).control: $(EXTENSION).control + cp $< $@ + +REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql))) +TEST_DIR = test +REGRESS_OPTS = --inputdir='$(TEST_DIR)' --outputdir='$(TEST_DIR)' + +PG_CONFIG = pg_config +PGXS := $(shell $(PG_CONFIG) --pgxs) +include $(PGXS) diff --git a/pg/README.md b/pg/README.md new file mode 100644 index 0000000..511fdae --- /dev/null +++ b/pg/README.md @@ -0,0 +1,7 @@ + +# Running the tests: + +``` +sudo make install +PGUSER=postgres make installcheck +``` diff --git a/pg/crankshaft.control b/pg/crankshaft.control new file mode 100644 index 0000000..208ffb6 --- /dev/null +++ b/pg/crankshaft.control @@ -0,0 +1,5 @@ +comment = 'CartoDB Spatial Analysis extension' +default_version = '0.0.1' +requires = 'plpythonu' +superuser = true +schema = cdb_crankshaft diff --git a/pg/sql/poc_xyz.sql b/pg/sql/poc_xyz.sql new file mode 100644 index 0000000..e342f68 --- /dev/null +++ b/pg/sql/poc_xyz.sql @@ -0,0 +1,5 @@ +CREATE OR REPLACE FUNCTION cdb_poc_xyz() +RETURNS Text AS $$ + from crankshaft.poc import xyz + return xyz() +$$ LANGUAGE plpythonu; diff --git a/pg/test/expected/01_install_test.out b/pg/test/expected/01_install_test.out new file mode 100644 index 0000000..26bd1bf --- /dev/null +++ b/pg/test/expected/01_install_test.out @@ -0,0 +1,4 @@ +-- Install dependencies +CREATE EXTENSION plpythonu; +-- Install the extension +CREATE EXTENSION crankshaft; diff --git a/pg/test/expected/02_poc_xyz_test.out b/pg/test/expected/02_poc_xyz_test.out new file mode 100644 index 0000000..bb23ea2 --- /dev/null +++ b/pg/test/expected/02_poc_xyz_test.out @@ -0,0 +1,6 @@ +SELECT cdb_crankshaft.cdb_poc_xyz(); + cdb_poc_xyz +------------- + xyz-result +(1 row) + diff --git a/pg/test/results/01_install_test.out b/pg/test/results/01_install_test.out new file mode 100644 index 0000000..26bd1bf --- /dev/null +++ b/pg/test/results/01_install_test.out @@ -0,0 +1,4 @@ +-- Install dependencies +CREATE EXTENSION plpythonu; +-- Install the extension +CREATE EXTENSION crankshaft; diff --git a/pg/test/results/02_poc_xyz_test.out b/pg/test/results/02_poc_xyz_test.out new file mode 100644 index 0000000..bb23ea2 --- /dev/null +++ b/pg/test/results/02_poc_xyz_test.out @@ -0,0 +1,6 @@ +SELECT cdb_crankshaft.cdb_poc_xyz(); + cdb_poc_xyz +------------- + xyz-result +(1 row) + diff --git a/pg/test/sql/01_install_test.sql b/pg/test/sql/01_install_test.sql new file mode 100644 index 0000000..11e8d14 --- /dev/null +++ b/pg/test/sql/01_install_test.sql @@ -0,0 +1,5 @@ +-- Install dependencies +CREATE EXTENSION plpythonu; + +-- Install the extension +CREATE EXTENSION crankshaft; diff --git a/pg/test/sql/02_poc_xyz_test.sql b/pg/test/sql/02_poc_xyz_test.sql new file mode 100644 index 0000000..62f7893 --- /dev/null +++ b/pg/test/sql/02_poc_xyz_test.sql @@ -0,0 +1 @@ +SELECT cdb_crankshaft.cdb_poc_xyz(); diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/python/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/python/README.md b/python/README.md new file mode 100644 index 0000000..f342bf2 --- /dev/null +++ b/python/README.md @@ -0,0 +1,9 @@ +# Crankshaft Python Package + +... +### Run the tests + +```bash +cd crankshaft +nosetests test/ +``` diff --git a/python/crankshaft/crankshaft/__init__.py b/python/crankshaft/crankshaft/__init__.py new file mode 100644 index 0000000..dddc2b3 --- /dev/null +++ b/python/crankshaft/crankshaft/__init__.py @@ -0,0 +1 @@ +import poc diff --git a/python/crankshaft/crankshaft/poc/__init__.py b/python/crankshaft/crankshaft/poc/__init__.py new file mode 100644 index 0000000..90ac56c --- /dev/null +++ b/python/crankshaft/crankshaft/poc/__init__.py @@ -0,0 +1 @@ +from xyz import * diff --git a/python/crankshaft/crankshaft/poc/xyz.py b/python/crankshaft/crankshaft/poc/xyz.py new file mode 100644 index 0000000..cd5160a --- /dev/null +++ b/python/crankshaft/crankshaft/poc/xyz.py @@ -0,0 +1,3 @@ +def xyz(): + # print "XYZ" + return "xyz-result" diff --git a/python/crankshaft/setup.py b/python/crankshaft/setup.py new file mode 100644 index 0000000..b20ff5f --- /dev/null +++ b/python/crankshaft/setup.py @@ -0,0 +1,48 @@ + +""" +CartoDB Spatial Analysis Python Library +See: +https://github.com/CartoDB/crankshaft +""" + +from setuptools import setup, find_packages + +REQUIRES = [] # ['pysal','numpy'] + +setup( + name='crankshaft', + + version='0.0.01', + + description='CartoDB Spatial Analysis Python Library', + + url='https://github.com/CartoDB/crankshaft', + + author='Data Services Team - CartoDB', + author_email='dataservices@cartodb.com', + + license='MIT', + + classifiers=[ + 'Development Status :: 1 - Planning', + 'Intended Audience :: Mapping comunity', + 'Topic :: Maps :: Mapping Tools', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 2.7', + ], + + keywords='maps mapping tools spatial analysis geostatistics', + + packages=find_packages(exclude=['contrib', 'docs', 'tests']), + + extras_require={ + 'dev': ['unittest'], + 'test': ['unittest', 'nose', 'mockredispy', 'mock'], + }, + + # install_requires=REQUIRES, + + # requires=REQUIRES, + + test_suite='test' +) diff --git a/python/crankshaft/test/test_poc.py b/python/crankshaft/test/test_poc.py new file mode 100644 index 0000000..13285ea --- /dev/null +++ b/python/crankshaft/test/test_poc.py @@ -0,0 +1,9 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- + +import unittest +import crankshaft + +class TestPoc(unittest.TestCase): + def test_should_have_xyz(self): + assert crankshaft.poc.xyz() == "xyz-result"