Skip to content

Commit

Permalink
Made build system for creating wheels and published to pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
vegardjervell committed May 12, 2023
1 parent 8ae6acf commit a06f4c0
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 24 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ cpp/Integration/debug/
cpp/include/
python/venv
venv/
venv*/
pypi_release/wheelhouse/*.whl
*__pycache__/
dist/

build/
pykingas.egg-info/
venv*
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!---
Generated at: 2023-05-12T10:31:37.030609
Generated at: 2023-05-12T14:03:05.673758
This is an auto-generated file, generated using the script at KineticGas/docs/join_docs.py
The file is created by joining the contents of the files
KineticGas/docs/markdown/
Expand Down Expand Up @@ -68,7 +68,9 @@ A standalone C++ module, that works without the python wrapper is currently unde

# Installing KineticGas

An up-to-date release of the KineticGas package is coming to PyPi as [pykingas](https://pypi.org/project/pykingas/#files), at the moment KineticGas must be built from source.
KineticGas is available on PyPi as the [`pykingas`](https://pypi.org/project/pykingas/) package, compiled for MacOS running on Apple Silicon, for python versions 3.8-3.11.

For other operating systems, KineticGas must currently be built from source.

## Building from source

Expand Down Expand Up @@ -96,6 +98,10 @@ The `bash` script `cpp/build_kingas.sh` uses `cmake` and `make` to compile the b
* Set `PYBIND11_ROOT` in `cpp/CMakeLists.txt` to the resulting directory.
* The system arcitecture to compile for, and the python version, are specified in `cpp/CMakeLists.txt`, modify these as needed.
* The bash script `cpp/build.sh` sets the environment variables `CC` and `CXX`, these may also need to be modified for your system.
* The python installation to build against can be specified with
* `bash cpp/build.sh -DPYTHON_EXECUTABLE=<path/to/python>`
* Where `<path/to/python>` can (usually) be replaced by `$(which python)`.
* If none of the above works, please feel free to leave an issue.



Expand Down
10 changes: 6 additions & 4 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
cmake_minimum_required(VERSION 3.4)
set(PYBIND11_PYTHON_VERSION "3.10")
cmake_minimum_required(VERSION 3.12)
# set(PYBIND11_PYTHON_VERSION "3.10")
string(ASCII 27 Esc)
message("${Esc}[34mPYBIND11_PYTHON_VERSION is : ${PYBIND11_PYTHON_VERSION}")
message("${Esc}[34mPYTHON_EXECUTABLE is : ${PYTHON_EXECUTABLE}")

set(PYBIND11_ROOT "/usr/local/include/pybind11") # This path must contain the pybind11 root dir.
set(CMAKE_CXX_COMPILER /usr/bin/g++)
set(CMAKE_C_COMPILER /usr/bin/gcc)

execute_process(COMMAND arch OUTPUT_VARIABLE TARGET_ARCHITECTURE)
message("Architecture is ${TARGET_ARCHITECTURE}")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -std=c++17 -pthread -arch arm64")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -DDEBUG -Wno-unused-parameter -Wno-unused-const-variable")
Expand Down
8 changes: 3 additions & 5 deletions cpp/build.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#!/usr/bin/env bash
# Script to build the KineticGas module and run tests. Can be used with options
# --fullclean : Wipe the release directory before rebuilding
# --cleancache : Delete the cache in the release directory before rebuilding
# --Debug : Build a debug version
# NOTE: The binary in `pykingas/` will not be overwritten unless tests succeed.
set -e

py_version=${1-"-DPYBIND11_PYTHON_VERSION=3"}

export CC=/usr/bin/gcc
export CXX=/usr/bin/g++

echo "Building KineticGas Release"

[ ! -d "cpp/release" ] && mkdir cpp/release
cd cpp/release
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake -DCMAKE_BUILD_TYPE=Release "${py_version}" ..
make
cd ../..
echo "Copying binary to ${PWD}/pykingas/KineticGas_r.so"
Expand Down
8 changes: 7 additions & 1 deletion docs/markdown/source_build.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Installing KineticGas

An up-to-date release of the KineticGas package is coming to PyPi as [pykingas](https://pypi.org/project/pykingas/#files), at the moment KineticGas must be built from source.
KineticGas is available on PyPi as the [`pykingas`](https://pypi.org/project/pykingas/) package, compiled for MacOS running on Apple Silicon, for python versions 3.8-3.11.

For other operating systems, KineticGas must currently be built from source.

## Building from source

Expand Down Expand Up @@ -28,5 +30,9 @@ The `bash` script `cpp/build_kingas.sh` uses `cmake` and `make` to compile the b
* Set `PYBIND11_ROOT` in `cpp/CMakeLists.txt` to the resulting directory.
* The system arcitecture to compile for, and the python version, are specified in `cpp/CMakeLists.txt`, modify these as needed.
* The bash script `cpp/build.sh` sets the environment variables `CC` and `CXX`, these may also need to be modified for your system.
* The python installation to build against can be specified with
* `bash cpp/build.sh -DPYTHON_EXECUTABLE=<path/to/python>`
* Where `<path/to/python>` can (usually) be replaced by `$(which python)`.
* If none of the above works, please feel free to leave an issue.


2 changes: 1 addition & 1 deletion pykingas/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!---
Generated at: 2023-05-12T10:31:37.030109
Generated at: 2023-05-12T14:03:05.671879
This is an auto-generated file, generated using the script at KineticGas/docs/join_docs.py
The file is created by joining the contents of the files
KineticGas/docs/markdown/
Expand Down
42 changes: 42 additions & 0 deletions pypi_release/build_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# Script to build wheels for pypi
# Note: Uses $(which pythonX.Y) to get the path to various python interpreters
set -e

pykingas_version="2.0.0"
os_tag="macosx_11_0_arm64"
py_versions=("3.8" "3.9" "3.10" "3.11") # Need to build different wheels for every python version, because pybind11.
wheelhouse_dir="pypi_release/wheelhouse"
for py_version in "${py_versions[@]}"; do

echo "Building wheel for python version : ${py_version}"

[ -f "pykingas/KineticGas_r.so" ] && rm pykingas/KineticGas_r.so
[ -d "cpp/release" ] && rm -rf cpp/release

bash cpp/build.sh -DPYTHON_EXECUTABLE="$(which "python${py_version}")"

python -m pip wheel --wheel-dir=${wheelhouse_dir} .
mv pypi_release/wheelhouse/pykingas-${pykingas_version}-py3-none-any.whl pypi_release/dist/pykingas-${pykingas_version}-cp"${py_version//.}"-none-${os_tag}.whl

done

# echo "Finished Building : Uploading test to testpypi"
# twine upload -r testpypi pypi_release/dist/*

exit 0

# Code to upload to PyPi :
twine upload pypi_release/dist/*

exit 0

#Code to Delocate wheels
# It appears that there is nothing to delocate here (at least according to delocate-listdeps)

cd pypi_release/wheelhouse
delocate-wheel -w fixed_wheels -v pykingas-${pykingas_version}-py3-none-any.whl
cd fixed_wheels
mv pykingas-${pykingas_version}-py3-none-any.whl pykingas-${pykingas_version}-cp${py_version//.}-none-macosx_11_0_arm64.whl
cd ..
rm pykingas-${pykingas_version}-py3-none-any.whl # Preventing unintentionally overwriting the fixed wheel
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions pypi_release/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pykingas.MieKinGas import MieKinGas

print('\033[96mImported MieKinGas\033[0m')

mie = MieKinGas('H2,C1')
mie.viscosity(300, 0.02, [0.5, 0.5], N=1)

print('\033[92mComputed Something!\033[0m')
16 changes: 16 additions & 0 deletions pypi_release/test_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

pykingas_version="2.0.5"
py_versions=("3.8" "3.9" "3.10" "3.11")

for py_version in "${py_versions[@]}"; do

source venv"${py_version//.}"/bin/activate

echo "Testing install for Python version $(python --version)"
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple pykingas==${pykingas_version}
python pypi_release/test_import.py

done
18 changes: 8 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import imp
from setuptools import setup
from pathlib import Path
from glob import glob

this_dir = Path(__file__).parent
readme = (this_dir / 'pykingas/README.md').read_text()
setup(
name='pykingas',
version='1.2.4',
version='2.0.0',
packages=['pykingas'],
package_data={'pykingas': ['KineticGas*', 'fluids/*']},
description='Revised Chapman-Enskog solutions of the Boltzmann Equations '
'for diffusion, thermal diffusion and thermal conductivity. '
'Implemented for Hard spheres and Mie-fluids.',
description='Revised Enskog theory for Mie fluids, and other spherical potentials. Allows prediction of transport '
'coefficients such as diffusion coefficients, viscosities, thermal diffusion coefficients'
' and thermal conductivities. In dense, multicomponent gas mixtures and supercritical mixtures.',
long_description=readme,
long_description_content_type='text/markdown',
author='Vegard Gjeldvik Jervell',
author_email='[email protected]',
url='https://github.com/vegardjervell/Kineticgas',
install_requires=['numpy>=1.22.1',
'scipy>=1.7.3',
'thermopack>=2.1.0']
url='https://github.com/thermotools/KineticGas',
install_requires=["numpy~=1.22",
"scipy~=1.7",
"thermopack~=2.1"]
)

0 comments on commit a06f4c0

Please sign in to comment.