Unverified Commit e453159f authored by Simon Ward's avatar Simon Ward
Browse files

Make platform independent [ci skip]

parent 757e93f9
# Adapted from https://github.com/RalfG/python-wheels-manylinux-build/blob/master/full_workflow_example.yml name: Python libs
name: Build CFML wheels on various systems
on: on:
push: push:
branches: [ simon ] branches: [ master ]
pull_request:
branches: [ master ]
# schedule:
# # Every day at 1am
# - cron: '0 1 * * *'
jobs: jobs:
# create-Linux:
# runs-on: ubuntu-latest get_Latest:
# runs-on: ubuntu-latest
# steps: if: "!contains(github.event.head_commit.message, '[ci skip]')"
# - uses: actions/checkout@v2
# steps:
# - name: Build manylinux wheels - name: Checkout ILL repo
# run: docker run -e PLAT=manylinux2010_x86_64 -v `pwd`:/io quay.io/pypa/manylinux2010_x86_64 /io/Scripts/buildscript.sh run: |
# git clone https://code.ill.fr/scientific-software/crysfml/ ./
# - uses: actions/upload-artifact@v2 git checkout feature-python_api-build_wheels
# with: rm -rf ./.git ./Html
# name: CrysFML - Linux - uses: actions/upload-artifact@v2
# path: ${{ github.workspace }}/dist/*.whl with:
# name: CrysFML_SRC
# create-OSX: path: ${{ github.workspace }}
# strategy: retention-days: 1
# max-parallel: 4
# matrix:
# python-version: ['3.6', '3.7', '3.8', '3.9'] create-Linux:
# os: [macos-10.15] runs-on: ubuntu-latest
# gcc_v: [ 10 ] # Version of GFortran we want to use.
## exclude: # Currently only python > 3.8 is supported on macos-11.0 and > 3.6 on macos-10.15 needs: get_Latest
## - os: macos-11.0
## python-version: '3.7' steps:
## - os: macos-11.0 - uses: actions/download-artifact@v2
## python-version: '3.8' with:
# name: CrysFML_SRC
# runs-on: ${{ matrix.os }}
# - name: Build manylinux wheels
# steps: run: |
# - uses: actions/checkout@v2 chmod +x ./Scripts/buildscript.sh
# docker run -e PLAT=manylinux2010_x86_64 -v ${{ github.workspace }}:/io quay.io/pypa/manylinux2010_x86_64 /io/Scripts/buildscript.sh
# - name: Setup python - uses: actions/upload-artifact@v2
# uses: actions/setup-python@v1 with:
# with: name: CrysFML - Linux
# python-version: ${{matrix.python-version}} path: ${{ github.workspace }}/dist/*.whl
#
# - name: Install cmake create-OSX:
# run: pip3 install cmake delocate wheel strategy:
# max-parallel: 4
# - name: Build CFML (OSX) matrix:
# env: python-version: ['3.8']
# FC: gfortran-${{ matrix.gcc_v }} os: [macos-10.15]
# CC: gcc-${{ matrix.gcc_v }} gcc_v: [ 10 ] # Version of GFortran we want to use.
# run: |
# pip3 wheel ./ --no-deps -w ./old/ runs-on: ${{ matrix.os }}
# delocate-wheel -w dist -v ./old/*.whl
# needs: get_Latest
# - uses: actions/upload-artifact@v2
# with: steps:
# name: CrysFML - ${{ matrix.os }} - Python ${{ matrix.python-version }} - uses: actions/download-artifact@v2
# path: ./dist/*.whl with:
name: CrysFML_SRC
- name: Setup python
uses: actions/setup-python@v1
with:
python-version: ${{matrix.python-version}}
- name: Install cmake
run: pip3 install cmake delocate wheel
- name: Build CFML (OSX)
env:
FC: gfortran-${{ matrix.gcc_v }}
CC: gcc-${{ matrix.gcc_v }}
run: |
pip3 wheel ./ --no-deps -w ./old/
delocate-wheel -w dist -v ./old/*.whl
- uses: actions/upload-artifact@v2
with:
name: CrysFML - MacOS
path: ./dist/*.whl
create-Windows: create-Windows:
strategy: strategy:
...@@ -92,25 +117,25 @@ jobs: ...@@ -92,25 +117,25 @@ jobs:
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v2
with: with:
name: CrysFML - ${{ matrix.os }} - Python ${{ matrix.python-version }} name: CrysFML - Windows
path: ./dist/*.whl path: ./dist/*.whl
# Upload_Artifacts: Upload_Artifacts:
# runs-on: ubuntu-latest runs-on: ubuntu-latest
# needs: [create-Linux, create-OSX, create-Windows] needs: [create-Linux, create-OSX]
# steps: steps:
# - uses: actions/checkout@v2 - uses: actions/download-artifact@v2
# - uses: actions/download-artifact@v2 - name: What is downloaded
# - name: Upload Artifacts GitHub releases run: |
## if: github.event_name == 'push' ls -al
# uses: ncipollo/release-action@v1 - name: Upload Artifacts GitHub releases
# with: uses: ncipollo/release-action@v1
# draft: falase with:
# prerelease: true draft: false
# allowUpdates: true prerelease: true
# replacesArtifacts: true allowUpdates: true
# token: ${{ secrets.GITHUB_TOKEN }} replacesArtifacts: true
# artifacts: "./dist/*.whl" token: ${{ secrets.GITHUB_TOKEN }}
## tag: ${{ env.BRANCH_NAME }} artifacts: "./**/*.whl"
## commit: ${{ env.BRANCH_NAME }} tag: "CurrentBuild"
# bodyFile: "RELEASE.md" body: "This is a build of the CFML libraries."
...@@ -17,11 +17,11 @@ function repair_wheel { ...@@ -17,11 +17,11 @@ function repair_wheel {
# Compile wheels # Compile wheels
for PYBIN in /opt/python/*/bin; do #for PYBIN in /opt/python/*/bin; do
# "${PYBIN}/pip" install -r /io/dev-requirements.txt export PYBIN=/opt/python/cp38-cp38/bin
"${PYBIN}/pip" wheel /io/ --no-deps --use-feature=in-tree-build -w /io/dist/ "${PYBIN}/pip" wheel /io/ --no-deps --use-feature=in-tree-build -w /io/dist/
rm -rf /io/build/ rm -rf /io/build/
done #done
# Bundle external shared libraries into the wheels # Bundle external shared libraries into the wheels
for whl in /io/dist/*.whl; do for whl in /io/dist/*.whl; do
...@@ -29,7 +29,6 @@ for whl in /io/dist/*.whl; do ...@@ -29,7 +29,6 @@ for whl in /io/dist/*.whl; do
done done
# Install packages and test # Install packages and test
for PYBIN in /opt/python/*/bin/; do #for PYBIN in /opt/python/*/bin/; do
"${PYBIN}/pip" install CFML --no-index -f /io/dist "${PYBIN}/pip" install CFML --no-index -f /io/dist
# (cd "$HOME"; "${PYBIN}/nosetests" pymanylinuxdemo) #done
done \ No newline at end of file
\ No newline at end of file
import os import os
import pathlib import pathlib
import pkgutil import pkgutil
...@@ -7,6 +8,7 @@ import sys ...@@ -7,6 +8,7 @@ import sys
import setuptools import setuptools
import distutils.sysconfig as sysconfig import distutils.sysconfig as sysconfig
from distutils.core import setup from distutils.core import setup
import distutils.command.build
from distutils.command.install_data import install_data from distutils.command.install_data import install_data
from subprocess import CalledProcessError, check_output, check_call from subprocess import CalledProcessError, check_output, check_call
...@@ -15,6 +17,23 @@ from setuptools.command.build_ext import build_ext ...@@ -15,6 +17,23 @@ from setuptools.command.build_ext import build_ext
from setuptools.command.install_lib import install_lib from setuptools.command.install_lib import install_lib
from setuptools.command.install_scripts import install_scripts from setuptools.command.install_scripts import install_scripts
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
# this overrides standard naming of the wheel to not include
# architecture or python dot version number
class Bdist_wheel(_bdist_wheel):
def finalize_options(self):
_bdist_wheel.finalize_options(self)
self.root_is_pure = False
def get_tag(self):
python, abi, plat = _bdist_wheel.get_tag(self)
python, abi = 'py3', 'none'
return python, abi, plat
except ImportError:
Bdist_wheel = None
BITS = struct.calcsize("P") * 8 BITS = struct.calcsize("P") * 8
PACKAGE_NAME = "crysfml_api" PACKAGE_NAME = "crysfml_api"
SOURCE_DIR = '.' SOURCE_DIR = '.'
...@@ -42,7 +61,6 @@ def get_cmake(): ...@@ -42,7 +61,6 @@ def get_cmake():
class CMakeExtension(Extension): class CMakeExtension(Extension):
""" """
An extension to run the cmake build An extension to run the cmake build
This simply overrides the base extension class so that setuptools This simply overrides the base extension class so that setuptools
doesn't try to build your sources for you doesn't try to build your sources for you
""" """
...@@ -54,7 +72,6 @@ class CMakeExtension(Extension): ...@@ -54,7 +72,6 @@ class CMakeExtension(Extension):
class InstallCMakeLibsData(install_data): class InstallCMakeLibsData(install_data):
""" """
Just a wrapper to get the install data into the egg-info Just a wrapper to get the install data into the egg-info
Listing the installed files in the egg-info guarantees that Listing the installed files in the egg-info guarantees that
all of the package files will be uninstalled when the user all of the package files will be uninstalled when the user
uninstalls your package through pip uninstalls your package through pip
...@@ -72,10 +89,10 @@ class InstallCMakeLibsData(install_data): ...@@ -72,10 +89,10 @@ class InstallCMakeLibsData(install_data):
self.outfiles = self.distribution.data_files self.outfiles = self.distribution.data_files
class InstallCMakeLibs(install_lib): class InstallCMakeLibs(install_lib):
""" """
Get the libraries from the parent distribution, use those as the outfiles Get the libraries from the parent distribution, use those as the outfiles
Skip building anything; everything is already built, forward libraries to Skip building anything; everything is already built, forward libraries to
the installation step the installation step
""" """
...@@ -141,6 +158,8 @@ class InstallCMakeLibs(install_lib): ...@@ -141,6 +158,8 @@ class InstallCMakeLibs(install_lib):
super().run() super().run()
pass
class InstallCMakeScripts(install_scripts): class InstallCMakeScripts(install_scripts):
""" """
...@@ -192,7 +211,8 @@ class BuildCMakeExt(build_ext): ...@@ -192,7 +211,8 @@ class BuildCMakeExt(build_ext):
for extension in self.extensions: for extension in self.extensions:
self.build_cmake(extension) self.build_cmake(extension)
super().run() # super().run()
pass
def build_cmake(self, extension: Extension): def build_cmake(self, extension: Extension):
""" """
...@@ -203,10 +223,17 @@ class BuildCMakeExt(build_ext): ...@@ -203,10 +223,17 @@ class BuildCMakeExt(build_ext):
build_dir = pathlib.Path(self.build_temp) build_dir = pathlib.Path(self.build_temp)
extension_path = pathlib.Path(self.get_ext_fullpath(extension.name)) # don't store the abi3 info in filename
extension._file_name = extension._full_name
ext_path = pathlib.Path(self.get_ext_fullpath(extension.name))
ext_ext = os.path.splitext(ext_path)[1]
filename = extension._file_name + ext_ext
extension_path = os.path.join(ext_path.parent, filename)
os.makedirs(build_dir, exist_ok=True) os.makedirs(build_dir, exist_ok=True)
os.makedirs(extension_path.parent.absolute(), exist_ok=True) os.makedirs(ext_path.parent.absolute(), exist_ok=True)
# Now that the necessary directories are created, build # Now that the necessary directories are created, build
...@@ -264,6 +291,16 @@ class BuildCMakeExt(build_ext): ...@@ -264,6 +291,16 @@ class BuildCMakeExt(build_ext):
# different place. See comments above for additional information # different place. See comments above for additional information
class BuildCommand(distutils.command.build.build):
def initialize_options(self):
# this overrides the directory names for
# build/lib and build/temp
distutils.command.build.build.initialize_options(self)
self.build_platlib = 'build/lib'
self.build_temp = 'build/temp'
setup(name="CFML", setup(name="CFML",
version="0.0.1", version="0.0.1",
author="Simon Ward", author="Simon Ward",
...@@ -281,11 +318,14 @@ setup(name="CFML", ...@@ -281,11 +318,14 @@ setup(name="CFML",
"Programming Language :: Fortran", "Programming Language :: Fortran",
"Programming Language :: Python"], "Programming Language :: Python"],
license='LGPL', license='LGPL',
cpython_tags=None,
cmdclass={ cmdclass={
'build': BuildCommand,
'build_ext': BuildCMakeExt, 'build_ext': BuildCMakeExt,
'install_data': InstallCMakeLibsData, 'install_data': InstallCMakeLibsData,
'install_lib': InstallCMakeLibs, 'install_lib': InstallCMakeLibs,
'install_scripts': InstallCMakeScripts 'install_scripts': InstallCMakeScripts,
'bdist_wheel': Bdist_wheel
}, },
setup_requires=['wheel'] setup_requires=['wheel']
) )
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment