Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Python 3 #278

Merged
merged 60 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
bede3e7
bump to the now-current nixpkgs release
exarkun Dec 27, 2021
96e4c46
parameterize python version in the nix package
exarkun Dec 27, 2021
22b0a17
fix problem with the new collections-extended dependency
exarkun Dec 27, 2021
d844ded
fix problem with the new cryptography build system
exarkun Dec 27, 2021
5bfcb79
fix the new conditional foolscap dependency
exarkun Dec 27, 2021
b3bacf4
update the pypi database to get fresh-enough versions
exarkun Dec 27, 2021
b7f22fc
add source for the now-current nixos release
exarkun Dec 27, 2021
013d873
bump the shell environment nixos release as well
exarkun Dec 27, 2021
cd120f3
respect the chosen python version in the tests and lint tools
exarkun Dec 27, 2021
0a0fe9d
nope, use python39 for lint because tools are missing from py27 ecosy…
exarkun Dec 27, 2021
96137fe
switch to flake8 to be able to suppress warnings
exarkun Dec 27, 2021
244cc32
switch from the nixos release tag to branch
exarkun Dec 27, 2021
86a8aa1
fix nixpkgs pkgconfig so mach-nix works at all
exarkun Dec 27, 2021
2bd1f45
initial porting changes
exarkun Dec 27, 2021
fc5684e
black
exarkun Dec 27, 2021
ed8e0a0
isort
exarkun Dec 27, 2021
c123df9
add python3.9 to the ci testing matrix
exarkun Dec 27, 2021
f296f9e
fix all the noqa comments
exarkun Dec 27, 2021
71658b3
more packaging fixes
exarkun Dec 31, 2021
4b5824b
changes for a passing test suite on 2.7 and 3.8
exarkun Dec 31, 2021
890e67d
add a test for using the test vector feature
exarkun Jan 4, 2022
4dc239c
provide a shell where we can run tests, not just linters
exarkun Jan 5, 2022
61dc80d
strip explicit Python 2 support from the Nix packaging
exarkun Jan 5, 2022
4c29995
Drop Python 2 from the CI matrix
exarkun Jan 5, 2022
bf7c312
commit to Python 3 for json.dumps
exarkun Jan 5, 2022
36667f6
drop __future__ and future imports
exarkun Jan 5, 2022
11a5df5
remove six and future dependency, also isort and black
exarkun Jan 5, 2022
0e489fa
update packaging metadata
exarkun Jan 5, 2022
2c88272
Merge remote-tracking branch 'origin/main' into python3
exarkun Jan 5, 2022
aab21d0
drop py27 support from macos ci
exarkun Jan 5, 2022
a990635
parameterize python version in nixos ci
exarkun Jan 5, 2022
11b4cc2
drop our copy of some eliot functions that we can now use from upstream
exarkun Jan 5, 2022
ec1bf28
switch GitHub Actions to Python 3.9 as well
exarkun Jan 5, 2022
ba62031
incompatible version formats ...
exarkun Jan 5, 2022
adf0b03
maybe this runs the configs I want
exarkun Jan 5, 2022
a24eeee
nope, how about this
exarkun Jan 5, 2022
9ce11d0
spurious mapping
exarkun Jan 5, 2022
9936c1f
normalize the CircleCI job names
exarkun Jan 5, 2022
cc70a9c
Drop the workaround for the problem with older prometheus_client
exarkun Jan 5, 2022
a8225b0
let setrlimit fail :/
exarkun Jan 5, 2022
6d098bc
Add a test for `get_root_nodes` and fix the implementation
exarkun Jan 5, 2022
1f134f9
match the exact expected length
exarkun Jan 8, 2022
5d2670e
more general reasoning about special cases for provider choices
exarkun Jan 8, 2022
46fa124
replace typing comments with syntax
exarkun Jan 8, 2022
f6591cb
base64 encoded tokens are always ascii
exarkun Jan 8, 2022
92ba74c
required_passes is content with dict_values now
exarkun Jan 8, 2022
c621b05
use f"" to simplify some string construction
exarkun Jan 8, 2022
ea07a48
cleanup stray keystroke
exarkun Jan 8, 2022
f7f0c93
Use FilePath instead of os.path
exarkun Jan 8, 2022
14956bf
get rid of past.builtins.long usage
exarkun Jan 8, 2022
34e05c2
drop the silly decode/encode dance for all the binding messages
exarkun Jan 8, 2022
22b0014
fixup comment in new test
exarkun Jan 8, 2022
1ebff29
Use auto_attribus on a couple exception types
exarkun Jan 8, 2022
67072ba
Compare dict keys directly instead of via a set conversion
exarkun Jan 8, 2022
39985b1
It's already a text-mode FilePath, right?
exarkun Jan 8, 2022
4ddd84c
Pin Tahoe-LAFS exactly because we use an unofficial/unstable interface
exarkun Jan 8, 2022
4f59ff8
widen the required range to allow the Nix package
exarkun Jan 9, 2022
209c83c
link to twisted tickets related to this
exarkun Jan 11, 2022
7581149
Use __future__.annotations
exarkun Jan 11, 2022
cb771a9
remove one more unnecessary asBytesMode call
exarkun Jan 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@ jobs:
- run:
name: "Get Pip"
command: |
# The CircleCI macOS environment has curl and Python but does not
# have pip. So, for starters, use curl and Python to get pip.
if [ "<< parameters.py-version >>" == "2.7" ]; then

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
else
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
fi
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python<< parameters.py-version >> get-pip.py

- run:
Expand Down Expand Up @@ -136,6 +129,8 @@ jobs:

linux-tests: &LINUX_TESTS
parameters:
py-version:
type: "string"
tahoe-lafs-source:
# The name of a niv source in nix/sources.json which corresponds to
# a Tahoe-LAFS version. This is the version that will be declared as a
Expand Down Expand Up @@ -209,7 +204,8 @@ jobs:
nix-build tests.nix \
--argstr hypothesisProfile ci \
--arg collectCoverage true \
--argstr tahoe-lafs-source << parameters.tahoe-lafs-source >>
--argstr tahoe-lafs-source << parameters.tahoe-lafs-source >> \
--argstr python python<< parameters.py-version >>

- run:
name: "Push to Cachix"
Expand Down Expand Up @@ -241,18 +237,17 @@ workflows:
jobs:
- "documentation"
- "linux-tests":
matrix:
parameters:
tahoe-lafs-source:
- "tahoe-lafs"
name: "Linux tests python 3.9"
py-version: "39"
tahoe-lafs-source: "tahoe-lafs"

# https://circleci.com/docs/2.0/testing-ios/#supported-xcode-versions
- "macos-tests":
name: "macOS tests python 3.8 xcode 11.7.0"
py-version: "3.8"
xcode-version: "11.7.0"

- "macos-tests":
matrix:
parameters:
py-version:
- "2.7"

xcode-version:
# https://circleci.com/docs/2.0/testing-ios/#supported-xcode-versions
- "12.3.0"
- "11.7.0"
name: "macOS tests python 3.9 xcode 12.3.0"
py-version: "3.9"
xcode-version: "12.3.0"
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
python-version:
- "2.7"
- "3.9"

steps:
# Avoid letting Windows newlines confusing milksnake.
Expand Down
39 changes: 33 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
let
sources = import nix/sources.nix;
in
{ pkgs ? import sources.release2105 {}
{ pkgs ? import sources.release2111 { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we pass in release 2105 in PrivateStorageio, I don't think we should be making this change here (at least not without also testing 2105 in CI for the moment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be easier to advance to 21.11 in PrivateStorageio than to back this up to 21.05. There are some build failures in our dependencies on 21.05 that aren't interesting in any way once we're up to 21.11 and will be annoying to fix. Since ZKAPAuthorizer is supplying Tahoe-LAFS, the fact that everything is working on 21.11 seems like a pretty strong signal that upgrading PrivateStorageio to 21.11 (at least for Tahoe-LAFS/ZKAPAuthorizer) will be straightforward. Although it is true I haven't really tried it out yet. I could do that before committing to this upgrade to confirm that is going to be the easier path.

, pypiData ? sources.pypi-deps-db
, mach-nix ? import sources.mach-nix { inherit pkgs pypiData; }
, python ? "python39"
, mach-nix ? import sources.mach-nix { inherit pkgs pypiData python; }
, tahoe-lafs-source ? "tahoe-lafs"
, tahoe-lafs-repo ? sources.${tahoe-lafs-source}
, ...
}:
let
lib = pkgs.lib;
python = "python27";
providers = {
_default = "sdist,nixpkgs,wheel";

# mach-nix doesn't provide a good way to depend on mach-nix packages,
# so we get it as a nixpkgs dependency from an overlay. See below for
# details.
Expand All @@ -34,6 +36,22 @@ in
# The version of Klein we get doesn't need / can't have the patch that
# comes from the nixpkgs derivation mach-nix picks up from 21.05.
klein = "wheel";

# - has an undetected poetry dependency and when trying to work around
# this another way, dependencies have undetected dependencies, easier
# to just use the wheel.
collections-extended = "wheel";
# same as collections-extended
exarkun marked this conversation as resolved.
Show resolved Hide resolved
isort = "wheel";

# From nixpkgs or sdist, fails with
# cp: cannot stat 'benchmark/': No such file or directory
# cp: cannot stat 'tests/': No such file or directory
tomli = "wheel";

# repo re-org or something?
# find: ‘hypothesis-6.32.1/hypothesis-python’: No such file or directory
hypothesis = "wheel";
exarkun marked this conversation as resolved.
Show resolved Hide resolved
};
in
rec {
Expand All @@ -52,12 +70,21 @@ in
# going on and discover the real version specified by `src` below.
version = "1.17.0.post999";
# See https://github.com/DavHau/mach-nix/issues/190
requirementsExtra = ''
requirementsExtra =
''
# See https://github.com/DavHau/mach-nix/issues/190
pyrsistent < 0.17
foolscap == 0.13.1
configparser
eliot
'';
foolscap >= 21.7.0

# undetected cryptography build dependency
# https://github.com/DavHau/mach-nix/issues/305
setuptools_rust
# undetected tomli build dependency
# probably same underlying cause as cryptography issue
flit_core
'';
postPatch = ''
cat > src/allmydata/_version.py <<EOF
# This _version.py is generated by nix.
Expand Down
18 changes: 15 additions & 3 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"homepage": "",
"owner": "DavHau",
"repo": "pypi-deps-db",
"rev": "96d01556b4597c022647acbf8c3b58d2a99bc963",
"sha256": "0s6ll2hi40gj6mp2zdg7w3dq17g381gnfkm390mqgp574lmbq6yw",
"rev": "856d67ab093a68425c3896ec2961cea3b95ae93f",
"sha256": "0a7avm4xvm454gxy4dq0fc19j3f9ik8gf3kjpsqhszfkamrn9y0p",
"type": "tarball",
"url": "https://github.com/DavHau/pypi-deps-db/archive/96d01556b4597c022647acbf8c3b58d2a99bc963.tar.gz",
"url": "https://github.com/DavHau/pypi-deps-db/archive/856d67ab093a68425c3896ec2961cea3b95ae93f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"release2105": {
Expand All @@ -41,6 +41,18 @@
"url": "https://releases.nixos.org/nixos/21.05/nixos-21.05.3740.ce7a1190a0f/nixexprs.tar.xz",
"url_template": "https://releases.nixos.org/nixos/21.05/nixos-21.05.3740.ce7a1190a0f/nixexprs.tar.xz"
},
"release2111": {
"branch": "release-21.11",
"description": "Nix Packages collection",
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d887ac7aee92e8fc54dde9060d60d927afae9d69",
"sha256": "1bpgfv45b1yvrgpwdgc4fm4a6sav198yd41bsrvlmm3jn2wi6qx5",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/d887ac7aee92e8fc54dde9060d60d927afae9d69.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"tahoe-lafs": {
"branch": "master",
"description": "The Tahoe-LAFS decentralized secure filesystem.",
Expand Down
13 changes: 10 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ keywords = tahoe-lafs, storage, privacy, cryptography
license = Apache 2.0
classifiers =
Framework :: Twisted
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.9
author = PrivateStorage.io, LLC
maintainer = PrivateStorage.io, LLC
home-page = https://privatestorage.io/
Expand All @@ -34,7 +34,7 @@ packages =
install_requires =
attrs
zope.interface
eliot
eliot >= 1.11,<2
aniso8601
python-challenge-bypass-ristretto
# The pip resolver sometimes finds treq's dependencies first and these are
Expand All @@ -55,3 +55,10 @@ install_requires =

[options.extras_require]
test = coverage; fixtures; testtools; hypothesis

[flake8]
# Enforce all pyflakes constraints, and also prohibit tabs for indentation.
# Reference:
# https://flake8.pycqa.org/en/latest/user/error-codes.html
# https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
select = F, W191
30 changes: 26 additions & 4 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@
{ ... }@args:
let
tests = import ./tests.nix args;
inherit (tests) pkgs;
inherit (tests) privatestorage lint-python;
inherit (privatestorage) pkgs mach-nix tahoe-lafs zkapauthorizer;

python-env = mach-nix.mkPython {
inherit (zkapauthorizer.meta.mach-nix) python providers;
overridesPre = [
(
self: super: {
inherit tahoe-lafs;
}
)
];
requirements =
''
${builtins.readFile ./requirements/test.in}
${zkapauthorizer.requirements}
'';
};
in
pkgs.mkShell {
# Avoid leaving .pyc all over the source tree when manually triggering tests
# runs.
PYTHONDONTWRITEBYTECODE = "1";

buildInputs = [
tests.python
tests.lint-python
pkgs.niv
# Provide the linting tools for interactive usage.
lint-python
exarkun marked this conversation as resolved.
Show resolved Hide resolved
# Supply all of the runtime and testing dependencies.
python-env
];
}
2 changes: 0 additions & 2 deletions src/_zkapauthorizer/_base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
This module implements base64 encoding-related functionality.
"""

from __future__ import absolute_import

from base64 import b64decode as _b64decode
from binascii import Error
from re import compile as _compile
Expand Down
23 changes: 23 additions & 0 deletions src/_zkapauthorizer/_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2022 PrivateStorage.io, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from json import dumps as _dumps
from typing import Any


def dumps_utf8(o: Any) -> bytes:
"""
Serialize an object to a UTF-8-encoded JSON byte string.
"""
return _dumps(o).encode("utf-8")
21 changes: 9 additions & 12 deletions src/_zkapauthorizer/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,15 @@
Tahoe-LAFS.
"""

from __future__ import absolute_import

import random
from datetime import datetime
from functools import partial
from typing import Callable, List
from weakref import WeakValueDictionary

try:
from typing import Callable
except ImportError:
pass

import attr
from allmydata.client import _Client
from allmydata.interfaces import IAnnounceableStorageServer, IFoolscapStoragePlugin
from allmydata.interfaces import IAnnounceableStorageServer, IFoolscapStoragePlugin, IFilesystemNode
from allmydata.node import MissingConfigEntry
from challenge_bypass_ristretto import PublicKey, SigningKey
from eliot import start_action
Expand Down Expand Up @@ -291,7 +285,7 @@ def get_now():
get_now=get_now,
)
last_run_path = FilePath(
node_config.get_private_path(b"last-lease-maintenance-run")
node_config.get_private_path(u"last-lease-maintenance-run")
)
# Create the service to periodically run the lease maintenance operation.
return lease_maintenance_service(
Expand All @@ -303,13 +297,16 @@ def get_now():
)


def get_root_nodes(client_node, node_config):
def get_root_nodes(client_node, node_config) -> List[IFilesystemNode]:
"""
Get the configured starting points for lease maintenance traversal.
"""
try:
rootcap = node_config.get_private_config(b"rootcap")
rootcap = node_config.get_private_config("rootcap")
except MissingConfigEntry:
return []
else:
return [client_node.create_node_from_uri(rootcap)]
return [client_node.create_node_from_uri(rootcap.encode("utf-8"))]


def load_signing_key(path):
Expand Down
13 changes: 9 additions & 4 deletions src/_zkapauthorizer/_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def less_limited_stack():
More precisely, the soft stack limit is raised to the hard limit.
"""
soft, hard = getrlimit(RLIMIT_STACK)
# We can raise the soft limit to the hard limit and no higher.
setrlimit(RLIMIT_STACK, (hard, hard))
yield
setrlimit(RLIMIT_STACK, (soft, hard))
try:
# We can raise the soft limit to the hard limit and no higher.
setrlimit(RLIMIT_STACK, (hard, hard))
except ValueError:
# Well, not on macOS: https://bugs.python.org/issue34602
yield
else:
yield
setrlimit(RLIMIT_STACK, (soft, hard))
Loading