From a49b2629b495b1019d5a86da73ece3efe72be76c Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Fri, 29 Jan 2021 10:30:09 -0500
Subject: [PATCH] Attempt a CircleCI macOS configuration

---
 .circleci/config.yml | 76 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 3 deletions(-)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index f0a4bc1..33a1f46 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -47,7 +47,76 @@ jobs:
           path: "docs/build"
           destination: "docs"
 
-  tests:
+  macos-tests:
+    macos:
+      xcode: "12.3.0"
+
+    steps:
+      - "checkout"
+
+      - restore_cache:
+          keys:
+          # when setup.cfg changes, use increasingly general patterns to
+          # restore cache
+          - pip-packages-v1-{{ .Branch }}-{{ checksum "setup.cfg" }}
+          - pip-packages-v1-{{ .Branch }}-
+          - pip-packages-v1-
+
+      - run:
+          name: "Get Pip"
+          command: |
+            # The CircleCI macOS environment has curl and Python 2.7 but does
+            # not have pip.  So, for starters, use curl and Python 2.7 to get
+            # pip.
+            curl https://bootstrap.pypa.io/2.7/get-pip.py -o get-pip.py
+            python2 get-pip.py
+
+      - run:
+          name: "Create Virtualenv"
+          command: |
+            # Now the CircleCI macOS Python 2 environment has some Python
+            # libraries in it which conflict with ZKAPAuthorizer's
+            # requirements.  So install virtualenv and use it to create an
+            # environment for ZKAPAuthorizer so it can have all its own
+            # versions of its dependencies.
+            /Users/distiller/Library/Python/2.7/bin/pip install virtualenv
+
+            # Make sure virtualenv creates a Python 2 environment!
+            virtualenv --python=python2 venv
+
+            # Get the newest pip we can because who knows what came along with
+            # that virtualenv.
+            venv/bin/pip install --upgrade pip
+
+      - run:
+          name: "Populate Wheelhouse"
+          command: |
+            # Get wheels for all the Python packages we depend on - either
+            # directly via the ZKAPAuthorizer distutils configuration *or*
+            # because some other tool depends on it.  For example, pip has a
+            # bunch of dependencies it is nice to have around, and using the
+            # wheels depends on the wheel package.
+            venv/bin/pip wheel --wheel-dir wheelhouse pip wheel .[test]
+
+      - save_cache:
+          paths:
+          - "wheelhouse"
+          key: pip-packages-v1-{{ .Branch }}-{{ checksum "setup.cfg" }}
+
+      - run:
+          name: "Install"
+          command: |
+            # Now we can install ZKAPAuthorizer and its dependencies and test
+            # dependencies into the environment.
+            venv/bin/pip install --no-index --find-links file://${PWD}/wheelhouse .[test]
+
+      - run:
+          name: "Test"
+          command: |
+            # And finally we can run the tests.
+            venv/bin/python -m twisted.trial _zkapauthorizer
+
+  linux-tests:
     docker:
       # Run in a highly Nix-capable environment.
       - image: "nixorg/nix:circleci"
@@ -142,5 +211,6 @@ workflows:
   version: 2
   everything:
     jobs:
-      - "documentation"
-      - "tests"
+      # - "documentation"
+      # - "linux-tests"
+      - "macos-tests"
-- 
GitLab