Skip to content

Commit

Permalink
Use modern tooling to build and test Python wheels (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Aug 2, 2024
2 parents 929052b + b9c6cc8 commit f3263b3
Show file tree
Hide file tree
Showing 19 changed files with 456 additions and 5,922 deletions.
8 changes: 6 additions & 2 deletions .ci/python.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash
set -e

python3 -m venv .venv
. .venv/bin/activate

pip install setuptools build tox

./autogen.sh
./configure PYTHON=/usr/bin/python3 CC=clang CXX=clang++ CXXFLAGS='-O1'
./configure CC=clang CXX=clang++ CXXFLAGS='-O1'
make -C Python
make -C Python wheel
3 changes: 2 additions & 1 deletion .ci/python.check
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash
set -e

. .venv/bin/activate

make -C Python check

. .venv/bin/activate
for i in Python/examples/*.py
do
echo "$i"
Expand Down
2 changes: 1 addition & 1 deletion .ci/python.install
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -e

python3 -m venv .venv
. .venv/bin/activate

pip install Python/dist/QuantLib-*.whl
grep -v QuantLib binder/requirements.txt > Python/examples/requirements.txt
pip install -r Python/examples/requirements.txt
51 changes: 3 additions & 48 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,6 @@ autom4te.cache
config.log
config.status
config/
CSharp/cpp/quantlib_wrap.cpp
CSharp/cpp/quantlib_wrap.h
CSharp/cpp/build
CSharp/csharp/obj
CSharp/examples/*/bin
CSharp/examples/*/obj
CSharp/.vs/
Java/bin/
Java/quantlib_wrap.cpp
Java/quantlib_wrap.h
Perl/Makefile.quantlib
Perl/QuantLib.bs
Perl/blib/
Perl/pm_to_blib
Perl/quantlib_wrap.cpp
Perl/MYMETA.yml
Perl/MYMETA.json
Python/QuantLib/quantlib_wrap.cpp
Python/.cache/
Python/QuantLib.egg-info
Python/QuantLib_Python.egg-info
Python/dist
Python/examples/*.ipynb
Python/examples/.ipynb_checkpoints
R/src/QuantLib.cpp
R/makeRData.Rout
R/src/symbols.rds
R.Rcheck
Ruby/extension.mak
Ruby/quantlib_wrap.cpp

# Build outputs
**/x64/Debug
Expand All @@ -44,13 +14,15 @@ Ruby/quantlib_wrap.cpp
**/bin/*.xml
**/bin/*.manifest

# CLion
# IDEs
.idea
.vscode
cmake-build-debug

# Artifacts created in multiple directories
Makefile
Makefile.in
.build-stamp
testCaseCollection.xml
.deps
.libs
Expand All @@ -59,8 +31,6 @@ testCaseCollection.xml
*.o
*.so
*.dylib
.build-stamp
*.pyc
*.exe
*.dll
*.exp
Expand All @@ -81,18 +51,3 @@ testCaseCollection.xml
*.pch
*.idb
*.ipch

# Outputs
CSharp/csharp/*.cs
CSharp/NQuantLib.dll
Java/QuantLib.jar
Java/*.jnilib
Java/org/
Perl/QuantLib.pm
Python/QuantLib/QuantLib.py
Python/build
R/R/QuantLib.R
R/QuantLib.RData

.vscode
**/venv
9 changes: 9 additions & 0 deletions CSharp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cpp/quantlib_wrap.cpp
cpp/quantlib_wrap.h
csharp/*.cs
NQuantLib.dll
cpp/build
csharp/obj
examples/*/bin
examples/*/obj
.vs/
6 changes: 6 additions & 0 deletions Java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bin/
quantlib_wrap.cpp
quantlib_wrap.h
QuantLib.jar
*.jnilib
org/
10 changes: 10 additions & 0 deletions Python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
src/QuantLib/quantlib_wrap.cpp
src/QuantLib/QuantLib.py
src/QuantLib.egg-info
build
dist
examples/*.ipynb
examples/.ipynb_checkpoints
*.pyc
.cache/
**/.venv
24 changes: 10 additions & 14 deletions Python/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@

CLEANFILES = QuantLib/quantlib_wrap.cpp QuantLib/QuantLib.py .build-stamp
CLEANFILES = src/QuantLib/quantlib_wrap.cpp src/QuantLib/QuantLib.py .build-stamp

BUILT_SOURCES = QuantLib/quantlib_wrap.cpp QuantLib/QuantLib.py
BUILT_SOURCES = src/QuantLib/quantlib_wrap.cpp src/QuantLib/QuantLib.py

if HAVE_PYTHON
if BUILD_PYTHON

all-local: .build-stamp

.build-stamp: QuantLib/quantlib_wrap.cpp QuantLib/QuantLib.py setup.py
CXXFLAGS="$(CXXFLAGS) $(CXXWARNINGFLAGS)" CC="$(CC)" CXX="$(CXX)" $(PYTHON) setup.py build
.build-stamp: src/QuantLib/quantlib_wrap.cpp src/QuantLib/QuantLib.py setup.py
CXXFLAGS="$(CXXFLAGS) $(CXXWARNINGFLAGS)" CC="$(CC)" CXX="$(CXX)" $(PYTHON) -m build --wheel
rm -f LICENSE.TXT
touch .build-stamp

check-local: .build-stamp
$(PYTHON) setup.py test

install-exec-local: .build-stamp
$(PYTHON) setup.py install
tox run

wheel: .build-stamp
$(PYTHON) setup.py bdist_wheel

clean-local:
rm -rf build
rm -rf build dist

endif
endif

QuantLib/quantlib_wrap.cpp QuantLib/QuantLib.py: ../SWIG/*.i
$(SWIG) -python -c++ -outdir QuantLib \
-o QuantLib/quantlib_wrap.cpp ../SWIG/quantlib.i
src/QuantLib/quantlib_wrap.cpp src/QuantLib/QuantLib.py: ../SWIG/*.i
$(SWIG) -python -c++ -outdir src/QuantLib -o src/QuantLib/quantlib_wrap.cpp ../SWIG/quantlib.i

dist-hook:
mkdir -p $(distdir)/examples
cp ./examples/*.py $(distdir)/examples
mkdir -p $(distdir)/test
cp ./test/*.py $(distdir)/test

EXTRA_DIST = README.txt setup.py setup.cfg QuantLib/__init__.py $(BUILT_SOURCES)
EXTRA_DIST = README.txt pytest.ini setup.cfg setup.py swig.cmd tox.ini src/QuantLib/__init__.py $(BUILT_SOURCES)

46 changes: 0 additions & 46 deletions Python/QuantLib-Python.spec.in

This file was deleted.

30 changes: 10 additions & 20 deletions Python/README.txt → Python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,25 @@ The C++ wrappers for the QuantLib-Python extension module are created
by means of SWIG (Simplified Wrapper and Interface Generator)
available from <http://www.swig.org/>; the latest version is suggested.

Building the wrappers requires the Setuptools package.
Building the wrappers requires the `setuptools` and `build` packages;
both can be installed (preferably in a virtual environment) by means
of `pip install`.

Generating the wrappers is not required if you are using a distributed
tarball. If you're building from a Git checkout, instead, use the
command:

python setup.py wrap

The commands to be issued for building and testing the
wrappers are:

python setup.py build
python setup.py test

respectively.
command `swig.cmd` on Windows or `make` on other platforms. Running
`make` also builds the wrappers as a wheel; on Windows, this requires
the explicit command `python -m build --wheel` instead.

The build step requires that the QuantLib headers and library can be
found by the compiler. On Unix-like platforms, this requires that
`quantlib-config` is in your path. On the Windows platform, instead,
it requires you to define a `QL_DIR` environment variable pointing to
your QuantLib directory (e.g., `C:\Lib\QuantLib`.)

The suggested way to install the module is to run first

python setup.py bdist_wheel
Once built, the resulting wheel can be installed with `pip`.

which requires the wheel module to be available and which will create
a QuantLib wheel in the dist folder. The resulting wheel can then
be installed with pip in the desired environment.
Finally, testing the wheel requires `tox`, also available via
`pip install`. Once available, running `tox run` will run the
test suite.

The test suite is implemented on top of the PyUnit framework, which is
included in the Python standard library.
2 changes: 2 additions & 0 deletions Python/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
filterwarnings = ignore:builtin type .* has no __module__ attribute:DeprecationWarning
Loading

0 comments on commit f3263b3

Please sign in to comment.