diff options
author | Matthew Sotoudeh <masotoudeh@ucdavis.edu> | 2020-08-22 11:27:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-22 11:27:56 -0700 |
commit | 3691134fa28bc5580f7f6ac39e3a70b7b603a918 (patch) | |
tree | b89c0763fe8def50c746e731eb6abdd856097fa9 | |
parent | 5edcf3b97c4c77b654af177bfa27558d9b88b52f (diff) |
CI scripts to test building Python with the setup script
Adds a CI script to run setup_python.sh. Also provides explicit instructions in the README for installing on macOS, as well as a warning if the setup script finds that ssl or zlib is not installed.
-rw-r--r-- | .github/workflows/test_setup_python.yml | 29 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 10 | ||||
-rwxr-xr-x | setup_python.sh | 11 |
4 files changed, 50 insertions, 1 deletions
diff --git a/.github/workflows/test_setup_python.yml b/.github/workflows/test_setup_python.yml new file mode 100644 index 0000000..e54e85c --- /dev/null +++ b/.github/workflows/test_setup_python.yml @@ -0,0 +1,29 @@ +# Adapted from: https://github.com/pubref/rules_protobuf/blob/master/.travis.yml +name: Test Setting up Python + +on: + pull_request: + paths: + - 'setup_python.sh' + - '.github/workflows/test_setup_python.yml' + +jobs: + set-up-python: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-10.15, ubuntu-16.04, ubuntu-18.04, ubuntu-20.04] + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.7.4. + # https://stackoverflow.com/questions/36774171/how-to-include-ssl-with-python-build-on-macos + run: | + OPTIONS="" + if [[ "${{ matrix.os }}" =~ "macos" ]] + then + OPTIONS="--with-openssl=$(brew --prefix openssl)" + fi + echo y | ./setup_python.sh 3.7.4 $HOME/.bazel_python $OPTIONS + [ "$($HOME/.bazel_python/3.7.4/bin/python3 --version)" = "Python 3.7.4" ] + $HOME/.bazel_python/3.7.4/bin/python3 -c "import ssl" + $HOME/.bazel_python/3.7.4/bin/python3 -c "import zlib" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp @@ -2,6 +2,7 @@ A simple way to use Python reproducibly within Bazel. ## One-Time Setup +#### Ubuntu First, install the packages necessary to build Python with commonly-used modules. On Ubuntu to get `pip`, `zlib`, and `bz2` modules, this looks like: ```bash @@ -24,6 +25,15 @@ Python, however you should always use the same install target directory (e.g., `$HOME/.bazel_python` above). Each version will be placed in its own subdirectory of that target. +#### macOS +On macOS, running the above will likely give a warning about missing SSL +modules. To resolve this, assuming you have Homebrew installed, you may need to +run instead: +```bash +brew install openssl +./setup_python.sh 3.7.4 $HOME/.bazel_python --with-openssl=$(brew --prefix openssl) +``` + ## Per-Project Usage 1. Add a `requirements.txt` with the pip requirements you need. 2. In your `WORKSPACE` add: diff --git a/setup_python.sh b/setup_python.sh index 80f2d37..e05c139 100755 --- a/setup_python.sh +++ b/setup_python.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ $# -ne 1 ] && [ $# -ne 2 ]; then +if [ $# -le 1 ]; then echo "This is $(basename $0). Usage:" echo "$(basename $0) [version] [/path/to/install/parent/directory] [python configure flags]" echo "Example:" @@ -38,6 +38,15 @@ then echo "If you have run this script multiple times, you may safely remove duplicate lines from $HOME/.bazelrc" echo "build --define BAZEL_PYTHON_DIR=$install_parent_dir" >> $HOME/.bazelrc echo "run --define BAZEL_PYTHON_DIR=$install_parent_dir" >> $HOME/.bazelrc + + if ! $install_dir/bin/python3 -c "import ssl" + then + echo "WARNING: Python was built *WITHOUT* the SSL module. This will break PyPI downloads. Please re-run this script after installing libssl-dev (see the README)." + fi + if ! $install_dir/bin/python3 -c "import zlib" + then + echo "WARNING: Python was built *WITHOUT* the zlib module. If needed, please re-run this script after installing zlib1g-dev (see the README)." + fi else echo "Aborting." fi |