From 4e79dd7aae24b5d5aa88c060a17a3a05ad08a17c Mon Sep 17 00:00:00 2001 From: Kyle Ellrott Date: Thu, 22 Aug 2024 15:02:04 -0700 Subject: [PATCH] Adding setup.py for pygrip --- gripql/python/gripql/__init__.py | 2 +- pygrip/__init__.py | 5 +++-- setup.py | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 setup.py diff --git a/gripql/python/gripql/__init__.py b/gripql/python/gripql/__init__.py index 8cc78e54..bbacd739 100644 --- a/gripql/python/gripql/__init__.py +++ b/gripql/python/gripql/__init__.py @@ -36,4 +36,4 @@ count ] -__version__ = "0.7.1" +__version__ = "0.8.0" diff --git a/pygrip/__init__.py b/pygrip/__init__.py index a691c8ff..df19dd8c 100644 --- a/pygrip/__init__.py +++ b/pygrip/__init__.py @@ -2,7 +2,8 @@ from __future__ import print_function from ctypes import * -import os, inspect +from ctypes.util import find_library +import os, inspect, sysconfig import random, string import json from gripql.query import QueryBuilder @@ -10,7 +11,7 @@ cwd = os.getcwd() currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) os.chdir(currentdir) -_lib = cdll.LoadLibrary("./pygrip.so") +_lib = cdll.LoadLibrary("./_pygrip" + sysconfig.get_config_vars()["EXT_SUFFIX"]) os.chdir(cwd) _lib.ReaderNext.restype = c_char_p diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..4dba5c58 --- /dev/null +++ b/setup.py @@ -0,0 +1,33 @@ +"""Setup for checksig package""" +import sys +from distutils.errors import CompileError +from subprocess import call + +from setuptools import Extension, setup, find_packages +from setuptools.command.build_ext import build_ext + + +class build_go_ext(build_ext): + """Custom command to build extension from Go source files""" + def build_extension(self, ext): + ext_path = self.get_ext_fullpath(ext.name) + cmd = ['go', 'build', '-buildmode=c-shared', '-o', ext_path] + cmd += ext.sources + out = call(cmd) + if out != 0: + raise CompileError('Go build failed') + +setup( + name='pygrip', + version='0.8.0', + packages=find_packages(include=['pygrip']), + #py_modules=['pygrip'], + ext_modules=[ + Extension('pygrip/_pygrip', ['./pygrip/wrapper.go']) + ], + cmdclass={'build_ext': build_go_ext}, + install_requires=[ + "gripql>=0.8.0" + ], + zip_safe=False, +) \ No newline at end of file