Set the path to virtualenvs in the Makefile
Also, version the virtualenv
This commit is contained in:
parent
1810f02242
commit
0056f411b5
@ -5,6 +5,8 @@
|
||||
# and make it available to PostgreSQL
|
||||
# PGUSER=postgres make installcheck -- test the 'dev' extension
|
||||
|
||||
SED = sed
|
||||
|
||||
EXTENSION = crankshaft
|
||||
|
||||
DATA = $(EXTENSION)--dev.sql \
|
||||
@ -14,8 +16,14 @@ DATA = $(EXTENSION)--dev.sql \
|
||||
SOURCES_DATA_DIR = sql
|
||||
SOURCES_DATA = $(wildcard $(SOURCES_DATA_DIR)/*.sql)
|
||||
|
||||
VIRTUALENV_PATH = $(realpath ../py/)
|
||||
ESC_VIRVIRTUALENV_PATH = $(subst /,\/,$(VIRTUALENV_PATH))
|
||||
|
||||
REPLACEMENTS = -e 's/@@VERSION@@/$(EXTVERSION)/g' \
|
||||
-e 's/@@VIRTUALENV_PATH@@/$(ESC_VIRVIRTUALENV_PATH)/g'
|
||||
|
||||
$(DATA): $(SOURCES_DATA)
|
||||
cat $(SOURCES_DATA_DIR)/*.sql > $@
|
||||
$(SED) $(REPLACEMENTS) $(SOURCES_DATA_DIR)/*.sql > $@
|
||||
|
||||
TEST_DIR = test
|
||||
REGRESS = $(notdir $(basename $(wildcard $(TEST_DIR)/sql/*test.sql)))
|
||||
@ -28,6 +36,7 @@ include $(PGXS)
|
||||
# This seems to be needed at least for PG 9.3.11
|
||||
all: $(DATA)
|
||||
|
||||
|
||||
# WIP: goals for releasing the extension...
|
||||
|
||||
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
|
||||
|
@ -1,18 +0,0 @@
|
||||
-- Use the crankshaft python module
|
||||
CREATE OR REPLACE FUNCTION _cdb_crankshaft_activate_py()
|
||||
RETURNS VOID
|
||||
AS $$
|
||||
# activate virtualenv
|
||||
# TODO: parameterize with environment variables or something
|
||||
venv_path = '/home/ubuntu/crankshaft/src/py/dev'
|
||||
activate_path = venv_path + '/bin/activate_this.py'
|
||||
exec(open(activate_path).read(),
|
||||
dict(__file__=activate_path))
|
||||
|
||||
# import something from virtualenv
|
||||
# from crankshaft import random_seeds
|
||||
|
||||
# do some stuff
|
||||
# random_seeds.set_random_seeds(123)
|
||||
# plpy.notice('here we are')
|
||||
$$ LANGUAGE plpythonu;
|
12
src/pg/sql/01_version.sql
Normal file
12
src/pg/sql/01_version.sql
Normal file
@ -0,0 +1,12 @@
|
||||
-- Version number of the extension release
|
||||
CREATE OR REPLACE FUNCTION cdb_crankshaft_version()
|
||||
RETURNS text AS $$
|
||||
SELECT '@@VERSION@@'::text;
|
||||
$$ language 'sql' IMMUTABLE STRICT;
|
||||
|
||||
-- Internal identifier of the installed extension instence
|
||||
-- e.g. 'dev' for current development version
|
||||
CREATE OR REPLACE FUNCTION cdb_crankshaft_internal_version()
|
||||
RETURNS text AS $$
|
||||
SELECT installed_version FROM pg_available_extensions where name='crankshaft' and pg_available_extensions IS NOT NULL;
|
||||
$$ language 'sql' IMMUTABLE STRICT;
|
23
src/pg/sql/02_py.sql
Normal file
23
src/pg/sql/02_py.sql
Normal file
@ -0,0 +1,23 @@
|
||||
CREATE OR REPLACE FUNCTION _cdb_crankshaft_virtualenvs_path()
|
||||
RETURNS text
|
||||
AS $$
|
||||
BEGIN
|
||||
-- RETURN '/opt/virtualenvs/crankshaft';
|
||||
RETURN '@@VIRTUALENV_PATH@@';
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE STRICT;
|
||||
|
||||
-- Use the crankshaft python module
|
||||
CREATE OR REPLACE FUNCTION _cdb_crankshaft_activate_py()
|
||||
RETURNS VOID
|
||||
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)
|
||||
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))
|
||||
$$ LANGUAGE plpythonu;
|
Loading…
Reference in New Issue
Block a user