Create python package and publish wheels.
parent
ab8ac8304d
commit
af0f31242f
@ -0,0 +1,58 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'python-release-*'
|
||||
|
||||
|
||||
jobs:
|
||||
build_wheels:
|
||||
name: Build wheels on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-20.04]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
if: runner.os == 'Linux'
|
||||
uses: docker/setup-qemu-action@v3
|
||||
with:
|
||||
platforms: all
|
||||
|
||||
- name: Build wheels
|
||||
uses: pypa/cibuildwheel@v2.16.2
|
||||
env:
|
||||
# CIBW_SKIP: cp36-* # Exclude
|
||||
CIBW_BUILD: cp*manylinux*
|
||||
# CIBW_BUILD_VERBOSITY: 1 # To debug issues
|
||||
CIBW_ARCHS_LINUX: auto aarch64
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
path: ./wheelhouse/*.whl
|
||||
|
||||
upload_pypi:
|
||||
needs: [build_wheels]
|
||||
runs-on: ubuntu-latest
|
||||
environment: pypi
|
||||
permissions:
|
||||
id-token: write
|
||||
# if: github.event_name == 'release' && github.event.action == 'published'
|
||||
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this)
|
||||
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
||||
steps:
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
# unpacks default artifact into dist/
|
||||
# if `name: artifact` is omitted, the action will create extra parent dir
|
||||
name: artifact
|
||||
path: dist
|
||||
|
||||
- uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
verify-metadata: false
|
@ -0,0 +1 @@
|
||||
from .iec61850 import *
|
@ -0,0 +1,91 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import sysconfig
|
||||
|
||||
from setuptools import Extension, find_packages, setup
|
||||
from setuptools.command.build_ext import build_ext
|
||||
from setuptools.command.build_py import build_py as _build_py
|
||||
|
||||
|
||||
class CMakeExtension(Extension):
|
||||
def __init__(self, name):
|
||||
Extension.__init__(self, name, sources=["."])
|
||||
self.sourcedir = os.path.abspath(".")
|
||||
|
||||
|
||||
class CMakeBuild(build_ext):
|
||||
def run(self):
|
||||
try:
|
||||
subprocess.check_output(["cmake", "--version"])
|
||||
except OSError:
|
||||
raise RuntimeError(
|
||||
"CMake must be installed to build the following extensions: "
|
||||
+ ", ".join(e.name for e in self.extensions)
|
||||
)
|
||||
|
||||
for ext in self.extensions:
|
||||
self.build_extension(ext)
|
||||
|
||||
def build_extension(self, ext):
|
||||
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
|
||||
cfg = "Debug" if self.debug else "Release"
|
||||
|
||||
cmake_args = [
|
||||
"-DPYTHON_EXECUTABLE=" + sys.executable,
|
||||
"-DPYTHON_INCLUDE_DIRS=" + sysconfig.get_paths()["include"],
|
||||
"-DBUILD_PYTHON_BINDINGS=ON",
|
||||
"-DCMAKE_BUILD_TYPE=" + cfg,
|
||||
]
|
||||
|
||||
build_args = ["--config", cfg]
|
||||
env = os.environ.copy()
|
||||
env["CXXFLAGS"] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get("CXXFLAGS", ""), self.distribution.get_version())
|
||||
if not os.path.exists(self.build_temp):
|
||||
os.makedirs(self.build_temp)
|
||||
if not os.path.exists(extdir):
|
||||
os.makedirs(extdir)
|
||||
|
||||
subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
|
||||
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=self.build_temp)
|
||||
|
||||
source_dir = os.path.join(self.build_temp, "pyiec61850")
|
||||
for file in os.listdir(source_dir):
|
||||
if file == "iec61850.py" or "_iec61850." in file:
|
||||
shutil.copy(os.path.join(source_dir, file), extdir)
|
||||
|
||||
|
||||
class build_py(_build_py):
|
||||
# See github.com/yanqd0/swig-python-demo
|
||||
# Run first build_ext, as Swig will generate new python files that will have to be detected and included
|
||||
def run(self):
|
||||
self.run_command("build_ext")
|
||||
return super().run()
|
||||
|
||||
|
||||
long_description = """
|
||||
============
|
||||
pyiec61850
|
||||
============
|
||||
|
||||
Compiled, packaged python bindings of https://github.com/mz-automation/libiec61850.
|
||||
|
||||
Wheels are built with the CI of the fork https://github.com/nrontsis/libiec61850.
|
||||
|
||||
License same as mz-automation/libiec61850.
|
||||
|
||||
Use at your own risk.
|
||||
"""
|
||||
|
||||
setup(
|
||||
name="pyiec61850",
|
||||
version="1.5.2a1",
|
||||
packages=find_packages(),
|
||||
description="Python bindings of https://github.com/mz-automation/libiec61850.",
|
||||
long_description=long_description,
|
||||
ext_modules=[CMakeExtension("pyiec61850/_iec61850")],
|
||||
cmdclass={"build_py": build_py, "build_ext": CMakeBuild},
|
||||
zip_safe=False,
|
||||
install_requires=[],
|
||||
)
|
Loading…
Reference in New Issue