Skip to content

Commit f5ed13a

Browse files
committed
Adding more files, fixing gitignore
1 parent 48229f1 commit f5ed13a

File tree

10 files changed

+223
-0
lines changed

10 files changed

+223
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -x
4+
5+
if [[ "${VIRTUAL_ENV}" == "" ]]; then
6+
echo "error: VIRTUAL_ENV not set"
7+
exit 1
8+
fi
9+
10+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
12+
# this is needed so that Go builds can find the Python headers etc
13+
cp -frv "${DIR}/python-config" "${VIRTUAL_ENV}/bin/python-config"
14+
15+
# this is needed so that our Go builds can find the common tooling when invoked from within a Virtualenv
16+
cp -frv "${DIR}/native_build.sh" "${VIRTUAL_ENV}/bin/native_build.sh"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -x
4+
5+
if [[ "${1}" == "" ]]; then
6+
echo "error: first argument must be name of lib (e.g. gomssql)"
7+
exit 1
8+
fi
9+
10+
NAME_OF_LIB="${1}"
11+
12+
if [[ "${VIRTUAL_ENV}" == "" ]]; then
13+
echo "error: a virtualenv must be activated"
14+
exit 1
15+
fi
16+
17+
# TODO
18+
# GO_VERSION="$(go version)"
19+
# if [[ ${GO_VERSION} != *"go1.13"* ]]; then
20+
# echo "error: Go version is not 1.13 (was ${GO_VERSION})"
21+
# exit 1
22+
# fi
23+
24+
PKG_CONFIG_PATH="$(pwd)"
25+
export PKG_CONFIG_PATH
26+
27+
OUTPUT_PATH="${NAME_OF_LIB}_python/built"
28+
29+
if [[ "${2}" != "fast" ]]; then
30+
echo "installing python deps..."
31+
pip install --upgrade -r requirements-dev.txt
32+
echo ""
33+
34+
echo "installing goimports..."
35+
go get golang.org/x/tools/cmd/goimports
36+
echo ""
37+
38+
echo "installing gopy..."
39+
go get github.com/go-python/[email protected]
40+
echo ""
41+
fi
42+
43+
echo "cleaning up output folder..."
44+
rm -frv "${OUTPUT_PATH:?}/*" || true
45+
mkdir -p "${OUTPUT_PATH}" || true
46+
touch "${OUTPUT_PATH}/__init__.py" || true
47+
echo ""
48+
49+
echo "building ${NAME_OF_LIB}-python..."
50+
export PATH=${PATH}:~/go/bin/
51+
export CFLAGS
52+
export C_INCLUDE_PATH
53+
gopy build -output="${OUTPUT_PATH}" -symbols=true -vm="$(command -v python)" "./${NAME_OF_LIB}_python_go"
54+
echo ""
55+
56+
echo "hacking in some sed fixes..."
57+
sed -i'.bak' "s/import _${NAME_OF_LIB}_python_go/from ${NAME_OF_LIB}_python.built import _${NAME_OF_LIB}_python_go/g" "${NAME_OF_LIB}_python/built/${NAME_OF_LIB}_python_go.py"
58+
sed -i'.bak' "s/import go/from ${NAME_OF_LIB}_python.built import go/g" "${NAME_OF_LIB}_python/built/${NAME_OF_LIB}_python_go.py"
59+
sed -i'.bak' "s/import _${NAME_OF_LIB}_python_go/from ${NAME_OF_LIB}_python.built import _${NAME_OF_LIB}_python_go/g" "${NAME_OF_LIB}_python/built/go.py"
60+
echo ""
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [[ "${VIRTUAL_ENV}" == "" ]]; then
6+
echo "error: a virtualenv must be activated"
7+
exit 1
8+
fi
9+
10+
export TEST_COMMUNITY
11+
export TEST_DATABASE
12+
export TEST_HOSTNAME
13+
export TEST_PASSWORD
14+
export TEST_PORT
15+
export TEST_RETRIES
16+
export TEST_TIMEOUT
17+
export TEST_USERNAME
18+
19+
FOCUS="test/smoke_test.py"
20+
if [[ "${1}" != "" ]]; then
21+
FOCUS="${*}"
22+
fi
23+
24+
GODEBUG=cgocheck=0 python -m pytest --junit-xml "/srv/test_results/junit_results.xml" -vv -s "${FOCUS}"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/local/Cellar/[email protected]/3.9.1_6/Frameworks/Python.framework/Versions/3.9/bin/python3.9
2+
# -*- python -*-
3+
4+
# Keep this script in sync with python-config.sh.in
5+
6+
import getopt
7+
import os
8+
import sys
9+
import sysconfig
10+
11+
valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
12+
'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir',
13+
'embed']
14+
15+
def exit_with_usage(code=1):
16+
print("Usage: {0} [{1}]".format(
17+
sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr)
18+
sys.exit(code)
19+
20+
try:
21+
opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
22+
except getopt.error:
23+
exit_with_usage()
24+
25+
if not opts:
26+
exit_with_usage()
27+
28+
getvar = sysconfig.get_config_var
29+
pyver = getvar('VERSION')
30+
31+
opt_flags = [flag for (flag, val) in opts]
32+
33+
if '--help' in opt_flags:
34+
exit_with_usage(code=0)
35+
36+
for opt in opt_flags:
37+
if opt == '--prefix':
38+
print(getvar('prefix'))
39+
40+
elif opt == '--exec-prefix':
41+
print(getvar('exec_prefix'))
42+
43+
elif opt in ('--includes', '--cflags'):
44+
flags = ['-I' + sysconfig.get_path('include'),
45+
'-I' + sysconfig.get_path('platinclude')]
46+
if opt == '--cflags':
47+
flags.extend(getvar('CFLAGS').split())
48+
print(' '.join(flags))
49+
50+
elif opt in ('--libs', '--ldflags'):
51+
libs = []
52+
if '--embed' in opt_flags:
53+
libs.append('-lpython' + pyver + sys.abiflags)
54+
else:
55+
libpython = getvar('LIBPYTHON')
56+
if libpython:
57+
libs.append(libpython)
58+
libs.extend(getvar('LIBS').split() + getvar('SYSLIBS').split())
59+
60+
# add the prefix/lib/pythonX.Y/config dir, but only if there is no
61+
# shared library in prefix/lib/.
62+
if opt == '--ldflags':
63+
if not getvar('Py_ENABLE_SHARED'):
64+
libs.insert(0, '-L' + getvar('LIBPL'))
65+
print(' '.join(libs))
66+
67+
elif opt == '--extension-suffix':
68+
print(getvar('EXT_SUFFIX'))
69+
70+
elif opt == '--abiflags':
71+
print(sys.abiflags)
72+
73+
elif opt == '--configdir':
74+
print(getvar('LIBPL'))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
prefix=/System/Library/Frameworks/Python.framework/Versions/2.7
2+
exec_prefix=${prefix}
3+
libdir=${exec_prefix}/lib
4+
includedir=${prefix}/include
5+
6+
Name: Python
7+
Description: Python library
8+
Requires:
9+
Version: 2.7
10+
Libs.private: -ldl -framework CoreFoundation
11+
Libs: -L${libdir} -lpython2.7
12+
Cflags: -I${includedir}/python2.7

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.iml
22
.git
33
.idea
4+
go*_python/built
5+
go*_python/py2

fix_venv.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -x
4+
5+
.common/go-binding-utils/fix_venv.sh

native_build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -x
4+
5+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
pushd "${DIR}"
7+
8+
if [[ -f "/tmp/native_build.sh" ]]; then
9+
/tmp/native_build.sh gomssql "${1}"
10+
elif which native_build.sh; then
11+
native_build.sh gomssql "${1}"
12+
else
13+
.common/go-binding-utils/native_build.sh gomssql "${1}"
14+
fi

python2.pc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
prefix=/System/Library/Frameworks/Python.framework/Versions/2.7
2+
exec_prefix=${prefix}
3+
libdir=${exec_prefix}/lib
4+
includedir=${prefix}/include
5+
6+
Name: Python
7+
Description: Python library
8+
Requires:
9+
Version: 2.7
10+
Libs.private: -ldl -framework CoreFoundation
11+
Libs: -L${libdir} -lpython2.7
12+
Cflags: -I${includedir}/python2.7

requirements-dev.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-r requirements.txt
2+
3+
PyBindGen==0.21.0
4+
pytest==4.6.11

0 commit comments

Comments
 (0)