From 7c36700ad7d659ec65de927b51dffba68e91000a Mon Sep 17 00:00:00 2001 From: John Bartholomew Date: Sat, 22 Feb 2025 20:05:22 +0000 Subject: [PATCH] reformat setup.py --- setup.py | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/setup.py b/setup.py index 242c6ae..8c0afca 100644 --- a/setup.py +++ b/setup.py @@ -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'.") + 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], )