Skip to content

Commit

Permalink
Added wheels release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-gromeyer committed Dec 22, 2022
1 parent 8da1d97 commit de86b7d
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 28 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true

#
# Build using CMake
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Build Python wheels

on:
push:
tags:
- 'v*'
workflow_dispatch:

jobs:
build_sdist:
name: Build SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Build SDist
run: pipx run build --sdist

- name: Check metadata
run: pipx run twine check dist/*

- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz


build_wheels:
name: Wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

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

- uses: pypa/cibuildwheel@v2.11.3
env:
CIBW_ARCHS_MACOS: auto universal2

- name: Verify clean directory
run: git diff --exit-code
shell: bash

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl


upload_all:
name: Upload wheels
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest

steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@v1.6.4
with:
password: ${{ secrets.PYPI_API_TOKEN }}

11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ build-wasm/
doc/
tests/error.log
conan/
python/build/
python/dist/
python/pyhtml2md.egg-info/
python/*.whl

build/
dist/
pyhtml2md.egg-info/
*.whl
wheelhouse/
tests/__pycache__/
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ set(HEADERS
)

if(PYTHON_BINDINGS)
include(python/CMakeLists.txt)
add_subdirectory(python/pybind11)
pybind11_add_module(pyhtml2md python/bindings.cpp ${SOURCES} ${HEADER})
target_compile_features(pyhtml2md PUBLIC cxx_std_11) # Require at least c++11
target_compile_definitions(pyhtml2md PRIVATE PYTHON_BINDINGS)
target_include_directories(pyhtml2md PRIVATE include)
return()
endif()

Expand Down
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include python/README.md COPYING python/pybind11/LICENSE python/pybind11/CMakeLists.txt CMakeLists.txt
graft python/pybind11/include
graft python/pybind11/tools
graft src
graft include
2 changes: 0 additions & 2 deletions html2mdConfig.cmake

This file was deleted.

39 changes: 39 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"ninja",
"cmake>=3.12",
]
build-backend = "setuptools.build_meta"

[tool.isort]
profile = "black"

[tool.mypy]
files = "setup.py"
python_version = "3.7"
strict = true
show_error_codes = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
warn_unreachable = true

[[tool.mypy.overrides]]
module = ["ninja"]
ignore_missing_imports = true


[tool.pytest.ini_options]
minversion = "6.0"
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
xfail_strict = true
filterwarnings = ["error"]
testpaths = ["tests"]

[tool.cibuildwheel]
test-command = "pytest {project}/tests"
test-extras = ["test"]
test-skip = ["*universal2:arm64"]
# Setuptools bug causes collision between pypy and cpython artifacts
before-build = "rm -rf {project}/build"

11 changes: 0 additions & 11 deletions python/CMakeLists.txt

This file was deleted.

17 changes: 12 additions & 5 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

pyhtml2md provides a way to use the html2md C++ library in Python. html2md is a fast and reliable library for converting HTML content into markdown.

## Installation
- [Installation](#installation)
- [Basic usage](#basic-usage)
- [Advanced usage](#advanced-usage)
- [Supported Tags](#supported-tags)
- [License](#license)

### Manually

1. Make sure you have a compiler with c++11 and ccmake installed on you system
2. Clone html2md: `git clone https://github.com/tim-gromeyer/html2md --recurse-submodules --depth=1`
3. Build and install the python package: `pip3 install ./html2md/python/`
## Installation

### Pre-build

Expand All @@ -20,6 +21,12 @@ You can also install from pip(not available yet):
pip3 install pyhtml2md
```

### Manually

1. Make sure you have a compiler with c++11 and ccmake installed on you system
2. Clone html2md: `git clone https://github.com/tim-gromeyer/html2md --recurse-submodules --depth=1`
3. Build and install the python package: `pip3 install ./html2md/`

## Basic usage

Here is an example of how to use the pyhtml2md to convert HTML to markdown:
Expand Down
4 changes: 2 additions & 2 deletions python/setup.py → setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from setuptools.command.build_ext import build_ext

# Get long description
with open("README.md") as f:
with open("python/README.md") as f:
long_description = f.read()

# Convert distutils Windows platform specifiers to CMake -A arguments
Expand Down Expand Up @@ -122,7 +122,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
build_temp.mkdir(parents=True)

subprocess.run(
["cmake", f"{ext.sourcedir}/.."] + cmake_args, cwd=build_temp, check=True
["cmake", ext.sourcedir] + cmake_args, cwd=build_temp, check=True
)
subprocess.run(
["cmake", "--build", "."] + build_args, cwd=build_temp, check=True
Expand Down
11 changes: 11 additions & 0 deletions tests/test_advanced.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pyhtml2md

options = pyhtml2md.Options()
options.splitLines = False

converter = pyhtml2md.Converter("<h1>Hello Python!</h1>", options)

def test_main():
assert converter.convert() == "# Hello Python!\n"
assert converter.ok() == True

5 changes: 5 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pyhtml2md

def test_main():
assert pyhtml2md.convert("<h1>Hello, world!</h1>") == "# Hello, world!\n"

0 comments on commit de86b7d

Please sign in to comment.