mirror of
https://github.com/CartoDB/crankshaft.git
synced 2024-11-01 10:20:48 +08:00
Basic structure of the extension & package
This commit is contained in:
parent
561d1282b3
commit
cfd3646fc3
38
CONTRIBUTING.md
Normal file
38
CONTRIBUTING.md
Normal 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
17
DEPLOYING.md
Normal 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:
|
||||||
|
|
||||||
|
...
|
16
README.md
16
README.md
@ -1 +1,17 @@
|
|||||||
# crankshaft
|
# 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
3
pg/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dist/
|
||||||
|
test/regression.diffs
|
||||||
|
test/regression.out
|
22
pg/Makefile
Normal file
22
pg/Makefile
Normal 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
7
pg/README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
# Running the tests:
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo make install
|
||||||
|
PGUSER=postgres make installcheck
|
||||||
|
```
|
5
pg/crankshaft.control
Normal file
5
pg/crankshaft.control
Normal 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
5
pg/sql/poc_xyz.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION cdb_poc_xyz()
|
||||||
|
RETURNS Text AS $$
|
||||||
|
from crankshaft.poc import xyz
|
||||||
|
return xyz()
|
||||||
|
$$ LANGUAGE plpythonu;
|
4
pg/test/expected/01_install_test.out
Normal file
4
pg/test/expected/01_install_test.out
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
-- Install dependencies
|
||||||
|
CREATE EXTENSION plpythonu;
|
||||||
|
-- Install the extension
|
||||||
|
CREATE EXTENSION crankshaft;
|
6
pg/test/expected/02_poc_xyz_test.out
Normal file
6
pg/test/expected/02_poc_xyz_test.out
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
SELECT cdb_crankshaft.cdb_poc_xyz();
|
||||||
|
cdb_poc_xyz
|
||||||
|
-------------
|
||||||
|
xyz-result
|
||||||
|
(1 row)
|
||||||
|
|
4
pg/test/results/01_install_test.out
Normal file
4
pg/test/results/01_install_test.out
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
-- Install dependencies
|
||||||
|
CREATE EXTENSION plpythonu;
|
||||||
|
-- Install the extension
|
||||||
|
CREATE EXTENSION crankshaft;
|
6
pg/test/results/02_poc_xyz_test.out
Normal file
6
pg/test/results/02_poc_xyz_test.out
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
SELECT cdb_crankshaft.cdb_poc_xyz();
|
||||||
|
cdb_poc_xyz
|
||||||
|
-------------
|
||||||
|
xyz-result
|
||||||
|
(1 row)
|
||||||
|
|
5
pg/test/sql/01_install_test.sql
Normal file
5
pg/test/sql/01_install_test.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
-- Install dependencies
|
||||||
|
CREATE EXTENSION plpythonu;
|
||||||
|
|
||||||
|
-- Install the extension
|
||||||
|
CREATE EXTENSION crankshaft;
|
1
pg/test/sql/02_poc_xyz_test.sql
Normal file
1
pg/test/sql/02_poc_xyz_test.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
SELECT cdb_crankshaft.cdb_poc_xyz();
|
1
python/.gitignore
vendored
Normal file
1
python/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.pyc
|
9
python/README.md
Normal file
9
python/README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Crankshaft Python Package
|
||||||
|
|
||||||
|
...
|
||||||
|
### Run the tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd crankshaft
|
||||||
|
nosetests test/
|
||||||
|
```
|
1
python/crankshaft/crankshaft/__init__.py
Normal file
1
python/crankshaft/crankshaft/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
import poc
|
1
python/crankshaft/crankshaft/poc/__init__.py
Normal file
1
python/crankshaft/crankshaft/poc/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from xyz import *
|
3
python/crankshaft/crankshaft/poc/xyz.py
Normal file
3
python/crankshaft/crankshaft/poc/xyz.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
def xyz():
|
||||||
|
# print "XYZ"
|
||||||
|
return "xyz-result"
|
48
python/crankshaft/setup.py
Normal file
48
python/crankshaft/setup.py
Normal 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'
|
||||||
|
)
|
9
python/crankshaft/test/test_poc.py
Normal file
9
python/crankshaft/test/test_poc.py
Normal 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"
|
Loading…
Reference in New Issue
Block a user