Skip to content

Commit

Permalink
Python packaging2 (#154)
Browse files Browse the repository at this point in the history
* start some refactoring

* Refactoring

* refactoring

* add netlist.py and associated tests

* fix install

* packaging in progress

* WIP

* remove job for the moment

* remove loadSNL from python

* switch to static naja core

* switch to fPIC

* more static libs

* build settings

* build settings

* starting wheels

* remove windows for the time being

* packaging

* update

* update

* WIP

* WIP

* version

* another attempt

* settings

* cleaning

* setup

* setup

* setup

* install boost

* boost

* still looking for boost

* boost again

* boost again

* boost again

* boost on macos

* only linux for the moment

* set variables

* print BOOST_ROOT

* print env var

* force boost root

* new attempt

* WIP

* clean

* clean

* Update wheels.yml

* add python

* other version

* another attempt

* clean again

* python version

* attempt again

* link with Python

* install flex/bison

* remove serialization

* remove capnp unit tests for python package

* install bison

* clean commands

* install wget

* remove pyloader testing in python package

* remove spdlog

* install flex

* don't build snippets

* remove spdlog

* clean spdlog

* clean spdlog

* remove a test

* split verilog tests

* change config

* linux compile

* package location

* update setup

* switch to verilog main

* new attempt

* upload

* test upload

* test package

* typo

* cleaning

* bump version

* same version

* initiate README

* rename to najaeda

* try to upload

* set urls

* fix URL

* missing '/'

* fix

* add verbose

* fix

* more support

* test

* start macos support

* macos setting

* macos again

* attempt

* test

* new test

* more version

* Update wheels.yml

* Update wheels.yml
  • Loading branch information
xtofalex authored Nov 27, 2024
1 parent c6b0190 commit 35595f7
Show file tree
Hide file tree
Showing 26 changed files with 343 additions and 122 deletions.
151 changes: 151 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Workflow to build and test wheels
name: najaeda Wheel builder

on:
push:
branches:
- main
# Release branches
#- "[0-9]+.[0-9]+.X"
pull_request:
branches:
- main
#- "[0-9]+.[0-9]+.X"
# Manual run
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
build_wheels:
name: Build wheel for cp${{ matrix.python }}-${{ matrix.platform_id }}-${{ matrix.manylinux_image }}
runs-on: ${{ matrix.os }}

strategy:
# Ensure that a wheel builder finishes even if another fails
fail-fast: false
matrix:
include:
# Linux 64 bit manylinux2014
- os: ubuntu-latest
python: 39
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 310
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 311
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 312
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 313
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 313t
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
free_threaded_support: True

# MacOS arm64
- os: macos-14
python: 39
platform_id: macosx_arm64
- os: macos-14
python: 310
platform_id: macosx_arm64
- os: macos-14
python: 311
platform_id: macosx_arm64
- os: macos-14
python: 312
platform_id: macosx_arm64
- os: macos-14
python: 313
platform_id: macosx_arm64
- os: macos-14
python: 313t
platform_id: macosx_arm64
free_threaded_support: True

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Configure macOS Environment
if: runner.os == 'macOS'
run: |
export HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 HOMEBREW_NO_ENV_HINTS=1
eval "$(brew shellenv)"
brew install -q boost flex bison
echo "/usr/local/opt/flex/bin" >> $GITHUB_PATH; echo "/usr/local/opt/bison/bin" >> $GITHUB_PATH;
echo "/opt/homebrew/opt/flex/bin" >> $GITHUB_PATH; echo "/opt/homebrew/opt/bison/bin" >> $GITHUB_PATH
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.22.0

- name: Build wheels
env:
CIBW_FREE_THREADED_SUPPORT: ${{ matrix.free_threaded_support }}
CIBW_ENVIRONMENT: SKLEARN_SKIP_NETWORK_TESTS=1
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_ARCHS: all
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }}
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_image }}
run: python -m cibuildwheel --output-dir wheelhouse

#Reminder!!: actions/upload-artifact and actions/download-artifact
#need to have same version
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-cp${{ matrix.python }}-${{ matrix.platform_id }}
path: ./wheelhouse/*.whl

test_upload_pypi:
# TODO: create an sdist that can build without a custom environment
needs: [build_wheels]
runs-on: ubuntu-latest
#environment: pypi
permissions:
id-token: write
steps:
#Reminder!!: actions/upload-artifact and actions/download-artifact
#need to have same version
- uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/[email protected]
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
skip-existing: true

pypi-publish:
needs: [test_upload_pypi]
name: Upload release to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Files: .github/workflows/* .gitmodules
Copyright: 2022 The Naja Authors.
License: Apache-2.0

Files: README.md README_pages/* AUTHORS docs/*
Files: README.md README.rst README_pages/* AUTHORS docs/*
Copyright: 2022 The Naja Authors.
License: Apache-2.0

Expand Down
117 changes: 71 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,34 @@ endif()

include(GNUInstallDirs)

option(BUILD_NAJA_PYTHON "Build Naja Python package" OFF)

#RPATH settings
#set(MACOSX_RPATH TRUE)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if(BUILD_NAJA_PYTHON)
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()
#set(CMAKE_INSTALL_RPATH "$ORIGIN/lib:$ORIGIN")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
else()
set(CMAKE_MACOSX_RPATH TRUE)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
######
endif()

######

set(CMAKE_CXX_STANDARD 20)
Expand Down Expand Up @@ -72,42 +87,52 @@ if(ENABLE_SANITIZERS)
)
endif(ENABLE_SANITIZERS)


if(NOT BUILD_ONLY_DOC)
find_package(TBB REQUIRED)
find_package(Boost REQUIRED)
find_package(Python3 3.9...<3.99 COMPONENTS Development Interpreter REQUIRED)
find_package(CapnProto CONFIG REQUIRED)
if(NOT BUILD_NAJA_PYTHON)
find_package(TBB REQUIRED)
find_package(CapnProto CONFIG REQUIRED)
endif(NOT BUILD_NAJA_PYTHON)

find_package(Boost REQUIRED)
if (APPLE OR NOT ${BUILD_NAJA_PYTHON})
find_package(Python3 3.9...<3.99 COMPONENTS Interpreter Development.Embed Development.Module REQUIRED)
else()
find_package(Python3 3.9...<3.99 COMPONENTS Interpreter Development.Module REQUIRED)
endif()
endif(NOT BUILD_ONLY_DOC)

if(PROJECT_IS_TOP_LEVEL)
option(LONG_TESTS "Enable long tests" OFF)
include(CTest)
enable_testing()
add_subdirectory(test)

option(BUILD_SPHINX_DOCUMENTATION "Build Sphinx documentation" OFF)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Doxygen
# look for Doxygen package
find_package(Doxygen)
if(DOXYGEN_FOUND)
add_subdirectory(docs)
endif(DOXYGEN_FOUND)
#Sphinx
#look for Sphinx package
find_package(Sphinx)

if(BUILD_SPHINX_DOCUMENTATION)
if (NOT (DOXYGEN_FOUND AND SPHINX_FOUND))
message(SEND_ERROR "Doxygen and Sphinx must be available to build Sphinx documentation")
endif(NOT (DOXYGEN_FOUND AND SPHINX_FOUND))
endif(BUILD_SPHINX_DOCUMENTATION)
endif(PROJECT_IS_TOP_LEVEL)
if(PROJECT_IS_TOP_LEVEL AND NOT BUILD_NAJA_PYTHON)
option(LONG_TESTS "Enable long tests" OFF)
include(CTest)
enable_testing()
add_subdirectory(test)
option(BUILD_SPHINX_DOCUMENTATION "Build Sphinx documentation" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Doxygen
# look for Doxygen package
find_package(Doxygen)
if(DOXYGEN_FOUND)
add_subdirectory(docs)
endif(DOXYGEN_FOUND)
#Sphinx
#look for Sphinx package
find_package(Sphinx)
if(BUILD_SPHINX_DOCUMENTATION)
if (NOT (DOXYGEN_FOUND AND SPHINX_FOUND))
message(SEND_ERROR "Doxygen and Sphinx must be available to build Sphinx documentation")
endif(NOT (DOXYGEN_FOUND AND SPHINX_FOUND))
endif(BUILD_SPHINX_DOCUMENTATION)
endif(PROJECT_IS_TOP_LEVEL AND NOT BUILD_NAJA_PYTHON)

if(NOT BUILD_ONLY_DOC)
add_subdirectory(thirdparty)
add_subdirectory(cmake)
add_subdirectory(src)
add_subdirectory(primitives)
endif(NOT BUILD_ONLY_DOC)
add_subdirectory(thirdparty)
add_subdirectory(src)
if(NOT BUILD_NAJA_PYTHON)
add_subdirectory(cmake)
add_subdirectory(primitives)
endif(NOT BUILD_NAJA_PYTHON)
endif(NOT BUILD_ONLY_DOC)
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Welcome to Naja Python package
40 changes: 31 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,44 @@
# SPDX-License-Identifier: Apache-2.0

[build-system]
requires = ["scikit-build-core", "setuptools", "wheel"]
requires = ["scikit-build-core >=0.4.3"]
build-backend = "scikit_build_core.build"

[project]
name = "naja"
name = "najaeda"
version = "0.1.0"
description = "Naja Python package"
description = "Naja EDA Python package"
authors = [{name = "Naja Authors", email = "[email protected]"}]
readme = "README.rst"
requires-python = ">=3.8"
license = {text = "Apache License 2.0"}
#readme = "README.md"
#keywords = ["naja", "python", "package"]

#[tool.setuptools]
#packages = ["naja"]
#package_dir = {"" = "src/naja_python"}

[tool.scikit-build.cmake.define]
CMAKE_BUILD_TYPE="Release"
BUILD_NAJA_PYTHON="ON"

[project.urls]
Homepage = "https://github.com/najaeda/naja"

[tool.cibuildwheel]
build-verbosity = 1

[tool.cibuildwheel.linux]
build-frontend = "build"
before-all = '''
yum -y install wget boost-devel flex
wget https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
tar -xvzf flex-2.6.4.tar.gz
cd flex-2.6.4
./configure
make
make install
cd ..
wget http://ftp.gnu.org/gnu/bison/bison-3.8.tar.gz
tar -xvzf bison-3.8.tar.gz
cd bison-3.8
./configure
make
make install
cd ..
'''
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

add_subdirectory(core)
add_subdirectory(snl)
add_subdirectory(naja_python)
add_subdirectory(najaeda)
if(NOT BUILD_NAJA_PYTHON)
add_subdirectory(dnl)
add_subdirectory(bne)
Expand Down
4 changes: 2 additions & 2 deletions src/naja_python/CMakeLists.txt → src/najaeda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# SPDX-License-Identifier: Apache-2.0

if(BUILD_NAJA_PYTHON)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/naja
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/najaeda
DESTINATION ${CMAKE_INSTALL_PREFIX}
PATTERN "*~" EXCLUDE
PATTERN "__pycache__" EXCLUDE
)
else(BUILD_NAJA_PYTHON)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/naja
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/najaeda
DESTINATION ${CMAKE_INSTALL_LIBDIR}/python
PATTERN "*~" EXCLUDE
PATTERN "__pycache__" EXCLUDE
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

import logging
from naja import snl
from najaeda import snl


class Equipotential:
Expand Down
6 changes: 4 additions & 2 deletions src/snl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

add_subdirectory(snl)
add_subdirectory(formats)
add_subdirectory(snippets)
add_subdirectory(python)
add_subdirectory(python)
if(NOT BUILD_NAJA_PYTHON)
add_subdirectory(snippets)
endif(NOT BUILD_NAJA_PYTHON)
Loading

0 comments on commit 35595f7

Please sign in to comment.