From 3c7156aa6d96a72785c374c250bcbd626c6a3bd7 Mon Sep 17 00:00:00 2001 From: Leon Foks Date: Thu, 10 Oct 2024 21:24:29 -0700 Subject: [PATCH] Change install instructions --- python/README.md | 13 +++-------- python/gatdaem1d/__init__.py | 9 +++----- python/meson.build | 29 ++++++++++++++++++++++++ python/pyproject.toml | 26 +++++++++++++++++++++ python/setup.py | 44 ------------------------------------ 5 files changed, 61 insertions(+), 60 deletions(-) create mode 100644 python/meson.build create mode 100644 python/pyproject.toml delete mode 100644 python/setup.py diff --git a/python/README.md b/python/README.md index b424f50..bcd84ff 100644 --- a/python/README.md +++ b/python/README.md @@ -4,21 +4,14 @@ The Python (>=v3.5) interface consists of a C/C++ shared library (.so on Linux or .dll on Windows) called gatdaem1d which contains time-domain forward modelling and derivative functions which are called by the Python interpreter. ## Compiling and installing the C/C++ shared libraries -First the shared library needs to be built with CMake. See one of the CMake build scripts in the root directory of the ga-aem source code repository. If you are only interested in the Python interface, you need only build the ***`python_bindings`*** target. - -## Install directory contents -After being built successfully the install directory should contain, -- [ga-aem-install-dir]/python contains the package set up or installation function `setup.py`. -- [ga-aem-install-dir]/python/gatdaem1d contains the file `__init__.py` which is the package's Python classes and function code. It is also where the compiled shared library will reside after compilation. - - On Linux the shared library is [ga-aem-install-dir]/python/gatdaem1d/gatdaem1d.so. - - On Windows the shared library is [ga-aem-install-dir]/python/gatdaem1d/gatdaem1d.dll. -- [ga-aem-install-dir]/python/examples contains example Python usage code. +We are using Meson to automatically build the required C++ library. +Ensure that the GNU C++ compiler is available, and FFTW has been installed. ## PIP install of the Python package - To install as a python package you can then, ```bash cd [ga-aem-install-dir]/python - python -m pip install . + pip install . ``` - Note that **`python`** may need to be **`python3`** on your system. diff --git a/python/gatdaem1d/__init__.py b/python/gatdaem1d/__init__.py index 551e6ae..58ee85e 100644 --- a/python/gatdaem1d/__init__.py +++ b/python/gatdaem1d/__init__.py @@ -11,12 +11,9 @@ #Function to load the shared library def load_library(): - import platform; - if(platform.system() == "Windows"): - ext = '.dll' - else: - ext = '.so' - libname = os.path.join(os.path.dirname(os.path.realpath(__file__)),"gatdaem1d"+ext) + files = os.listdir(os.path.dirname(os.path.realpath(__file__))) + libname = [file for file in files if 'gatdaem1d_ext' in file][0] + libname = os.path.join(os.path.dirname(os.path.realpath(__file__)),libname) lib = ctypes.CDLL(libname) return lib; diff --git a/python/meson.build b/python/meson.build new file mode 100644 index 0000000..832037c --- /dev/null +++ b/python/meson.build @@ -0,0 +1,29 @@ +project('startingmeson', 'cpp', + version: '0.1' +) + +py = import('python').find_installation(pure: false) + +cpp = meson.get_compiler('cpp') + +incdir = include_directories(['../src', '../submodules/cpp-utils/include']) + +fftw = dependency('fftw3') + +module_path = 'gatdaem1d' + +shared_library('gatdaem1d_ext', + ['../src/gatdaem1d.cpp', '../src/gatdaem1d.h'], + include_directories: incdir, + dependencies: fftw, + install: true) + +python_sources = [ + 'gatdaem1d/__init__.py', + ] + +py.install_sources( + python_sources, + subdir: module_path +) + diff --git a/python/pyproject.toml b/python/pyproject.toml new file mode 100644 index 0000000..a9afc4a --- /dev/null +++ b/python/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["meson-python"] +build-backend = "mesonpy" + +[project] +name = "gatdaem1d" +version = "2.0.1" +description = "Time-domain airborne electromagnetic forward modelling" +readme = { file = "README.md", content-type = "text/markdown" } +requires-python = ">=3.10" +authors = [{ name = "Ross C Brodie", email = "ross.c.brodie@ga.gov.au" }] +keywords = ["electromagnetic", "geophysics"] +dependencies = ["numpy"] +classifiers = [ + 'License :: OSI Approved', + 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)', + 'Programming Language :: Python :: 3', + 'Topic :: Scientific/Engineering :: Physics', + 'Topic :: Electromagnetic :: Airborne :: Forward modelling :: Geophysics' +] + +[tool.spin] +package = 'gatdaem1d' + +[tool.setuptools.packages.find] +gatdaem1d = ["."] \ No newline at end of file diff --git a/python/setup.py b/python/setup.py deleted file mode 100644 index b721886..0000000 --- a/python/setup.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# Setup Script -# Author: Leon Foks -# March 10 2017 -# Updated: Ross C Brodie, March 20 2017 -# Updated: Ross C Brodie, March 21 2024 to Version 2.0 -# Updated: Leon Foks, June 5 2024. Added .dylib -import sys -import os -from os.path import join - -# Test Python's version -major, minor = sys.version_info[0:2] -if (major, minor) < (3, 5): - sys.stderr.write('\nPython 3.5 or later is needed to use this package\n') - sys.exit(1) - -try: - from setuptools import setup -except ImportError: - pass - -setup(name='gatdaem1d', - packages=['gatdaem1d'], - package_dir={'gatdaem1d':'gatdaem1d'}, - package_data={'gatdaem1d':['gatdaem1d.so', 'gatdaem1d.dll', 'gatdaem1d.dylib']}, - scripts=[], - version=2.0, - description='Time-domain airborne electromagnetic forward modelling.', - long_description='Time-domain airborne electromagnetic forward modelling. Python interface to C++ library for forward model and derivative calculations for airborne electromagnetic (AEM) systems used in geophysics.', - classifiers=[ - 'Development Status :: 4 - Beta', - 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)', - 'Programming Language :: Python :: 3.5', - 'Topic :: Scientific/Engineering :: Physics', - 'Topic :: Electromagnetic :: Airborne :: Forward modelling :: Geophysics', - ], - author='Ross C Brodie, Geoscience Australia and Leon Foks', - author_email='ross.c.brodie at ga.gov.au', - install_requires=[ - 'numpy>=1.11', - ], - url='https://github.com/GeoscienceAustralia/ga-aem', - license='GNU General Public License v2 (GPLv2)')