Skip to content

Commit

Permalink
Added custom build script to switch to pyproject.toml as single sourc…
Browse files Browse the repository at this point in the history
…e of truth
  • Loading branch information
JessicaTegner committed Aug 31, 2023
1 parent df67c94 commit 403bb74
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 134 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ jobs:
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Download pandoc
run: poetry run python setup_binary.py download_pandoc
run: poetry run python binary_build_prep.py
- name: run tests
run: poetry run python tests.py

builder_pypandoc:
needs: [test]
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-20.04 # Any OS is fine as this wheel is not OS dependent
steps:
- name: Check out repository
Expand All @@ -60,10 +59,12 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: 3.9 # Build any 1 python version as this wheel is not version dependent
- name: Update dependencies
run: python -m pip install -U pip wheel setuptools
- name: Install and configure Poetry
run: |
pip3 install poetry
poetry config virtualenvs.in-project true
- name: Build wheel
run: python setup.py sdist bdist_wheel
run: poetry build
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -72,7 +73,6 @@ jobs:

builder_pypandoc_binary:
needs: [test]
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
# Ref: https://cibuildwheel.readthedocs.io/en/stable/options/#archs
Expand All @@ -85,12 +85,12 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Remove pyproject and use setuptools
run: rm pyproject.toml
- name: Build binary Archive
uses: pypa/cibuildwheel@v2.9.0
uses: pypa/cibuildwheel@v2.15.0
env:
CIBW_BEFORE_ALL: "mv setup_binary.py setup.py && python3 setup.py download_pandoc"
CIBW_BUILD_FRONTEND: "build"
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_BEFORE_ALL: "python3 binary_build_prep.py"
CIBW_BUILD: cp39-* # Build any 1 python version as this wheel is not version dependent
# We skip some variants because:
# - pandoc does not publish binaries for Linux 32bit
Expand All @@ -103,7 +103,7 @@ jobs:

publisher_release:
needs: [builder_pypandoc, builder_pypandoc_binary]
if: startsWith(github.ref, 'refs/tags/v')
if: github.ref == 'refs/heads/master' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Check out repository
Expand Down
22 changes: 22 additions & 0 deletions binary_build_prep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
from pypandoc.pandoc_download import download_pandoc

import subprocess
import sys

check_result = subprocess.call(["patch", "--dry-run", "-N", "-u", "pyproject.toml", "-i", "pyproject.toml.patch"])
if check_result != 0:
print("Something is wrong with the pyproject.toml patch")
sys.exit(1)


patch_result = subprocess.check_call(["patch", "-u", "pyproject.toml", "-i", "pyproject.toml.patch"])
if patch_result != 0:
print("Something went wrong when patching pyproject.toml")
sys.exit(2)


print("Downloading pandoc")
targetfolder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "pypandoc", "files")
download_pandoc(targetfolder=targetfolder)

2 changes: 2 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def build(*args, **kwargs):
pass
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[tool.poetry]
name = "pypandoc"
version = "1.11"
description = "Thin wrapper for pandoc"
authors = ["JessicaTegner <jessica.tegneroutlook.com>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/JessicaTegner/pypandoc"
version = "1.12"

classifiers = [
'Development Status :: 4 - Beta',
Expand Down Expand Up @@ -37,8 +37,12 @@ python = "^3.6"
[tool.poetry.dev-dependencies]
pandocfilters = "^1.5.0"

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

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

[tool.poetry.urls]
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- pyproject.toml 2023-08-31 17:54:06.196415200 +0200
+++ pyproject.binary.toml 2023-08-31 17:57:56.021476600 +0200
@@ -1,5 +1,6 @@
[tool.poetry]
-name = "pypandoc"
+name = "pypandoc_binary"
+include = ["pypandoc/files/*"]
description = "Thin wrapper for pandoc"
authors = ["JessicaTegner <jessica.tegneroutlook.com>"]
license = "MIT"
26 changes: 0 additions & 26 deletions setup.py

This file was deleted.

95 changes: 0 additions & 95 deletions setup_binary.py

This file was deleted.

0 comments on commit 403bb74

Please sign in to comment.