reformat setup.py

This commit is contained in:
John Bartholomew 2025-02-22 20:05:22 +00:00
parent 3c92d79e96
commit 7c36700ad7

View File

@ -20,55 +20,66 @@ from setuptools.command.test import test as TestCommand
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", "-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'.")
jsonnet_ext = Extension(
'_gojsonnet',
sources=MODULE_SOURCES,
extra_objects=[
LIB_DIR + '/libgojsonnet.a',
],
include_dirs = ['cpp-jsonnet/include'],
language='c++',
print(
"_gojsonnet does not support running tests with 'python setup.py test'. Please run 'pytest'."
)
setup(name='gojsonnet',
url='https://jsonnet.org',
description='Python bindings for Jsonnet - The data templating language ',
author='David Cunningham',
author_email='dcunnin@google.com',
jsonnet_ext = Extension(
"_gojsonnet",
sources=MODULE_SOURCES,
extra_objects=[
LIB_DIR + "/libgojsonnet.a",
],
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",
version=get_version(),
cmdclass={
'build_ext': BuildJsonnetExt,
'test': NoopTestCommand,
"build_ext": BuildJsonnetExt,
"test": NoopTestCommand,
},
ext_modules=[jsonnet_ext],
)