Skip to content

Commit

Permalink
feat: Increase robustness of Python setup script (#1249)
Browse files Browse the repository at this point in the history
We've previously run into some minor issues with the Python setup script. This is only natural because shell scripting is hell, but we can still try to make it a little more robust. To this end, this commit adds two new features to the setup script:

1. The setup script now supports ZSH as well as Bash, so it should also work on Mac operating systems.
2. The script now tells the user which version of Python the bindings were set up for, so they don't run into versioning conflicts.
  • Loading branch information
stephenswat authored May 17, 2022
1 parent 190d85b commit de23d56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Examples/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ else()
endif()

add_custom_target(ActsPythonGlueCode)
configure_file(setup.sh.in ${_python_dir}/setup.sh COPYONLY)
configure_file(setup.sh.in ${_python_dir}/setup.sh @ONLY)
install(FILES setup.sh.in DESTINATION "python" RENAME setup.sh)


foreach(f ${py_files})
set(_target ${_python_dir}/acts/${f})
get_filename_component(_dir ${_target} DIRECTORY)
Expand Down
29 changes: 27 additions & 2 deletions Examples/Python/setup.sh.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
python_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# This file is part of the Acts project.
#
# Copyright (C) 2021-2022 CERN for the benefit of the Acts project
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

export PYTHONPATH=$python_dir:$PYTHONPATH
# This script sets up the ACTS Python bindings in the environment in a somewhat
# robust way.

if [ -n "$ZSH_VERSION" ]; then
export PYTHONPATH=${0:a:h}:$PYTHONPATH
elif [ -n "$BASH_VERSION" ]; then
python_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export PYTHONPATH=$python_dir:$PYTHONPATH
else
# If the current shell is not ZSH or Bash, we can't guarantee that the
# script will work, so we throw an error.
echo "ERROR: neither ZSH nor Bash was detected, other shells are not supported. The environment has not been modified."
exit 1
fi

# This message might seem excessive, but the Acts bindings are only installed
# for one Python version, and it is not trivial for the user to find out which.
# Thus, we let them know explicitly so they can more easily debug any potential
# import errors.
echo "INFO: Acts Python @Python_VERSION_MAJOR@.@Python_VERSION_MINOR@ bindings setup complete."

0 comments on commit de23d56

Please sign in to comment.