From 0465a51a46e62c4f97797676c884cd25c127f41b Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 7 Feb 2024 18:18:44 +0100 Subject: [PATCH] Initial project config and implement build process Enhanced the .gitignore to filter out additional build artifacts and Python cache files, promoting a cleaner repository state. Introduced a basic project structure with a new pyproject.toml, defining metadata and build requirements for the 'limedriver' Python package. Also added a LICENSE file and a custom setup.py which automates the retrieval and build of 'limedriver' submodules, streamlining the set-up for development and ensuring consistent builds across environments. These changes lay the groundwork for further development and distribution of the project. --- .gitignore | 10 ++++++++++ LICENSE | 0 pyproject.toml | 21 +++++++++++++++++++++ setup.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 LICENSE create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index aebcf3c..ca8bb68 100644 --- a/.gitignore +++ b/.gitignore @@ -52,5 +52,15 @@ Thumbs.db # Log files *.log +# Python cache data +__pycache__/ +*.pyc + +# Cython / Python build files +build/ +*.c +src/limedriver.egg-info + # Data data/ +venv/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml index e69de29..8fc3733 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[project] +name = "limedriver" +version = "0.1.0" +description = "Python bindings for limedriver" +authors = [{name = "Kumi", email = "limedriver@kumi.email"}] +license = {file = "LICENSE"} +readme = "README.md" +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Topic :: Software Development :: Build Tools", + "Programming Language :: Python :: 3", +] + +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "Cython>=0.29.21" +] \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..09cfe35 --- /dev/null +++ b/setup.py @@ -0,0 +1,49 @@ +from setuptools import setup, Extension +from setuptools.command.build_ext import build_ext + +import subprocess +import os + +from Cython.Build import cythonize + +class BuildExtCommand(build_ext): + """Custom build_ext command to ensure that the submodule is retrieved and built.""" + + def build_extensions(self): + os.environ['CXX'] = 'h5c++' + super().build_extensions() + + def run(self): + if not os.path.exists('extern/limedriver'): + self.clone_limedriver() + + self.build_limedriver() + + super().run() + + def clone_limedriver(self): + subprocess.check_call(['git', 'submodule', 'init']) + subprocess.check_call(['git', 'submodule', 'update']) + + def build_limedriver(self): + subprocess.check_call(['./configure'], cwd='extern/limedriver') + subprocess.check_call(['make'], cwd='extern/limedriver') + +ext_modules = [ + Extension( + 'limedriver', + sources=['src/limedriver/limedriver.pyx'], + include_dirs=["extern/limedriver/src/"], + libraries=["LimeSuite"], + ), +] + +setup( + name='limedriver', + + cmdclass={ + 'build_ext': BuildExtCommand, + }, + + ext_modules=cythonize(ext_modules), +)