Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e8cf735
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:36:16 2019 -0700

    Trusty Py34 is from system, not pyenv

commit 1f7d236
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:30:08 2019 -0700

    OSX requires language: general

commit 4941956
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:23:28 2019 -0700

    Move constant to top of file

    Think this is the style used in most Python projects and ours.

commit c478ecb
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:19:29 2019 -0700

    Set Pyenv for Trusty

commit 30aab56
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:16:58 2019 -0700

    Try pyenv approach

    Path wrangling didn't work.

commit 9b9e6be
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:12:11 2019 -0700

    Global python entry -> build matrix

    See if moving back to osx_setup and linux_setup works.

commit 0dc87dc
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:09:18 2019 -0700

    Maybe fix Trusty using Py3.4

commit aaab4bf
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:05:50 2019 -0700

    Test if OSX comes pre-installed with Python?

commit 96cb6ac
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:02:44 2019 -0700

    Remove unneeded anchors from OSX shards

    Turns out Precise comes installed with 3.6 when requested! So we only need Pyenv for OSX, not Linux.

commit 4a312a4
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 09:01:31 2019 -0700

    Try to debug Trusty image using Py3.4

commit d511d99
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 08:48:28 2019 -0700

    Remove stray whitespace

commit 126ae2f
Merge: cd28677 4aee51a
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 08:47:56 2019 -0700

    Merge branch 'gh-pages' of github.com:pantsbuild/setup into ci-py

commit 4aee51a
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 08:46:38 2019 -0700

    Test Ubuntu Xenial (pantsbuild#31)

    Travis added Xenial back in November. See https://blog.travis-ci.com/2018-11-08-xenial-release.

    Adding this test results in better coverage.

commit cd28677
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 08:36:55 2019 -0700

    Add  prefix to script. Oops

commit 4afcdcf
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 08:24:43 2019 -0700

    Add comment explaining why we rewrite pants.ini like this

commit ef5bf71
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 08:22:55 2019 -0700

    Tweak ci.py formatting

commit 599ae46
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 08:19:38 2019 -0700

    Try to install Py36 on each shard

    Also modernize .travis.yml to use all the cool goodies we've learned in Pants's CI like anchors and the brew addon package!

commit 717271f
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 07:50:10 2019 -0700

    Remove PythonVersion and fix --pants-version unspecified

    --pants-version unspecified would fail because of a bad config, that the contrib module would refer to pants_version even though that line was deleted.

commit d1f9f0f
Author: Eric Arellano <ericarellano@me.com>
Date:   Tue Mar 12 07:40:38 2019 -0700

    Add ci.py to CI to allow parameterizing pants_version and python_version
  • Loading branch information
Eric-Arellano committed Mar 12, 2019
1 parent 5531a2b commit 4d2791a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 33 deletions.
67 changes: 49 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,75 @@
language: python
python: "2.7.13"

# Needed to enable Travis CI for gh-pages branches, see:
# https://github.com/travis-ci/travis-core/pull/137
branches:
only:
- gh-pages

script:
- ci.py --pants-version unspecified --python-version unspecified
- ci.py --pants-version unspecified --python-version 2.7
- ci.py --pants-version unspecified --python-version 3.6
- ci.py --pants-version pants.ini --python-version unspecified
- ci.py --pants-version pants.ini --python-version 2.7
- ci.py --pants-version pants.ini --python-version 3.6
- ./ci.py --pants-version unspecified --python-version unspecified
- ./ci.py --pants-version unspecified --python-version 2.7
- ./ci.py --pants-version unspecified --python-version 3.6
- ./ci.py --pants-version pants.ini --python-version unspecified
- ./ci.py --pants-version pants.ini --python-version 2.7
- ./ci.py --pants-version pants.ini --python-version 3.6

osx_setup: &osx_setup
os: osx
language: generic
addons:
brew:
packages:
- openssl
env:
- >
PYENV_ROOT="${HOME}/.pyenv"
PATH="${PYENV_ROOT}/shims:${PATH}"
- >
# These flags are necessary to get OpenSSL working. See
# https://github.com/pyenv/pyenv/wiki/Common-build-problems#error-the-python-ssl-extension-was-not-compiled-missing-the-openssl-lib.
PATH="/usr/local/opt/openssl/bin:$PATH"
LDFLAGS="-L/usr/local/opt/openssl/lib"
CPPFLAGS="-I/usr/local/opt/openssl/include"
before_install:
- >
git clone https://github.com/pyenv/pyenv ${PYENV_ROOT}
&& ${PYENV_ROOT}/bin/pyenv install 3.6.8
&& ${PYENV_ROOT}/bin/pyenv global 3.6.8
linux_setup: &linux_setup
os: linux
sudo: false
language: python
python:
- "2.7"
- "3.6"

matrix:
include:
- name: "OSX 10.11 - El Capitan"
os: osx
<<: *osx_setup
osx_image: xcode8.0
language: generic

- name: "OSX 10.12 - Sierra"
os: osx
<<: *osx_setup
osx_image: xcode9.2
language: generic

- name: "OSX 10.13 - High Sierra"
os: osx
<<: *osx_setup
osx_image: xcode9.4
language: generic

- name: "Ubuntu 12.04 - Precise"
os: linux
<<: *linux_setup
dist: precise
sudo: required

- name: "Ubuntu 14.04 - Trusty"
os: linux
<<: *linux_setup
dist: trusty
sudo: false
before_install:
# NB: Trusty image comes with system Python 3.4, but we require 3.6+.
# Use pyenv global to ensure we use 2.7 and 3.6, not 3.4.
- pyenv global 2.7.14 3.6.3

- name: "Ubuntu 16.04 - Xenial"
<<: *linux_setup
dist: xenial
28 changes: 13 additions & 15 deletions ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from enum import Enum


PANTS_INI = 'pants.ini'


class PantsVersion(Enum):
unspecified = "unspecified"
pants_ini = "pants.ini"
Expand All @@ -27,18 +30,13 @@ def __str__(self):
return self.value


PANTS_INI = 'pants.ini'


def main() -> None:
args = create_parser().parse_args()
run_tests(pants_version=args.pants_version, python_version=args.python_version)


def create_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Utility to run CI for the setup repo."
)
parser = argparse.ArgumentParser(description="Utility to run CI for the setup repo.")
parser.add_argument(
"--pants-version",
action="store",
Expand Down Expand Up @@ -75,26 +73,26 @@ def run_tests(*, pants_version: PantsVersion, python_version: PythonVersion) ->

@contextmanager
def setup_pants_version(pants_version: PantsVersion):
"""Modify pants.ini to allow the pants version to be unspecified or what it originally was in pants.ini."""
"""Modify pants.ini to allow the pants version to be unspecified or keep what was originally there."""
with open(PANTS_INI, 'r') as f:
original_pants_ini = list(f.readlines())
pants_version_line_index = next(
(i for i, line in enumerate(original_pants_ini) if line.startswith("pants_version:")),
None
)
if pants_version == PantsVersion.pants_ini and pants_version_line_index is None:
pants_version_specified = any(line.startswith("pants_version:") for line in original_pants_ini)
if pants_version == PantsVersion.pants_ini and not pants_version_specified:
raise ValueError("You requested to use the pants_version from pants.ini for this test, but pants.ini "
"does not include a pants_version! Please update pants.ini and run again.")
if pants_version == PantsVersion.unspecified and pants_version_line_index is not None:
if pants_version == PantsVersion.unspecified and pants_version_specified:
with open(PANTS_INI, 'w') as f:
f.writelines(line for i, line in enumerate(original_pants_ini) if i != pants_version_line_index)
# NB: we must not only remove the original definition of `pants_version`, but also
# any lines that make use of it, such as contrib packages pinning their version to `pants_version`.
f.writelines(line for line in original_pants_ini if "pants_version" not in line)
yield
with open(PANTS_INI, 'w') as f:
f.writelines(original_pants_ini)
f.writelines(original_pants_ini)


@contextmanager
def setup_python_version(python_version: PythonVersion):
"""Set $PYTHON env var to a specific Python version or keep unspecified for default behavior."""
# TODO: modify this test to change pants.ini like we do in setup_pants_version!
# Right now we are only testing that the virtual environment resolves properly, and
# can't yet test that we parse pants.ini correctly until https://github.com/pantsbuild/pants/pull/7363
Expand Down

0 comments on commit 4d2791a

Please sign in to comment.