Remove install_python_bindings.py script and update docs

`install_python_bindings.py` was not used by CI
and scripts, except for `scripts/run-python-test.sh`
which only used it to invoke `cargo`.

Instead of using an additional script,
run cargo directly.

The documentation is updated to remove
references to `install_python_bindings.py`.
The section "Installing bindings from source"
was in fact incorrect as it suggested
running `tox --devenv` first and only then
compiling the library with `install_python_bindings.py`.
Now it explicitly says to run cargo first
and then install the package without using `tox`.
`tox` is still used for running the tests
and setting up development environment.
This commit is contained in:
link2xt
2023-03-30 09:33:04 +00:00
parent 3e65b6f3a6
commit ae5f72cf4f
5 changed files with 59 additions and 57 deletions

View File

@@ -8,6 +8,7 @@
- Update rPGP to 0.10.1. #4236 - Update rPGP to 0.10.1. #4236
### Fixes ### Fixes
- Fix python bindings README documentation on installing the bindings from source.
## [1.112.3] - 2023-03-30 ## [1.112.3] - 2023-03-30

View File

@@ -12,17 +12,17 @@ a low-level Chat/Contact/Message API to user interfaces and bots.
Installing pre-built packages (Linux-only) Installing pre-built packages (Linux-only)
========================================== ==========================================
If you have a Linux system you may try to install the ``deltachat`` binary "wheel" packages If you have a Linux system you may install the ``deltachat`` binary "wheel" packages
without any "build-from-source" steps. without any "build-from-source" steps.
Otherwise you need to `compile the Delta Chat bindings yourself`__. Otherwise you need to `compile the Delta Chat bindings yourself`__.
__ sourceinstall_ __ sourceinstall_
We recommend to first `install virtualenv <https://virtualenv.pypa.io/en/stable/installation.html>`_, We recommend to first create a fresh Python virtual environment
then create a fresh Python virtual environment and activate it in your shell:: and activate it in your shell::
virtualenv env # or: python -m venv python -m venv env
source env/bin/activate source env/bin/activate
Afterwards, invoking ``python`` or ``pip install`` only Afterwards, invoking ``python`` or ``pip install`` only
modifies files in your ``env`` directory and leaves modifies files in your ``env`` directory and leaves
@@ -40,16 +40,14 @@ To verify it worked::
Running tests Running tests
============= =============
Recommended way to run tests is using `tox <https://tox.wiki>`_. Recommended way to run tests is using `scripts/run-python-test.sh`
After successful binding installation you can install tox script provided in the core repository.
and run the tests::
pip install tox This script compiles the library in debug mode and runs the tests using `tox`_.
tox -e py3 By default it will run all "offline" tests and skip all functional
This will run all "offline" tests and skip all functional
end-to-end tests that require accounts on real e-mail servers. end-to-end tests that require accounts on real e-mail servers.
.. _`tox`: https://tox.wiki
.. _livetests: .. _livetests:
Running "live" tests with temporary accounts Running "live" tests with temporary accounts
@@ -61,13 +59,32 @@ Please feel free to contact us through a github issue or by e-mail and we'll sen
export DCC_NEW_TMP_EMAIL=<URL you got from us> export DCC_NEW_TMP_EMAIL=<URL you got from us>
With this account-creation setting, pytest runs create ephemeral e-mail accounts on the http://testrun.org server. These accounts exists only for one hour and then are removed completely. With this account-creation setting, pytest runs create ephemeral e-mail accounts on the http://testrun.org server.
One hour is enough to invoke pytest and run all offline and online tests:: These accounts are removed automatically as they expire.
After setting the variable, either rerun `scripts/run-python-test.sh`
or run offline and online tests with `tox` directly::
tox -e py3 tox -e py
Each test run creates new accounts. Each test run creates new accounts.
Developing the bindings
-----------------------
If you want to develop or debug the bindings,
you can create a testing development environment using `tox`::
tox -c python --devenv env
. env/bin/activate
Inside this environment the bindings are installed
in editable mode (as if installed with `python -m pip install -e`)
together with the testing dependencies like `pytest` and its plugins.
You can then edit the source code in the development tree
and quickly run `pytest` manually without waiting for `tox`
to recreating the virtual environment each time.
.. _sourceinstall: .. _sourceinstall:
Installing bindings from source Installing bindings from source
@@ -89,20 +106,34 @@ To install the Delta Chat Python bindings make sure you have Python3 installed.
E.g. on Debian-based systems `apt install python3 python3-pip E.g. on Debian-based systems `apt install python3 python3-pip
python3-venv` should give you a usable python installation. python3-venv` should give you a usable python installation.
Ensure you are in the deltachat-core-rust/python directory, create the First, build the core library::
virtual environment with dependencies using tox
and activate it in your shell::
cd python cargo build --release -p deltachat_ffi --features jsonrpc
tox --devenv env
`jsonrpc` feature is required even if not used by the bindings
because `deltachat.h` includes JSON-RPC functions unconditionally.
Create the virtual environment and activate it:
python -m venv env
source env/bin/activate source env/bin/activate
You should now be able to build the python bindings using the supplied script:: Build and install the bindings:
python3 install_python_bindings.py export DCC_RS_DEV="$PWD"
export DCC_RS_TARGET=release
python -m pip install python
The core compilation and bindings building might take a while, `DCC_RS_DEV` environment variable specifies the location of
depending on the speed of your machine. the core development tree. If this variable is not set,
`libdeltachat` library and `deltachat.h` header are expected
to be installed system-wide.
When `DCC_RS_DEV` is set, `DCC_RS_TARGET` specifies
the build profile name to look up the artifacts
in the target directory.
In this case setting it can be skipped because
`DCC_RS_TARGET=release` is the default.
Building manylinux based wheels Building manylinux based wheels
=============================== ===============================

View File

@@ -1,30 +0,0 @@
#!/usr/bin/env python3
"""
setup a python binding development in-place install with cargo debug symbols.
"""
import os
import subprocess
import sys
if __name__ == "__main__":
target = os.environ.get("DCC_RS_TARGET")
if target is None:
os.environ["DCC_RS_TARGET"] = target = "debug"
if "DCC_RS_DEV" not in os.environ:
dn = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.environ["DCC_RS_DEV"] = dn
cmd = ["cargo", "build", "-p", "deltachat_ffi", "--features", "jsonrpc"]
if target == "release":
os.environ["CARGO_PROFILE_RELEASE_LTO"] = "on"
cmd.append("--release")
print("running:", " ".join(cmd))
subprocess.check_call(cmd)
subprocess.check_call("rm -rf build/ src/deltachat/*.so src/deltachat/*.dylib src/deltachat/*.dll", shell=True)
if len(sys.argv) <= 1 or sys.argv[1] != "onlybuild":
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", "."])

View File

@@ -43,7 +43,7 @@ deps =
pygments pygments
restructuredtext_lint restructuredtext_lint
commands = commands =
black --quiet --check --diff setup.py install_python_bindings.py src/deltachat examples/ tests/ black --quiet --check --diff setup.py src/deltachat examples/ tests/
ruff src/deltachat tests/ examples/ ruff src/deltachat tests/ examples/
rst-lint --encoding 'utf-8' README.rst rst-lint --encoding 'utf-8' README.rst

View File

@@ -12,7 +12,7 @@ export DCC_RS_DEV=`pwd`
cd python cd python
python install_python_bindings.py onlybuild cargo build -p deltachat_ffi --features jsonrpc
# remove and inhibit writing PYC files # remove and inhibit writing PYC files
rm -rf tests/__pycache__ rm -rf tests/__pycache__
@@ -22,4 +22,4 @@ export PYTHONDONTWRITEBYTECODE=1
# run python tests (tox invokes pytest to run tests in python/tests) # run python tests (tox invokes pytest to run tests in python/tests)
#TOX_PARALLEL_NO_SPINNER=1 tox -e lint,doc #TOX_PARALLEL_NO_SPINNER=1 tox -e lint,doc
tox -e lint tox -e lint
tox -e doc,py3 tox -e doc,py