Skip to content

Commit 25d7de1

Browse files
authored
Merge pull request #41 from LeastAuthority/support-python3
Support Python3, add NixOS 21.11 to CI, and build more wheels
2 parents 6e25af8 + 5a505ec commit 25d7de1

File tree

5 files changed

+167
-54
lines changed

5 files changed

+167
-54
lines changed

.circleci/config.yml

Lines changed: 148 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
version: 2.1
22

3-
jobs:
4-
package-macos:
3+
# Define executors that various packaging jobs need. This lets us make one
4+
# packaging job that accepts an executor parameter and avoids duplicating the
5+
# packaging steps.
6+
executors:
7+
manylinux-2014-x86_64:
8+
docker:
9+
- image: "quay.io/pypa/manylinux2014_x86_64"
10+
manylinux_2_24-x86_64:
11+
docker:
12+
- image: "quay.io/pypa/manylinux_2_24_x86_64"
13+
14+
# Define some custom commands that we can use as elements of `steps` in job
15+
# definitions.
16+
commands:
17+
build-wheel:
18+
description: "Build a Python wheel"
19+
520
parameters:
6-
xcode-version:
21+
python:
22+
description: "The path to the Python executable to use"
723
type: "string"
24+
default: "python3"
825

9-
macos:
10-
xcode: "<< parameters.xcode-version >>"
11-
12-
environment:
13-
# PyPI authentication configuration for twine so we can upload packages.
14-
# TWINE_PASSWORD is set in the CircleCI private configuration section.
15-
# In the CircleCI web app:
16-
#
17-
# Project Settings ->
18-
# Environment Variables ->
19-
# Add Environment Variable ->
20-
# Name: TWINE_PASSWORD
21-
# Value: <a token issued by PyPI>
22-
#
23-
# The PyPI token is issued in the PyPI web app:
24-
#
25-
# Manage ->
26-
# Settings ->
27-
# Create a token for ... ->
28-
# Permissions: Upload
29-
# Scope: Project: python-challenge-bypass-ristretto
30-
TWINE_USERNAME: "__token__"
26+
audit-wheel:
27+
description: "A boolean controlling whether the auditwheel tool is used to fix up the wheel"
28+
type: "boolean"
3129

3230
steps:
3331
- "checkout"
@@ -43,27 +41,69 @@ jobs:
4341
name: "Install Rust Build Toolchain"
4442
command: |
4543
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /tmp/rustup-init
46-
sh /tmp/rustup-init -y --default-toolchain stable
47-
. "$HOME"/.cargo/env
44+
for i in $(seq 10); do
45+
if sh /tmp/rustup-init -y --default-toolchain stable; then
46+
break
47+
else
48+
sleep 1
49+
fi
50+
done
51+
echo '. "$HOME"/.cargo/env' >> $BASH_ENV
4852
4953
- run:
5054
name: "Get Python Build/Package Dependencies"
5155
command: |
5256
# Make sure we have a pip that's aware of Python version constraints
53-
pip install --upgrade pip
57+
<< parameters.python >> -m pip install --upgrade pip
5458
# Pre-install these two setup_depends using pip so we don't have
5559
# to rely on whatever resolution logic setuptools would apply.
56-
pip install --upgrade milksnake setuptools_scm
57-
# And get these so we can build and then upload a wheel
58-
pip install wheel twine
60+
<< parameters.python >> -m pip install --upgrade milksnake setuptools_scm
61+
# And get these so we can build, fix, and upload a wheel.
62+
<< parameters.python >> -m pip install wheel auditwheel twine
5963
6064
- run:
6165
name: "Build Wheel"
6266
command: |
63-
python setup.py bdist_wheel
67+
<< parameters.python >> -m pip wheel --no-deps .
68+
69+
- when:
70+
condition: << parameters.audit-wheel >>
71+
steps:
72+
- run:
73+
name: "Audix / Fix Wheel"
74+
command: |
75+
# Since both macOS and Linux jobs re-use this step, make
76+
# sure we only try to use auditwheel on the appropriate
77+
# platform. That is, only on Linux.
78+
<< parameters.python >> -m auditwheel repair python_challenge_bypass_ristretto*.whl
79+
# Delete the original, unfixed wheel.
80+
rm *.whl
81+
# Move the fixed wheel here for consistency with the
82+
# non-manylinux case.
83+
mv wheelhouse/python_challenge_bypass_ristretto*.whl ./
6484
6585
- run:
6686
name: "Upload Wheel"
87+
environment:
88+
# PyPI authentication configuration for twine so we can upload
89+
# packages. TWINE_PASSWORD is set in the CircleCI private
90+
# configuration section. In the CircleCI web app:
91+
#
92+
# Project Settings ->
93+
# Environment Variables ->
94+
# Add Environment Variable ->
95+
# Name: TWINE_PASSWORD
96+
# Value: <a token issued by PyPI>
97+
#
98+
# The PyPI token is issued in the PyPI web app:
99+
#
100+
# Manage ->
101+
# Settings ->
102+
# Create a token for ... ->
103+
# Permissions: Upload
104+
# Scope: Project: python-challenge-bypass-ristretto
105+
TWINE_USERNAME: "__token__"
106+
67107
command: |
68108
if [[ "$CIRCLE_TAG" == v* ]]; then
69109
# We're building a release tag so we should probably really
@@ -76,9 +116,57 @@ jobs:
76116
repo="testpypi"
77117
TWINE_PASSWORD="$TWINE_TESTPYPI_PASSWORD"
78118
fi
79-
python -m twine upload --repository $repo dist/*
119+
<< parameters.python >> -m twine upload --repository $repo python_challenge_bypass_ristretto*.whl
120+
121+
# Define the actual jobs that will be available to run in a workflow.
122+
jobs:
123+
124+
# Build a manylinux wheel.
125+
package-manylinux:
126+
parameters:
127+
executor:
128+
# note the name comes from the `executors` section above
129+
description: "the name of the executor to use to run this job"
130+
type: "executor"
131+
132+
pre-command:
133+
description: |
134+
a command to run first which resolves any inconsistencies between
135+
the chosen executor and the requirements of this job
136+
type: "string"
137+
default: ""
138+
139+
python:
140+
description: "the path to the Python executable to use"
141+
type: "string"
142+
80143

81-
tests-353333: &TESTS
144+
executor: "<< parameters.executor >>"
145+
146+
steps:
147+
- run:
148+
name: "Prepare Execution Environment"
149+
command: |
150+
<< parameters.pre-command >>
151+
152+
- "build-wheel":
153+
python: "<< parameters.python >>"
154+
audit-wheel: true
155+
156+
package-macos:
157+
parameters:
158+
xcode-version:
159+
type: "string"
160+
161+
macos:
162+
xcode: "<< parameters.xcode-version >>"
163+
164+
steps:
165+
- "build-wheel":
166+
audit-wheel: false
167+
168+
169+
tests-template: &TESTS
82170
docker:
83171
# Run in a highly Nix-capable environment.
84172
- image: "nixorg/nix:circleci"
@@ -90,7 +178,7 @@ jobs:
90178
# time of this comment. We can bump it to a newer version when that
91179
# makes sense. Meanwhile, the platform won't shift around beneath us
92180
# unexpectedly.
93-
NIXPKGS_REV: "353333ef340952c05332e3c271dff953264cb017"
181+
NIXPKGS_REV: "XXX" # Set this in a derived environment.
94182

95183
steps:
96184
- run:
@@ -158,36 +246,48 @@ jobs:
158246
command: |
159247
./ci-tools/run-tests.sh
160248
161-
tests-1909:
162-
<<: *TESTS
163-
environment:
164-
NIXPKGS_REV: "19.09"
165-
166-
tests-2009:
249+
tests-2105:
167250
<<: *TESTS
168251
environment:
169-
NIXPKGS_REV: "20.09"
252+
NIXPKGS_REV: "21.05"
170253

171-
tests-2105:
254+
tests-2111:
172255
<<: *TESTS
173256
environment:
174-
NIXPKGS_REV: "21.05"
257+
NIXPKGS_REV: "21.11"
175258

176259
workflows:
177260
version: 2
178261
all-tests:
179262
jobs:
180-
- "tests-2009"
181263
- "tests-2105"
264+
- "tests-2111"
265+
- "package-manylinux":
266+
name: "package-manylinux-2014_x86_64"
267+
executor: "manylinux-2014-x86_64"
268+
# The image this executor uses comes with no ssh client. CircleCI
269+
# rewrites our git configuration to fetch sources over ssh. Then it
270+
# fails if we don't have any ssh client.
271+
pre-command: "yum install -y openssh-clients"
272+
python: "/opt/python/cp37-cp37m/bin/python"
273+
- "package-manylinux":
274+
name: "package-manylinux_2_24-x86_64"
275+
executor: "manylinux_2_24-x86_64"
276+
# Similar to the manylinux-2014_x86_64 case.
277+
pre-command: "apt-get update -y && apt-get install -y openssh-client"
278+
python: "/opt/python/cp37-cp37m/bin/python"
279+
182280
- "package-macos":
183281
matrix:
184282
parameters:
185283
# https://circleci.com/docs/2.0/testing-ios/#supported-xcode-versions
186284
xcode-version:
187-
# Latest macOS 10.14
285+
# Latest macOS 10.14.x
188286
- "11.1.0"
189-
# The newest macOS 10.15 that still has Python 2. :/
190-
- "11.4.1"
287+
# Latest macOS 10.15.x
288+
- "12.4.0"
289+
# Latest macOS 11.x
290+
- "13.2.1"
191291
filters:
192292
# CircleCI does not run workflows for tags unless you explicitly
193293
# specify tag filters. Additionally, if a job requires any other

challenge_bypass_ristretto/tests/test_privacypass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def test_serialization_roundtrip(self, token, signing_key):
395395

396396

397397
# The signature uses sha512.
398-
SIG_SIZE = 512 / 8
398+
SIG_SIZE = 512 // 8
399399
def verification_signatures():
400400
"""
401401
Strategy that builds byte strings that are the right length to be

ci-tools/run-tests.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22

33
set -euxo pipefail
44

5-
# Run the ffi binding tests
6-
nix-build -A tests --out-link ffi-tests challenge-bypass-ristretto.nix
5+
# On CI, explicitly pass a value for nixpkgs so that the build respects the
6+
# nixpkgs revision CI is trying to test. Otherwise, accept the default
7+
# nixpkgs defined by the packaging expressions.
8+
if [ -v CI ]; then
9+
pkgsArg=(--arg pkgs "import <nixpkgs> {}")
10+
else
11+
pkgsArg=()
12+
fi
13+
14+
# Run the ffi binding tests.
15+
nix-build \
16+
-A tests \
17+
--out-link ffi-tests \
18+
"${pkgsArg[@]}" \
19+
challenge-bypass-ristretto.nix
720

821
# Build the Python package itself
9-
nix-build --out-link result
22+
nix-build --out-link result "${pkgsArg[@]}"
1023

1124
# Run what passes for the test suite for our Python code, too. It would be
1225
# nice to put this into a tests attribute on the Python package derivation,

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ in
1010
, challenge-bypass-ristretto-ffi-repo ? sources.challenge-bypass-ristretto-ffi
1111
, challenge-bypass-ristretto-ffi ? pkgs.callPackage ./challenge-bypass-ristretto.nix { inherit challenge-bypass-ristretto-ffi-repo; }
1212
# Choose the Python runtime for which we're building
13-
, pythonPackages ? pkgs.python27Packages
13+
, pythonPackages ? pkgs.python39Packages
1414
}:
1515
# Build our Python bindings in the usual way, supplying the necessary extra
1616
# dependency.

shell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let
22
sources = import nix/sources.nix;
33
in
44
{ pkgs ? import sources.nixpkgs { }
5-
, python ? pkgs.python2
5+
, python ? pkgs.python39
66
}:
77
let
88
challenge-bypass-ristretto-ffi = pkgs.callPackage ./challenge-bypass-ristretto.nix {

0 commit comments

Comments
 (0)