Skip to content

Commit 56f785e

Browse files
committed
Cythonize original implementation
1 parent 6d57f22 commit 56f785e

File tree

5 files changed

+52424
-0
lines changed

5 files changed

+52424
-0
lines changed

.github/workflows/pythonbuild.yml

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
pull_request:
6+
release:
7+
types:
8+
- published
9+
10+
jobs:
11+
build_legacy:
12+
name: Build wheel for legacy Python versions
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-latest, windows-latest, macos-latest]
18+
env:
19+
CIBW_BUILD: cp27-* cp35-* pp27-*
20+
CIBW_BUILD_VERBOSITY: 3
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
with:
25+
submodules: 'true'
26+
27+
- name: Build wheels
28+
uses: pypa/[email protected]
29+
with:
30+
output-dir: wheelhouse
31+
32+
- name: Upload wheels
33+
uses: actions/upload-artifact@v2
34+
with:
35+
path: ./wheelhouse/*.whl
36+
37+
build_windows_27_legacy:
38+
name: Build wheel on windows-latest/auto/2.7
39+
runs-on: windows-latest
40+
41+
steps:
42+
- uses: actions/checkout@v2
43+
with:
44+
submodules: 'true'
45+
46+
- uses: ilammy/msvc-dev-cmd@v1
47+
48+
- name: Build 64-bit wheel
49+
uses: pypa/[email protected]
50+
with:
51+
output-dir: wheelhouse
52+
env:
53+
CIBW_BUILD: cp27-win_amd64
54+
DISTUTILS_USE_SDK: 1
55+
CIBW_BUILD_VERBOSITY: 3
56+
MSSdk: 1
57+
58+
- uses: ilammy/msvc-dev-cmd@v1
59+
with:
60+
arch: x86
61+
62+
- name: Build 32-bit wheel
63+
uses: pypa/[email protected]
64+
with:
65+
output-dir: wheelhouse
66+
env:
67+
CIBW_BUILD: cp27-win32
68+
DISTUTILS_USE_SDK: 1
69+
CIBW_BUILD_VERBOSITY: 3
70+
MSSdk: 1
71+
72+
- name: Upload wheels
73+
uses: actions/upload-artifact@v2
74+
with:
75+
path: ./wheelhouse/*.whl
76+
77+
build_wheels:
78+
name: Build wheel on ${{ matrix.os }}/auto/${{matrix.python_tag}}
79+
runs-on: ${{ matrix.os }}
80+
strategy:
81+
fail-fast: false
82+
matrix:
83+
python_tag: ["cp37-*", "cp38-*", "cp39-*"]
84+
os: [windows-latest, macos-latest]
85+
env:
86+
CIBW_BUILD: ${{matrix.python_tag}}
87+
CIBW_TEST_REQUIRES: pytest hypothesis pandas
88+
CIBW_TEST_COMMAND: pytest {package}/tests
89+
CIBW_BUILD_VERBOSITY: 3
90+
91+
steps:
92+
- uses: actions/checkout@v2
93+
with:
94+
submodules: 'true'
95+
96+
- name: Build wheels
97+
uses: pypa/[email protected]
98+
with:
99+
output-dir: wheelhouse
100+
101+
- name: Upload wheels
102+
uses: actions/upload-artifact@v2
103+
with:
104+
path: ./wheelhouse/*.whl
105+
106+
build_wheels_apple_silicon:
107+
name: Build wheel on macos-latest/universal2+arm64/${{matrix.python_tag}}
108+
runs-on: macos-latest
109+
strategy:
110+
fail-fast: false
111+
matrix:
112+
python_tag: ["cp38-*", "cp39-*"]
113+
env:
114+
CIBW_BUILD: ${{matrix.python_tag}}
115+
CIBW_ARCHS_MACOS: "universal2 arm64"
116+
CIBW_BUILD_VERBOSITY: 3
117+
118+
steps:
119+
- uses: actions/checkout@v2
120+
with:
121+
submodules: 'true'
122+
123+
- name: Build wheels
124+
uses: pypa/[email protected]
125+
with:
126+
output-dir: wheelhouse
127+
128+
- name: Upload wheels
129+
uses: actions/upload-artifact@v2
130+
with:
131+
path: ./wheelhouse/*.whl
132+
133+
build_wheels_manylinux:
134+
name: Build wheels on ubuntu-latest/${{matrix.arch}}/${{matrix.python_tag}}
135+
runs-on: ubuntu-latest
136+
strategy:
137+
fail-fast: false
138+
matrix:
139+
arch: [auto, aarch64, ppc64le, s390x]
140+
python_tag: [ "cp36-*", "cp37-*", "cp38-*", "cp39-*"]
141+
env:
142+
CIBW_ARCHS_LINUX: ${{matrix.arch}}
143+
CIBW_BUILD: ${{matrix.python_tag}}
144+
CIBW_TEST_SKIP: "*-manylinux_{aarch64,ppc64le,s390x}"
145+
CIBW_TEST_REQUIRES: pytest hypothesis pandas
146+
CIBW_TEST_COMMAND: pytest {package}/tests
147+
CIBW_BUILD_VERBOSITY: 3
148+
149+
steps:
150+
- uses: actions/checkout@v2
151+
with:
152+
submodules: 'true'
153+
154+
- uses: docker/setup-qemu-action@v1
155+
name: Set up QEMU
156+
157+
- name: Build wheel
158+
uses: pypa/[email protected]
159+
with:
160+
output-dir: wheelhouse
161+
162+
- name: Upload wheels
163+
uses: actions/upload-artifact@v2
164+
with:
165+
path: ./wheelhouse/*.whl
166+
167+
build_wheels_pypy:
168+
name: Build wheel on ${{ matrix.os }}/auto/pp37-*
169+
runs-on: ${{ matrix.os }}
170+
strategy:
171+
fail-fast: false
172+
matrix:
173+
# numpy ships no wheels for pypy on mac os
174+
os: [ubuntu-latest, windows-latest]
175+
env:
176+
CIBW_BUILD: "pp37-*"
177+
# activate tests when the fix for
178+
# https://foss.heptapod.net/pypy/pypy/-/issues/3413 is released
179+
CIBW_TEST_REQUIRES: pytest hypothesis pandas
180+
CIBW_TEST_COMMAND: pytest {package}/tests
181+
CIBW_BUILD_VERBOSITY: 3
182+
183+
steps:
184+
- uses: actions/checkout@v2
185+
with:
186+
submodules: 'true'
187+
188+
- name: Build wheels
189+
uses: pypa/[email protected]
190+
with:
191+
output-dir: wheelhouse
192+
193+
- name: Upload wheels
194+
uses: actions/upload-artifact@v2
195+
with:
196+
path: ./wheelhouse/*.whl
197+
198+
build_sdist:
199+
name: Build source distribution
200+
runs-on: ubuntu-latest
201+
steps:
202+
- uses: actions/checkout@v2
203+
with:
204+
submodules: 'true'
205+
206+
- uses: actions/setup-python@v2
207+
name: Install Python
208+
with:
209+
python-version: '3.7'
210+
211+
- name: Build sdist
212+
run: |
213+
pip3 install build; python3 -m build --sdist
214+
# test whether tarball contains all files required for compiling
215+
pip3 install dist/cydifflib-*.tar.gz
216+
pip3 uninstall cydifflib --yes
217+
218+
- uses: actions/upload-artifact@v2
219+
with:
220+
path: dist/*.tar.gz
221+
222+
deploy-wheels:
223+
if: github.event_name == 'release' && github.event.action == 'published'
224+
needs: [build_legacy, build_windows_27_legacy, build_wheels, build_wheels_apple_silicon, build_wheels_manylinux, build_wheels_pypy, build_sdist]
225+
name: deploy wheels to pypi
226+
runs-on: ubuntu-18.04
227+
228+
steps:
229+
- uses: actions/download-artifact@v2
230+
with:
231+
name: artifact
232+
path: dist
233+
234+
- uses: pypa/gh-action-pypi-publish@master
235+
with:
236+
user: __token__
237+
password: ${{ secrets.pypi_password }}

setup.cfg

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[metadata]
2+
name = cydifflib
3+
version = 0.1.0
4+
url = https://github.com/maxbachmann/cydifflib
5+
author = Max Bachmann
6+
author_email = [email protected]
7+
description = Fast difflib reimplementation in Cython
8+
long_description = file: README.md
9+
long_description_content_type = text/markdown
10+
11+
license = MIT
12+
license_file = LICENSE
13+
classifiers =
14+
Programming Language :: Python :: 2
15+
Programming Language :: Python :: 2.7
16+
Programming Language :: Python :: 3
17+
Programming Language :: Python :: 3.5
18+
Programming Language :: Python :: 3.6
19+
Programming Language :: Python :: 3.7
20+
Programming Language :: Python :: 3.8
21+
Programming Language :: Python :: 3.9
22+
License :: OSI Approved :: MIT License
23+
24+
[options]
25+
zip_safe = False
26+
include_package_data = True
27+
package_dir=
28+
=src
29+
packages = find:
30+
python_requires = >=2.7
31+
32+
[options.packages.find]
33+
where=src

setup.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from setuptools import setup, Extension
2+
from setuptools.command.build_ext import build_ext
3+
import sys
4+
5+
class BuildExt(build_ext):
6+
"""A custom build extension for adding compiler-specific options."""
7+
c_opts = {
8+
'msvc': ['/EHsc', '/O2', '/W4', '/DNDEBUG'],
9+
'unix': ['-O3', '-std=c++11', '-Wextra', '-Wall', '-Wconversion', '-g0', '-DNDEBUG'],
10+
}
11+
l_opts = {
12+
'msvc': [],
13+
'unix': [],
14+
}
15+
16+
if sys.platform == 'darwin':
17+
darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.9']
18+
c_opts['unix'] += darwin_opts
19+
l_opts['unix'] += darwin_opts
20+
21+
def build_extensions(self):
22+
ct = self.compiler.compiler_type
23+
opts = self.c_opts.get(ct, [])
24+
link_opts = self.l_opts.get(ct, [])
25+
if ct == 'unix':
26+
opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version())
27+
elif ct == 'msvc':
28+
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
29+
for ext in self.extensions:
30+
ext.extra_compile_args += opts
31+
ext.extra_link_args += link_opts
32+
build_ext.build_extensions(self)
33+
34+
ext_modules = [
35+
Extension(
36+
name='cydifflib',
37+
sources=['src/cydifflib.cpp'],
38+
language='c++',
39+
)
40+
]
41+
42+
if __name__ == "__main__":
43+
setup(
44+
cmdclass={'build_ext': BuildExt},
45+
ext_modules = ext_modules
46+
)

0 commit comments

Comments
 (0)