Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/install-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/bash

# Helper script to install Go dev tools.
# This is run _inside_ the manylinux container(s)
# used in cibuildwheel to build the wheels.

set -euo pipefail

TDIR="$(mktemp -d)"
>&2 echo "Working dir: ${TDIR}"
trap "rm -rf ${TDIR}" EXIT

>&2 echo "Downloading Go 1.23.6 distribution file."
curl -fL -o "${TDIR}/go1.23.6.linux-amd64.tar.gz" 'https://go.dev/dl/go1.23.6.linux-amd64.tar.gz'

>&2 echo "Checking distribution file integrity"
GO_DIST_SHA256='9379441ea310de000f33a4dc767bd966e72ab2826270e038e78b2c53c2e7802d'
printf '%s %s/go1.23.6.linux-amd64.tar.gz\n' "${GO_DIST_SHA256}" "${TDIR}" | sha256sum -c

>&2 echo "Unpacking to /usr/local/go"
rm -rf /usr/local/go && tar -C /usr/local -xzf "${TDIR}/go1.23.6.linux-amd64.tar.gz"

>&2 echo "Installed Go version:"
/usr/local/go/bin/go version
17 changes: 13 additions & 4 deletions .github/workflows/publish-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-python@v5
with:
Expand All @@ -50,22 +52,29 @@ jobs:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
#os: [ubuntu-22.04, windows-latest, macos-latest]
os: [ubuntu-22.04, windows-latest]
os: [ubuntu-22.04]

permissions:
contents: read

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Build wheels
uses: pypa/cibuildwheel@ee63bf16da6cddfb925f542f2c7b59ad50e93969 # v2.22.0
env:
# Skip PyPy, 32-bit Windows, 32-bit Linux, and CPython before 3.9.
# Skip PyPy, 32-bit Windows, 32-bit Linux, musllinux and CPython before 3.9.
# See https://cibuildwheel.readthedocs.io/en/stable/options/#examples_1
CIBW_SKIP: "*-win32 pp* *-manylinux_i686 *-musllinux_i686 cp36-* cp37-* cp38-*"
CIBW_SKIP: "*-win32 pp* *-manylinux_i686 *-musllinux* cp36-* cp37-* cp38-*"
CIBW_BEFORE_ALL_LINUX: >
bash {package}/.github/workflows/install-go.sh &&
export PATH="$PATH":/usr/local/go/bin &&
command -v go > /dev/null
CIBW_ENVIRONMENT: PATH=$PATH:/usr/local/go/bin
CIBW_TEST_COMMAND: >
python {package}/python/_jsonnet_test.py

Expand Down
2 changes: 1 addition & 1 deletion c-bindings-tests/compat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def test_jsonnet_evaluate_file_multi(self):

def test_jsonnet_version(self):
res = lib.jsonnet_version()
match = re.match(r'^v[0-9]+[.][0-9]+[.][0-9]+ [(]go-jsonnet[)]$', to_bytes(res).decode('utf-8'))
match = re.match(r'^v[0-9]+[.][0-9]+[.][0-9]+(-?([a-z]+[0-9]*))? [(]go-jsonnet[)]$', to_bytes(res).decode('utf-8'))
self.assertIsNotNone(match)

def test_jsonnet_native_callback_square(self):
Expand Down
51 changes: 31 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,66 @@
from subprocess import Popen, PIPE

DIR = os.path.abspath(os.path.dirname(__file__))
LIB_DIR = DIR + '/c-bindings'
MODULE_SOURCES = ['python/_jsonnet.c']
LIB_DIR = DIR + "/c-bindings"
MODULE_SOURCES = ["python/_jsonnet.c"]


def get_version():
"""
Parses the version out of vm.go
"""
with open(os.path.join(DIR, 'vm.go')) as f:
with open(os.path.join(DIR, "vm.go")) as f:
for line in f:
if 'const' in line and 'version' in line:
v_code = line.partition('=')[2].strip('\n "')
if v_code[0] == 'v':
if "const" in line and "version" in line:
v_code = line.partition("=")[2].strip('\n "')
if v_code[0] == "v":
return v_code[1:]

return None


class BuildJsonnetExt(BuildExt):
def run(self):
p = Popen(['go', 'build', '-o', 'libgojsonnet.a', '-buildmode=c-archive'], cwd=LIB_DIR, stdout=PIPE)
p = Popen(
["go", "build", "-x", "-o", "libgojsonnet.a", "-buildmode=c-archive"],
cwd=LIB_DIR,
stdout=PIPE,
)
p.wait()

if p.returncode != 0:
raise Exception('Could not build libgojsonnet.a')
raise Exception("Could not build libgojsonnet.a")

BuildExt.run(self)


class NoopTestCommand(TestCommand):
def __init__(self, dist):
print("_gojsonnet does not support running tests with 'python setup.py test'. Please run 'pytest'.")
print(
"_gojsonnet does not support running tests with 'python setup.py test'. Please run 'pytest'."
)


jsonnet_ext = Extension(
'_gojsonnet',
"_gojsonnet",
sources=MODULE_SOURCES,
extra_objects=[
LIB_DIR + '/libgojsonnet.a',
LIB_DIR + "/libgojsonnet.a",
],
include_dirs = ['cpp-jsonnet/include'],
language='c++',
include_dirs=["cpp-jsonnet/include"],
language="c++",
)

setup(name='gojsonnet',
url='https://jsonnet.org',
description='Python bindings for Jsonnet - The data templating language ',
author='David Cunningham',
author_email='dcunnin@google.com',
setup(
name="gojsonnet",
url="https://jsonnet.org",
description="Python bindings for Jsonnet - The data templating language ",
author="David Cunningham",
author_email="dcunnin@google.com",
version=get_version(),
cmdclass={
'build_ext': BuildJsonnetExt,
'test': NoopTestCommand,
"build_ext": BuildJsonnetExt,
"test": NoopTestCommand,
},
ext_modules=[jsonnet_ext],
)