Basic structure of the extension & package

This commit is contained in:
Javier Goizueta 2016-02-15 18:29:43 +01:00
parent 561d1282b3
commit cfd3646fc3
21 changed files with 212 additions and 1 deletions

38
CONTRIBUTING.md Normal file
View File

@ -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
...

17
DEPLOYING.md Normal file
View File

@ -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:
...

View File

@ -1 +1,17 @@
# 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';

3
pg/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
dist/
test/regression.diffs
test/regression.out

22
pg/Makefile Normal file
View File

@ -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)

7
pg/README.md Normal file
View File

@ -0,0 +1,7 @@
# Running the tests:
```
sudo make install
PGUSER=postgres make installcheck
```

5
pg/crankshaft.control Normal file
View File

@ -0,0 +1,5 @@
comment = 'CartoDB Spatial Analysis extension'
default_version = '0.0.1'
requires = 'plpythonu'
superuser = true
schema = cdb_crankshaft

5
pg/sql/poc_xyz.sql Normal file
View File

@ -0,0 +1,5 @@
CREATE OR REPLACE FUNCTION cdb_poc_xyz()
RETURNS Text AS $$
from crankshaft.poc import xyz
return xyz()
$$ LANGUAGE plpythonu;

View File

@ -0,0 +1,4 @@
-- Install dependencies
CREATE EXTENSION plpythonu;
-- Install the extension
CREATE EXTENSION crankshaft;

View File

@ -0,0 +1,6 @@
SELECT cdb_crankshaft.cdb_poc_xyz();
cdb_poc_xyz
-------------
xyz-result
(1 row)

View File

@ -0,0 +1,4 @@
-- Install dependencies
CREATE EXTENSION plpythonu;
-- Install the extension
CREATE EXTENSION crankshaft;

View File

@ -0,0 +1,6 @@
SELECT cdb_crankshaft.cdb_poc_xyz();
cdb_poc_xyz
-------------
xyz-result
(1 row)

View File

@ -0,0 +1,5 @@
-- Install dependencies
CREATE EXTENSION plpythonu;
-- Install the extension
CREATE EXTENSION crankshaft;

View File

@ -0,0 +1 @@
SELECT cdb_crankshaft.cdb_poc_xyz();

1
python/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

9
python/README.md Normal file
View File

@ -0,0 +1,9 @@
# Crankshaft Python Package
...
### Run the tests
```bash
cd crankshaft
nosetests test/
```

View File

@ -0,0 +1 @@
import poc

View File

@ -0,0 +1 @@
from xyz import *

View File

@ -0,0 +1,3 @@
def xyz():
# print "XYZ"
return "xyz-result"

View File

@ -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'
)

View File

@ -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"