diff --git a/.gitignore b/.gitignore index 902c4dda6a8ec1d40ced27025ab609c9579edab4..b949e476d8a8c1a32d98228a5a1c944587e22b6f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ coverage/ # Ignore project temporary directory. tmp/ + +# Ignore Vagrant artifacts. +.vagrant \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000000000000000000000000000000000000..5194289b7ee5ee4536b8cac842551532ee667763 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,13 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + config.vm.box = "debian/contrib-stretch64" + config.vm.hostname = "gimmecert-testing" + + config.vm.provision "shell", path: "provision.sh" +end diff --git a/docs/development.rst b/docs/development.rst index dd9b6d54900d8c344066b6912ab1b703998e1d96..f486a6faad54e3a2733476de9a5118fcd98a5972 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -137,6 +137,44 @@ Tests can also be run using `tox `_: tox -e doc,lint +Running tests on all supproted Python versions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +With a range of different Python versions supported, it might be +somewhat difficult to run the tests against all the posible versions +of Python depending on distribution used for development. + +The projects comes with a `Vagrantfile `_ +to make this easier. To run all tests within a Vagrant machine, +perform the following steps: + +1. Go to project root directory:: + + workon gimmecert + +2. Bring up the Vagrant machine (this may take a while since it will + build the necessary Python versions):: + + vagrant up + +3. Log-in into the Vagrant machine:: + + vagrant ssh + +4. Change directory:: + + cd /vagrant + +5. Clean Python caches to ensure your main development machine files + do not interfere:: + + py3clean + +6. Run tests against all available environments:: + + tox + + Building documentation ---------------------- diff --git a/provision.sh b/provision.sh new file mode 100755 index 0000000000000000000000000000000000000000..d571e04032f87b2a79067cc9a613d7c4a1dfb77e --- /dev/null +++ b/provision.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# +# Provisioning script for the Vagrant test environment. Do not run +# outside of vagrant machine. +# + +# Fail as soon as a command fails. +set -e + +hostname=$(hostname) + +if [[ $hostname != "gimmecert-testing" ]]; then + echo "Script should only be run on Vagrant testing machine." + exit 1 +fi + +# Update apt caches. +apt-get update -qq + +# Install development tools. +apt-get install -qq -y git virtualenv + +# Install Python build dependencies. +apt-get install -qq -y make build-essential libssl1.0-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libffi-dev + +# Clone the pyenv and pyenv-virtualenv tools for setting-up multiple +# Python installations. +if [[ ! -e /home/vagrant/.pyenv ]]; then + sudo -i -u vagrant git clone https://github.com/pyenv/pyenv/ /home/vagrant/.pyenv +fi + +if [[ ! -e /home/vagrant/.pyenv/plugins/pyenv-virtualenv ]]; then + sudo -i -u vagrant git clone https://github.com/pyenv/pyenv-virtualenv.git /home/vagrant/.pyenv/plugins/pyenv-virtualenv +fi + +# Enable pyenv for the user. +bash_profile="/home/vagrant/.bash_profile" + +if [[ ! -e $bash_profile ]] || ! grep -q "export PYENV_ROOT" "$bash_profile"; then + echo 'export PYENV_ROOT="$HOME/.pyenv"' >> "$bash_profile" +fi + +if [[ ! -e $bash_profile ]] || ! grep -q "export PATH=" "$bash_profile"; then + echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> "$bash_profile" +fi + +if [[ ! -e $bash_profile ]] || ! grep -q 'pyenv init' "$bash_profile"; then + echo 'eval "$(pyenv init -)"' >> "$bash_profile" +fi + +chown vagrant:vagrant "$bash_profile" +chmod 0640 "$bash_profile" + +# List of Python versions to install. +python_versions=("3.4.9" "3.5.6" "3.6.7" "3.7.1") + +# Install various Python versions. +for python_version in "${python_versions[@]}"; do + sudo -i -u vagrant pyenv install -s "$python_version" +done + +# Register them globally. +sudo -i -u vagrant pyenv global system "${python_versions[@]}" + +# Set-up virtual environment for running tox. +if [[ ! -f /home/vagrant/virtualenv-tox/bin/activate ]]; then + sudo -i -u vagrant virtualenv --prompt '(tox) ' -q -p /usr/bin/python3 /home/vagrant/virtualenv-tox +fi + +if [[ ! -e $bash_profile ]] || ! grep -q "source /home/vagrant/virtualenv-tox/bin/activate" "$bash_profile"; then + echo 'source /home/vagrant/virtualenv-tox/bin/activate' >> "$bash_profile" +fi + +# Install development requirements. +sudo -i -u vagrant pip install -q -e "/vagrant[devel]"