-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cython bindings oss build #2361
base: main
Are you sure you want to change the base?
Conversation
…3.13 api, augment setup.py (first hack)
…ll install with PYTHONPATH set
… add boost and other dep libs
… libiberty PIC build
…libs, target/min python version
…or test code, get tests passing
…ate test dir from folly/python source
for reference I am using the following script to bootstrap Python and Cython into the folly build environment ECHO=$([[ "$SHELL" == *"zsh"* ]] && echo "echo" || echo "echo -e")
$ECHO "${COLOR_GREEN}Setting up Python test environment ${COLOR_OFF}"
PYTHON_VERSION="3.13" # Latest Python version to install via uv
CYTHON_VERSION="3.0.11" # Target Cython release (3.1.0a1 crashes - use 3.1.0 when released)
PLATFORM="$(uname -s)"
case "${PLATFORM}" in
Linux*) PLATFORM=Linux;;
Darwin*) PLATFORM=Mac;;
*) PLATFORM="UNKNOWN:${PLATFORM}"
esac
$ECHO "${COLOR_GREEN}Detected platform: $PLATFORM ${COLOR_OFF}"
# Ensure python3 and pip3 are installed
if [ "${PLATFORM}" = "Linux" ]; then
if [ "${EUID}" -ne 0 ]; then
SUDO=sudo
fi
${SUDO} apt-get install -y python3 python3-pip python3-venv clang
elif [ "${PLATFORM}" = "Mac" ]; then
brew install python3
else
$ECHO "${COLOR_RED}[ ERROR ] Unrecognised platform: ${PLATFORM}${COLOR_OFF}"
exit 1
fi
VENV_DIR=".venv"
UV_PIP_INSTALL="uv pip install --no-config --upgrade"
export UV_PYTHON_INSTALL_DIR="${VENV_DIR}"
if [ ! -d "${VENV_DIR}" ]; then
[ -f ".python-version" ] && rm -f ".python-version"
python3 -m venv --prompt "pip" "${VENV_DIR}"
source "${VENV_DIR}/bin/activate"
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade uv
uv venv --prompt "uv" \
--seed --relocatable \
--allow-existing --no-config \
--python-preference only-managed \
--python "${PYTHON_VERSION}" \
"${VENV_DIR}"
fi
source ./.venv/bin/activate
if ! command -v "uv" >/dev/null 2>&1 ; then
$ECHO "${COLOR_RED}[ ERROR ] Failed to install uv... ${COLOR_OFF}"
exit -1
fi
# Ensure uv is upgraded to latest
${UV_PIP_INSTALL} uv
# Install desired python verion using uv
uv python install --no-config "${PYTHON_VERSION}"
uv python pin --no-config "${PYTHON_VERSION}"
# Install required packages
${UV_PIP_INSTALL} build wheel setuptools
#${UV_PIP_INSTALL} "git+https://github.com/cython/cython.git@${CYTHON_VERSION}"
${UV_PIP_INSTALL} "cython==${CYTHON_VERSION}"
${UV_PIP_INSTALL} pytest pytest-asyncio pytest-cov
${UV_PIP_INSTALL} aioquic
cd "${VENV_DIR}"
PYTHON_DIR=$(python3 -c 'import sysconfig; print(sysconfig.get_config_var("prefix").split("/")[-1])')
if [ -d "include" ] && [ ! -L "include" ]; then
rm -rf "include"
fi
ln -sf "${PYTHON_DIR}/include" "include"
cd ..
deactivate
$ECHO "${COLOR_GREEN}Python test environment is set up ${COLOR_OFF}" |
MacOS builds and tests successfully |
@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@gmarzot, I discovered through @Orvid that you and I have been doing similar work recently to revive the build for Python support in folly. (For additional context, I'm also working on reviving support for Python in the fbthrift repo as well.) My similar PR is in #2370. Can you let me know if that PR works for you? I noticed that your PR also includes support for newer extensions – mine only tries to fix up support for |
hi jmswen, can you supply the specific build command you are running to
execute the build (python cython version, platform etc.)?
Were you able to run any tests against the packages produced? attaching
output like this to PR is generally good.
You will see in my PR these details and a successful run of the unit tests
in the folly/python/test directory.
At first glance I see my PR as a superset of these changes. Though I do see
some things at the cmake level that I could merge in.
If we can agree my PR covers all your needs, then we can recommend to @Orvid
King ***@***.***> how to proceed.
thanks for contacting me and best regards, Giovanni
…On Thu, Jan 16, 2025 at 10:19 PM jmswen ***@***.***> wrote:
@gmarzot <https://github.com/gmarzot>, I discovered through @Orvid
<https://github.com/Orvid> that you and I have been doing similar work
recently to revive the build for Python support in folly. (For additional
context, I'm also working on reviving support for Python in the fbthrift
repo as well.) My similar PR is in #2370
<#2370>. Can you let me know if
that PR works for you? I noticed that your PR also includes support for
newer extensions – mine only tries to fix up support for folly.iobuf and
folly.executor at the moment, but it would be easy to extend the changes.
—
Reply to this email directly, view it on GitHub
<#2361 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB7T3IEYX4O5A43BEXNSC7D2LBZE3AVCNFSM6AAAAABU4N5YAGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOJXGM2TCNBYGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@gmarzot It seems the build/test commands were stripped from the commit info when exporting to GitHub from Meta's internal Phabricator. The commands I'm using (which you'll likely need to adapt slightly) are:
As I mentioned, I have also been working on reviving the fbthrift Python support, and I have verified that an fbthrift Python service works with my folly changes in #2370. As you alluded to, your PR makes more changes than mine. Given that it will likely take some time to review all those changes, I think the best path forward is to land my PR and rebase the changes related to |
@jmswen yes i guess not 100% orthogonal but we could proceed as you suggest. @Orvid not sure what input you need but i am fine with the suggestion above. @jmswen thank you for your work and contribution and i will check out the fbthrift stuff (not familiar). in the meantime i will merge you pr and see how it plays.. i am curious why you have c++17 vs c++20? and i am trying to see how you were able to seemingly skip some of the lib dependencies i ran into.. did you try using cython 3.1 dev? the iobuf pyx crashes compile for me. |
see attached file for bootstrapping python/cython venv into build environment
moved interface source files to not collide with cython gen names:
iobuf.cpp/h => iobuf_intf.cpp/h
executor.cpp/h => executor_intf.cpp/h
include paths for all cython generated .h _api.h <folly/...> and i left all the source references as <folly/python/...>
updated CMake ignore lists
small tweak to support python 3.13 Py_IsFinalizing()
rewrite setup.py - build all packages (folly, folly.iobuf, folly.executor, folly.fiber_manager, folly.build_mode)
several manifest dependency issues:
xz url redirects to sourceforge(?) and fails download (how is this working for anyone?)
ninja rather old version not compatible with modern python 3.13
libiberty was not supporting -fPIC needed to link to python bindings (hard-coded this change - could be improved - please review)
various changes to eliminate warnings from cython 3.0.11-1
I suggest eliminating all python support for versions prior to 3.0 and likewise requiring >=3.0 for cython would be reasonable.
I am building with PYTHON_EXTENSIONS ON like this:
simple test like this:
once the cython build above completes and installs, the test directory can be built from folly/python/test like this:
the tests may then be run from folly/python like this:
pytest -n auto -v test
MacOS Specific Setup: