From f2d8bb84b2e92f1e457dbb5c02e989017a40d692 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Tue, 15 Mar 2016 16:16:54 +0100 Subject: [PATCH] Implement release with variant python package names Instead of having to use different virtual environments for development and for each version to be used in development here we're using differnt names for each release's python package. There a pending problem here: pip replaces underscores in the package name by dashes when installing it. --- Makefile | 12 +++++++++--- README.md | 9 ++++++++- release/.gitignore | 0 src/pg/Makefile | 26 ++++++++++++++++++++++---- src/pg/sql/02_py.sql | 6 ++---- src/py/.gitignore | 2 +- src/py/Makefile | 10 +++++----- 7 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 release/.gitignore diff --git a/Makefile b/Makefile index 5cae2cb..f4abbaa 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,12 @@ install: $(MAKE) -C $(PYP_DIR) install $(MAKE) -C $(EXT_DIR) install -testinstalled: - $(MAKE) -C $(PYP_DIR) testinstalled - $(MAKE) -C $(EXT_DIR) installcheck +test: + $(MAKE) -C $(PYP_DIR) test + $(MAKE) -C $(EXT_DIR) test + +release: install + $(MAKE) -C $(EXT_DIR) release + +deploy: + echo 'not yet implemented' diff --git a/README.md b/README.md index c9dd529..83d71bb 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,14 @@ Update local installation with `sudo make install` Run the tests with `PGUSER=postgres make test` -Update extension in working database with +The commands mentioned, executed from the top directory, +install and test both the Pyhton package and the PostgreSQL extension. + +When developing the Pyhon package, it can be +installed and tested in its own from the `src/pg` directory with the same commands. + +When a new development extension has beeen installed it is available +in PostgreSQL; update extension in any specific database with * `ALTER EXTENSION crankshaft VERSION TO 'current';` `ALTER EXTENSION crankshaft VERSION TO 'dev';` diff --git a/release/.gitignore b/release/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/src/pg/Makefile b/src/pg/Makefile index ed65eba..28279ee 100644 --- a/src/pg/Makefile +++ b/src/pg/Makefile @@ -16,7 +16,7 @@ DATA = $(EXTENSION)--dev.sql \ SOURCES_DATA_DIR = sql SOURCES_DATA = $(wildcard $(SOURCES_DATA_DIR)/*.sql) -VIRTUALENV_PATH = $(realpath ../py/) +VIRTUALENV_PATH = $(realpath ../py/environment) ESC_VIRVIRTUALENV_PATH = $(subst /,\/,$(VIRTUALENV_PATH)) REPLACEMENTS = -e 's/@@VERSION@@/$(EXTVERSION)/g' \ @@ -41,8 +41,26 @@ all: $(DATA) EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/") -../release/$(EXTENSION).control: $(EXTENSION).control +RELEASED_PACKAGE = crankshaft_$(subst .,_,$(EXTVERSION)) + +RELEASE_REPLACEMENTS = -e 's/import\scrankshaft/import $(RELEASED_PACKAGE)/g' \ + -e 's/from\scrankshaft/from $(RELEASED_PACKAGE)/g' + +../../release/$(EXTENSION).control: $(EXTENSION).control cp $< $@ -release: ../release/$(EXTENSION).control - cp $(EXTENSION)--dev.sql $(EXTENSION)--$(EXTVERSION).sql +release: ../../release/$(EXTENSION).control + # ALTERNATIVE: use release virtualenv; copy here files from src replacing VIRTUALENV_PATH + $(SED) $(RELEASE_REPLACEMENTS) $(EXTENSION)--dev.sql > ../../release/$(EXTENSION)--$(EXTVERSION).sql + cp -r ../py/crankshaft ../../release/$(RELEASED_PACKAGE) + $(SED) -i -e 's/name='"'"'crankshaft'"'"'/name='"'"'$(RELEASED_PACKAGE)'"'"'/g' ../../release/$(RELEASED_PACKAGE)/setup.py + +install_release: + $(INSTALL_DATA) ../../release/$(EXTENSION).control '$(DESTDIR)$(datadir)/extension/' + $(INSTALL_DATA) ../../release/*.sql '$(DESTDIR)$(datadir)/extension/' + # virtualenv --system-site-packages ../py/dev + ../py/environment/bin/pip install -I -U ../../release/$(RELEASED_PACKAGE) + ../py/environment/bin/pip install -I nose + +test: export PGUSER=postgres +test: installcheck diff --git a/src/pg/sql/02_py.sql b/src/pg/sql/02_py.sql index a233a0a..b940fe5 100644 --- a/src/pg/sql/02_py.sql +++ b/src/pg/sql/02_py.sql @@ -1,4 +1,4 @@ -CREATE OR REPLACE FUNCTION _cdb_crankshaft_virtualenvs_path() +CREATE OR REPLACE FUNCTION _cdb_crankshaft_virtualenv_path() RETURNS text AS $$ BEGIN @@ -14,9 +14,7 @@ AS $$ import os # plpy.notice('%',str(os.environ)) # activate virtualenv - crankshaft_version = plpy.execute('SELECT cdb_crankshaft.cdb_crankshaft_internal_version()')[0]['cdb_crankshaft_internal_version'] - base_path = plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_virtualenvs_path()')[0]['_cdb_crankshaft_virtualenvs_path'] - default_venv_path = os.path.join(base_path, crankshaft_version) + default_venv_path = plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_virtualenv_path()')[0]['_cdb_crankshaft_virtualenv_path'] venv_path = os.environ.get('CRANKSHAFT_VENV', default_venv_path) activate_path = venv_path + '/bin/activate_this.py' exec(open(activate_path).read(), dict(__file__=activate_path)) diff --git a/src/py/.gitignore b/src/py/.gitignore index fb50fe5..98a71cf 100644 --- a/src/py/.gitignore +++ b/src/py/.gitignore @@ -1,2 +1,2 @@ *.pyc -dev/ +environment/ diff --git a/src/py/Makefile b/src/py/Makefile index 16be269..51c568f 100644 --- a/src/py/Makefile +++ b/src/py/Makefile @@ -1,9 +1,9 @@ # Install the package locally for development install: - virtualenv --system-site-packages dev - ./dev/bin/pip install -I ./crankshaft - ./dev/bin/pip install -I nose + virtualenv --system-site-packages environment + ./environment/bin/pip install -I -U ./crankshaft + ./environment/bin/pip install -I nose # Test develpment install -testinstalled: - ./dev/bin/nosetests crankshaft/test/ +test: + ./environment/bin/nosetests crankshaft/test/