Skip to content

Commit

Permalink
Build wheels for Linux, MacOS, Windows. PyPi release from GitHub acti…
Browse files Browse the repository at this point in the history
…ons.
  • Loading branch information
zopieux committed Aug 19, 2023
1 parent b7c05af commit 02bd29c
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/actions/cmark-gfm-patch/action.yml
@@ -1,7 +1,7 @@
name: Patch cmark-gfm
description: Apply local modifications to cmark-gfm
runs:
using: "composite"
using: composite
steps:
- run: git -C third_party/cmark apply $PWD/tasklist-id.patch
shell: bash
73 changes: 73 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,73 @@
name: Package and upload to PyPi
on:
release:
types: [published, edited]
jobs:
build:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, windows-2022, macos-12]

steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Patch cmark-gfm
uses: ./.github/actions/cmark-gfm-patch

- uses: actions/setup-python@v3
name: Install Python
with:
python-version: '3.11'

- name: Install build deps
run: |
python -m pip --disable-pip-version-check install cibuildwheel==2.15.0 twine==4.0.2
- uses: docker/setup-qemu-action@v1
if: runner.os == 'Linux'
name: Set up QEMU

- name: Build wheels
run: |
python -m cibuildwheel --output-dir dist
twine check ./dist/*.whl
- name: Build sdist
if: runner.os == 'Linux'
run: |
python setup.py sdist
twine check ./dist/*.tar.gz
- uses: actions/upload-artifact@v3
name: Upload wheels and sdist
with:
name: dist-${{ matrix.os }}
path: |-
./dist/*.whl
./dist/*.tar.gz
upload-pypi:
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
needs: [build]

steps:
- name: Retrieve dists
uses: actions/download-artifact@v3
with:
# No name to download from all matrix runs.
path: all_dists

- name: Combine dists into one folder
run: |-
mkdir -p dist
find all_dists/ -type f -exec cp -v '{}' dist/ ';'
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
59 changes: 59 additions & 0 deletions .github/workflows/check.yml
@@ -0,0 +1,59 @@
name: Check tests & typing
on:
pull_request:
push:
release:
jobs:
test:
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

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

- name: Patch cmark-gfm
uses: ./.github/actions/cmark-gfm-patch

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install -U pip pytest
python -m pip install -e .
- name: Test with pytest
run: pytest tests

- name: Test installing from sdist
run: |
python setup.py sdist
python -m venv /tmp/sdist-test
/tmp/sdist-test/bin/pip install ./dist/*.tar.gz
/tmp/sdist-test/bin/python -c 'import pycmarkgfm; print(pycmarkgfm.gfm_to_html("it *works*"))' | grep '<p>it <em>works</em></p>'
check-typing:
name: Check typing with mypy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v3
with:
python-version: '3.11'

- name: Install dependencies
run: python -m pip install mypy

- name: Check types
run: mypy pycmarkgfm/ tests/
58 changes: 58 additions & 0 deletions .github/workflows/generate.yml
@@ -0,0 +1,58 @@
name: Generate cmark header files
on:
push:
branches: [doesnotexit]
workflow_dispatch:
jobs:
generate:
name: Generate cmake header files for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]

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

- name: Patch cmark-gfm
uses: ./.github/actions/cmark-gfm-patch

- name: Build
run: |
mkdir build
cd build
cmake ../third_party/cmark
- name: Copy (Windows)
if: runner.os == 'Windows'
working-directory: ./build
run: |
Get-ChildItem -Recurse
New-Item -ItemType Directory -Force -Path ${{ github.workspace }}/generated/windows
Copy-Item -Force -Path extensions/cmark-gfm-extensions_export.h -Destination ${{ github.workspace }}/generated/windows
Copy-Item -Force -Path src/cmark-gfm_export.h -Destination ${{ github.workspace}}/generated/windows
Copy-Item -Force -Path src/cmark-gfm_version.h -Destination ${{ github.workspace}}/generated/windows
Copy-Item -Force -Path src/config.h -Destination ${{ github.workspace }}/generated/windows
- name: Copy (Unix)
if: runner.os == 'Linux'
working-directory: ./build
run: |
ls -lRa
mkdir -p ${{ github.workspace }}/generated/unix
cp extensions/cmark-gfm-extensions_export.h src/cmark-gfm_export.h src/cmark-gfm_version.h src/config.h ${{ github.workspace }}/generated/unix
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
add-paths: generated/
title: Update generated headers for ${{ runner.os }}
commit-message: Update generated headers for ${{ runner.os }}.
body: ''
reviewers: zopieux
branch: gen-headers
branch-suffix: short-commit-hash
delete-branch: true
99 changes: 0 additions & 99 deletions .github/workflows/test.yml

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
### 1.2.1

* No new feature nor bugfix.
* Now compatible with both Linux, MacOS and Windows, with precompiled wheels.
* The process of publishing package updates, including wheels, is now automatic via GitHub actions.

### 1.2.0

* No new feature nor bugfix.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -9,12 +9,12 @@ with enhanced support for task lists.
* As opposed to most cmark-gfm bindings out there, this package supports
[parsing and toggling task lists](#dealing-with-task-lists).
* Compatibility:
[![](https://github.com/Zopieux/pycmarkgfm/workflows/Test%20and%20package/badge.svg)](https://github.com/Zopieux/pycmarkgfm/actions?query=workflow%3A%22Test+and+package%22)
with Python 3.5, 3.6, 3.7, 3.8, 3.9 on Linux-like platforms. If you need Windows support, please contribute a PR.
[![](https://github.com/zopieux/pycmarkgfm/actions/workflows/check.yml/badge.svg?event=release)](https://github.com/zopieux/pycmarkgfm/actions/workflows/check.yml)
with Python 3.7 & newer, on Linux, MacOS and Windows.

## Installation

This packages is [available on PyPi](https://pypi.org/project/pycmarkgfm/).
This packages is [available on PyPi](https://pypi.org/project/pycmarkgfm/) along with precompiled wheels for most architectures.

$ pip install pycmarkgfm

Expand Down Expand Up @@ -107,7 +107,7 @@ You can also use `checked=True/False` instead of `TOGGLE` to force a particular
[cmarkgfm](https://pypi.org/project/cmarkgfm/) is similar to this package, in fact cmarkgfm's cffi build script
is partially re-used in this project – in compliance with its MIT license.

As of October 2020, cmarkgfm is still a well-maintained project and I recommend using it if you don't need the extra
As of October 2023, cmarkgfm is still a well-maintained project and I recommend using it if you don't need the extra
features provided by pycmarkgfm, most notably the support for task lists.

## License
Expand Down
17 changes: 0 additions & 17 deletions generated.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 6 additions & 4 deletions pycmarkgfm/build_cmark.py
Expand Up @@ -15,7 +15,8 @@
BUILD = os.path.join(PACKAGE_ROOT, "build")
SRC_DIR = os.path.join(PACKAGE_ROOT, "third_party/cmark/src")
EXTENSIONS_SRC_DIR = os.path.join(PACKAGE_ROOT, "third_party/cmark/extensions")
UNIX_GENERATED_SRC_DIR = os.path.join(PACKAGE_ROOT, "generated")
UNIX_GENERATED_SRC_DIR = os.path.join(PACKAGE_ROOT, "generated", "unix")
WIN_GENERATED_SRC_DIR = os.path.join(PACKAGE_ROOT, "generated", "windows")

with open(os.path.join(CWD, "cmark.cffi.h"), "r", encoding="utf-8") as fh:
CMARK_DEF_H = fh.read()
Expand Down Expand Up @@ -56,11 +57,12 @@ def _compiler_type():


COMPILER_TYPE = _compiler_type()
PY2 = sys.version_info[0] < 3
PY34 = sys.version_info[:2] == (3, 4)
if COMPILER_TYPE in {"unix", "mingw32"} or (PY2 or PY34):
if COMPILER_TYPE in {"unix", "mingw32"}:
EXTRA_COMPILE_ARGS = ["-std=c99"]
GENERATED_SRC_DIR = UNIX_GENERATED_SRC_DIR
elif COMPILER_TYPE == "msvc":
EXTRA_COMPILE_ARGS = ["/TP"]
GENERATED_SRC_DIR = WIN_GENERATED_SRC_DIR
else:
raise ValueError("unsupported compiler: %s" % COMPILER_TYPE)

Expand Down

0 comments on commit 02bd29c

Please sign in to comment.