Skip to content
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

Refactor chapel-py to use the C Python Stable API #26565

Merged
merged 23 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions doc/rst/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
# to prevent failures if chapel-py is not built/installed, check if its installed
# if installed, add the path and generate the rst file
# if not installed, just create the file so that the build doesn't fail
chapel_py_dir = os.path.abspath(
"../../third-party/chpl-venv/install/chpl-frontend-py-deps-py"
+ str(sys.version_info.major)
+ str(sys.version_info.minor)
)
old_sys_path = sys.path.copy()
sys.path.insert(0, os.path.abspath('../../util/chplenv'))
import chpl_home_utils
chapel_py_dir = chpl_home_utils.get_chpldeps(True)
jabraham17 marked this conversation as resolved.
Show resolved Hide resolved
del chpl_home_utils
sys.path = old_sys_path

include_chapel_py_docs = False
chapel_py_api_template = os.path.abspath("./tools/chapel-py/chapel-py-api-template.rst")
chapel_py_api_rst = os.path.abspath("./tools/chapel-py/chapel-py-api.rst")
Expand Down
3 changes: 1 addition & 2 deletions third-party/chpl-venv/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ CHPL_VENV_VIRTUALENV_DIR_DEPS2_OK=$(CHPL_VENV_BUILD)/build-venv/ok2
CHPL_VENV_VIRTUALENV_BIN=$(CHPL_VENV_VIRTUALENV_DIR)/bin
CHPL_VENV_INSTALL=$(CHPL_VENV_DIR)/install
CHPL_VENV_CHPLDEPS=$(CHPL_VENV_INSTALL)/chpldeps
# CHPL_VENV_CHPL_FRONTEND_PY_DEPS=$(CHPL_VENV_INSTALL)/chpl-frontend-py-deps-py$(shell $(PYTHON) -c 'import sys; print(str(sys.version_info.major) + str(sys.version_info.minor))')
CHPL_VENV_CHPL_FRONTEND_PY_DEPS=$(CHPL_VENV_CHPLDEPS)
CHPL_VENV_CHPL_FRONTEND_PY_DEPS=$(shell $(PYTHON) $(CHPL_MAKE_HOME)/util/chplenv/chpl_home_utils.py --chpldeps-chapel-py)
CHPL_VENV_CHPLDEPS_MAIN=$(CHPL_VENV_CHPLDEPS)/__main__.py
18 changes: 11 additions & 7 deletions util/chplenv/chpl_home_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,18 @@ def add_vars_to_paths(s):
# Get the chpl-venv install directory:
# $CHPL_HOME/third-party/chpl-venv/install/chpldeps
@memoize
def get_chpldeps(version=None):
def get_chpldeps(chapel_py=False):
base = os.path.join(get_chpl_third_party(), "chpl-venv", "install")
if version is None:
if not chapel_py:
chpl_venv = os.path.join(base, "chpldeps")
else:
chpl_venv = os.path.join(base, "chpl-frontend-py-deps-py" + str(version))
# for 3.10+, we can use chpl-frontend-py-deps
# for other versions, we have to use chpl-frontend-py-deps-pyX.Y
name = "chpl-frontend-py-deps"
jabraham17 marked this conversation as resolved.
Show resolved Hide resolved
minor_version = sys.version_info.minor
if minor_version < 10:
name += "-py" + str(minor_version)
chpl_venv = os.path.join(base, name)
return chpl_venv

@memoize
Expand All @@ -180,12 +186,10 @@ def _main():
parser.add_option('--chpldeps', action='store_const',
dest='func', const=get_chpldeps)
parser.add_option(
"--chpldeps-version",
"--chpldeps-chapel-py",
action="store_const",
dest="func",
const=lambda: get_chpldeps(
str(sys.version_info.major) + str(sys.version_info.minor)
),
const=lambda: get_chpldeps(True),
)
parser.add_option('--using-module', action='store_const',
dest='func', const=using_chapel_module)
Expand Down
7 changes: 5 additions & 2 deletions util/config/run-in-venv-with-python-bindings.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ PLATFORM=$("$CHPL_HOME/util/printchplenv" --value --only CHPL_HOST_PLATFORM)
# Perform checks and set up environment variables for virtual env.
source $CWD/run-in-venv-common.bash

chpl_frontend_py_deps=$("$python" "$CHPL_HOME/util/chplenv/chpl_home_utils.py" --chpldeps)
chpl_frontend_py_deps=$("$python" "$CHPL_HOME/util/chplenv/chpl_home_utils.py" --chpldeps-chapel-py)
export PYTHONPATH="$chpl_frontend_py_deps":$PYTHONPATH

if [ ! -d "$chpl_frontend_py_deps/chapel" ]; then
python_version=$("$python" -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
echo "chapel python bindings are not built for python ${python_version}" 1>&2
echo "make sure your current python version matches the one used to build chapel" 1>&2
# if chpl_frontend_py_deps does not end with 'deps', tell user to match python version
if [[ "$chpl_frontend_py_deps" != *deps ]]; then
echo "make sure your current python version matches the one used to build chapel" 1>&2
fi
exit 1
fi

Expand Down
Loading