Skip to content

Commit

Permalink
Merge pull request #15 from Distributive-Network/feature/poetry
Browse files Browse the repository at this point in the history
Feature/poetry: Add poetry build and publish process whenever a release is tagged
  • Loading branch information
Xmader authored May 29, 2023
2 parents 3336a78 + 6f54c23 commit 3dddb9d
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
name: 'Testing Suite'
name: 'Test and Publish Suite'

on:
push:
branches:
- main
tags:
- '*'
workflow_call:
workflow_dispatch:
pull_request:

jobs:
test-suite:
test-and-publish:
strategy:
fail-fast: false
matrix:
os: [ 'ubuntu-latest' ] # , 'windows-latest', 'macos-latest' ]
python_version: [ '3.9', '3.10', '3.11' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
- name: Setup Poetry
uses: snok/install-poetry@v1
- name: Setup cmake
run: |
sudo apt-get install -y cmake doxygen graphviz gcovr llvm python3-dev python3-pytest
pip install pytest
echo "Installing Dependencies"
sudo apt-get update -y
sudo apt-get install -y cmake doxygen graphviz gcovr llvm
echo "Installing python deps"
poetry install --no-root
echo "Installed Dependencies"
- name: Cache spidermonkey build
id: cache-spidermonkey
uses: actions/cache@v3
Expand All @@ -35,17 +44,28 @@ jobs:
key: ${{ runner.os }}-spidermonkey
- name: Build-Library
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
run: ./setup.sh && ./build_script.sh
run: ./setup.sh #&& ./build_script.sh
- name: Build wheel
run: |
echo $(poetry run python --version)
poetry build --format=wheel
ls -lah ./dist/
- name: google-tests
run: |
cd build
make && make tests
gcovr --xml-pretty --exclude-unreachable-branches --print-summary -o coverage.xml
cd tests && ctest
cd ../src
python -m pytest ../../tests/python
cd ../../
poetry run python -m pip install ./dist/*.whl
poetry run python -m pytest tests/python
- name: google-tests-artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}-${{ github.run_id }}-${{ github.sha }}
path: ./build/coverage.xml
- name: Buid and Publish package
if: ${{ success() && github.event_name == 'push' && contains(github.ref, 'refs/tags/') }}
run: |
echo $(poetry run python --version)
poetry publish --no-interaction --skip-existing --build --username __token__ --password ${{ secrets.PYPI_API_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ tests/__pycache__/*
tests/python/__pycache__/*
Testing/Temporary
_spidermonkey_install
__pycache__
dist
*.so
25 changes: 25 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import subprocess
import os, sys

dir_path = os.path.dirname( os.path.realpath(__file__) )


def execute(cmd: str):
popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
shell = True, text = True )
for stdout_line in iter(popen.stdout.readline, ""):
sys.stdout.write(stdout_line)
sys.stdout.flush()

popen.stdout.close()
return_code = popen.wait()
if return_code:
raise subprocess.CalledProcessError(return_code, cmd)

def build():
build_script_sh = os.path.join( dir_path, 'build_script.sh' )
execute(f"bash {build_script_sh}")
execute(f"cp ./build/src/pythonmonkey.so ./python/pythonmonkey/pythonmonkey.so")

if __name__ == "__main__":
build()
158 changes: 158 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[tool.poetry]
name = "pythonmonkey"
version = "0.1.0"
description = ""
authors = ["Caleb Aikens <caleb@distributive.network>", "Tom Tang <xmader@distributive.network>"]
readme = "README.md"
packages = [
{ include = "pythonmonkey", from = "python" },
]
include = [ "python/pythonmonkey/pythonmonkey.so" ]


[tool.poetry.dependencies]
python = "^3.9"


[tool.poetry.build]
script = "build.py"
generate-setup-file = false


[tool.poetry.group.dev.dependencies]
pytest = "^7.3.1"
pip = "^23.1.2"
numpy = "^1.24.3"

[build-system]
requires = ["poetry-core>=1.0.0a9"]
build-backend = "poetry.core.masonry.api"

1 change: 1 addition & 0 deletions python/pythonmonkey/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .pythonmonkey import *
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/
echo "Installing dependencies"
sudo apt-get update --yes
sudo apt-get upgrade --yes
sudo apt-get install cmake python3-dev python3-pytest doxygen graphviz gcovr llvm g++ pkg-config m4 --yes
sudo apt-get install cmake doxygen graphviz gcovr llvm g++ pkg-config m4 --yes
sudo curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y #install rust compiler
echo "Done installing dependencies"

Expand Down

0 comments on commit 3dddb9d

Please sign in to comment.