Skip to content

Commit

Permalink
Drop support for python 2
Browse files Browse the repository at this point in the history
Don't make broad, disruptive changes for now, but disallow python 2 in
./configure, adjust the docs, and remove code where it's unlikely to
cause conflicts with other pending changes.

Signed-off-by: Rob Browning <[email protected]>
Tested-by: Rob Browning <[email protected]>
  • Loading branch information
rlbdv committed Jan 16, 2022
1 parent 6b3ca3b commit c8af075
Show file tree
Hide file tree
Showing 20 changed files with 127 additions and 573 deletions.
53 changes: 5 additions & 48 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@

task:
name: debian (py2 check/lint root)
container:
image: debian:buster
cpu: 4
memory: 2
script: |
set -xe
dev/prep-for-debianish-build python2
dev/system-info
BUP_PYTHON_CONFIG=python2.7-config ./configure --with-pylint=yes
make -j6 check
task:
name: debian (py2 long-check)
container:
image: debian:buster
cpu: 4
memory: 2
script: |
set -xe
dev/prep-for-debianish-build python2
dev/system-info
adduser --disabled-password --gecos '' bup
chown -R bup:bup .
printf "make -j6 -C %q BUP_PYTHON_CONFIG=python2.7-config long-check" \
"$(pwd)" | su -l bup
task:
name: debian (py2 check)
container:
image: debian:buster
cpu: 4
memory: 2
script: |
set -xe
dev/prep-for-debianish-build python2
dev/system-info
adduser --disabled-password --gecos '' bup
chown -R bup:bup .
printf "make -j6 -C %q BUP_PYTHON_CONFIG=python2.7-config check" \
"$(pwd)" | su -l bup
task:
name: debian (py3 check/lint root)
name: debian check/lint root
container:
image: debian:buster
cpu: 4
Expand All @@ -56,7 +13,7 @@ task:
make -j6 check
task:
name: debian (py3 long-check)
name: debian long-check
container:
image: debian:buster
cpu: 4
Expand All @@ -71,7 +28,7 @@ task:
"$(pwd)" | su -l bup
task:
name: debian (py3 check)
name: debian check
container:
image: debian:buster
cpu: 4
Expand All @@ -86,7 +43,7 @@ task:
"$(pwd)" | su -l bup
task:
name: freebsd (py3 check)
name: freebsd check
freebsd_instance:
image: freebsd-12-2-release-amd64
cpu: 4
Expand All @@ -98,7 +55,7 @@ task:
BUP_PYTHON_CONFIG=python3.8-config make -j6 check
task:
name: macos (py3 check)
name: macos check
osx_instance:
image: catalina-base
script: |
Expand Down
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*-conf-*-
[GENERAL OPTIONS]
ignore=py2raise.py

[MESSAGES CONTROL]
disable=all
Expand Down
54 changes: 0 additions & 54 deletions CODINGSTYLE
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,3 @@ blank line in between). Here's an example from

Module-level docstrings follow exactly the same guidelines but without the
blank line between the summary and the details.


Exception Handling
------------------

Avoid finally: blocks in favor of explict catches because a throw
from a finally block will lose any pending exception. An explicit
catch can chain it (see below).

To behave similarly under Python 2 and 3, use add_ex_tb() to
explicitly add stack traces to any exceptions that are going to be
re-raised by anything other than a no-argument raise (otherwise the
stack trace will be lost)::

try:
...
except ... as ex:
add_ex_tb(ex)
pending_ex = ex
...
raise pending_ex

When an exception is thrown from an exception handler, the pending
exception should be the `"context"
<https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement>`_
of the new exception, which can be accomplished (portably) via
``pending_raise()``::

try:
...
except ... as ex:
with pending_raise(ex):
clean_up()

This should do roughly the same thing in Python 2 and Python 3,
throwing any exception from ``clean_up()`` after adding ex as the
``__context__`` if clean_up() throws, and throwing ``ex`` otherwise.

If for some reason, you need more control, you can use
``add_ex_ctx()`` directly::

try:
...
except ... as ex:
add_ex_tb(ex)
try:
...
except ... as ex2:
add_ex_tb(ex2)
raise add_ex_ctx(ex2, ex)
raise

See the end of ``lib/bup/compat.py`` for a functional example, and all
of this can be removed once we drop support for Python 2.
2 changes: 1 addition & 1 deletion Documentation/bup-import-duplicity.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Since all invocations of duplicity use a temporary `--archive-dir`,

Part of the `bup`(1) suite.

[mkdtemp]: https://docs.python.org/2/library/tempfile.html#tempfile.mkdtemp
[mkdtemp]: https://docs.python.org/3/library/tempfile.html#tempfile.mkdtemp
9 changes: 1 addition & 8 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,9 @@ long-test: test
long-check: export BUP_TEST_LEVEL=11
long-check: check

.PHONY: check-py2 check-py3 check-both
.PHONY: check-py3
check-py3:
$(MAKE) clean && BUP_PYTHON_CONFIG=python3-config $(MAKE) check
check-py2:
$(MAKE) clean && BUP_PYTHON_CONFIG=python2.7-config $(MAKE) check
check-both:
$(MAKE) check-py3
$(MAKE) check-py2

.PHONY: Documentation/all
Documentation/all: $(man_roff) $(man_html)
Expand Down Expand Up @@ -300,7 +295,5 @@ clean: Documentation/clean
rm -rf $(clean_paths) .pytest_cache
rm -f $(generated_dependencies)
find . -name __pycache__ -exec rm -rf {} +
# Remove this *.pyc cleanup once we drop py2
rm -f lib/bup/*.pyc lib/bup/cmd/*.pyc test/__init__.pyc
if test -e test/tmp; then dev/force-delete test/tmp; fi
dev/configure-sampledata --clean
41 changes: 6 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ Reasons you might want to avoid bup
more likely to eat your data. It's also missing some
probably-critical features, though fewer than it used to be.

- It requires python 3.7 or newer (or 2.7 for a bit longer), a C
compiler, and an installed git version >= 1.5.6. It also requires
par2 if you want fsck to be able to generate the information needed
to recover from some types of corruption. While python 2.7 is
still supported, please make plans to upgrade. Python 2 upstream
support ended on 2020-01-01, and we plan to drop support soon too.
- It requires python 3.7 or newer, a C compiler, and an installed git
version >= 1.5.6. It also requires par2 if you want fsck to be
able to generate the information needed to recover from some types
of corruption.

- It currently only works on Linux, FreeBSD, NetBSD, OS X >= 10.4,
Solaris, or Windows (with Cygwin, and WSL). Patches to support
Expand Down Expand Up @@ -159,33 +157,6 @@ From source
apt-get install python3-tornado # optional (bup web)
```
Or, if you can't yet migrate to Python 3 (please try to soon):

```sh
apt-get install python2.7-dev python-fuse
apt-get install python-pyxattr python-pytest
apt-get install pkg-config linux-libc-dev libacl1-dev
apt-get install gcc make acl attr rsync
apt-get isntall python-pytest-xdist # optional (parallel tests)
apt-get install par2 # optional (error correction)
apt-get install libreadline-dev # optional (bup ftp)
apt-get install python-tornado # optional (bup web)
```

On CentOS (for CentOS 6, at least), this should be sufficient (run
as root):

```sh
yum groupinstall "Development Tools"
yum install python2 python2-devel libacl-devel pylibacl
yum install fuse-python pyxattr
yum install perl-Time-HiRes
yum install readline-devel # optional (bup ftp)
yum install python-tornado # optional (bup web)
```

In addition to the default CentOS repositories, you may need to add
RPMForge (for fuse-python) and EPEL (for pyxattr).
On Cygwin, install python, make, rsync, and gcc4.
Expand Down Expand Up @@ -599,8 +570,8 @@ mailing list (see below) if you'd like to help.
__setitem__, and __setslice__ [3].

[1] http://comments.gmane.org/gmane.comp.sysutils.backup.bup/613
[2] http://docs.python.org/2/library/mmap.html
[3] http://docs.python.org/2/reference/datamodel.html#emulating-container-types
[2] http://docs.python.org/3/library/mmap.html
[3] http://docs.python.org/3/reference/datamodel.html#emulating-container-types

- 'bup index' is slower than it should be.

Expand Down
6 changes: 2 additions & 4 deletions config/configure
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,12 @@ if test "$BUP_PYTHON_CONFIG"; then
"$BUP_PYTHON_CONFIG")
fi
else
for py_maj_ver in 10 9 8 7 6; do
bup_python_config="$(bup_find_prog "python3.$py_maj_ver-config" '')"
for py_min_ver in 10 9 8 7 6; do
bup_python_config="$(bup_find_prog "python3.$py_min_ver-config" '')"
test -z "$bup_python_config" || break
done
test -z "$bup_python_config" \
&& bup_python_config="$(bup_find_prog python3-config '')"
test -z "$bup_python_config" \
&& bup_python_config="$(bup_find_prog python2.7-config '')"
if test -z "$bup_python_config"; then
AC_FAIL "ERROR: unable to find a suitable python-config"
fi
Expand Down
4 changes: 2 additions & 2 deletions dev/cleanup-mounts-under
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ for python in \
python3.8 \
python3.7 \
python3.6 \
python \
python2.7; do \
python; \
do \
if command -v "$python"; then
exec "$python" "$0" "$@"
fi
Expand Down
11 changes: 2 additions & 9 deletions dev/prep-for-debianish-build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -exuo pipefail

usage()
{
echo "Usage: prep-for-debianish-build [python2|python3] [pyxattr|xattr]"
echo "Usage: prep-for-debianish-build [python3] [pyxattr|xattr]"
}

export DEBIAN_FRONTEND=noninteractive
Expand All @@ -14,19 +14,12 @@ common_debs='gcc make linux-libc-dev git rsync eatmydata acl attr par2'
common_debs="$common_debs duplicity rdiff-backup rsnapshot dosfstools kmod"
common_debs="$common_debs pkg-config libreadline-dev libacl1-dev"

pyver="${1:-python2}"
pyver="${1:-python3}"
xattr="${2:-pyxattr}"

# dosfstools: for vfat for the (root) tests

case "$pyver" in
python2)
apt-get install -y \
$common_debs \
python2.7-dev python-fuse \
python-"$xattr" python-tornado python-pytest \
python-pytest-xdist pylint
;;
python3)
apt-get install -y \
$common_debs \
Expand Down
9 changes: 2 additions & 7 deletions dev/prep-for-freebsd-build
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ set -exu

usage()
{
echo "Usage: prep-for-freebsd-build [python2|python3]"
echo "Usage: prep-for-freebsd-build [python3]"
}

pyver="${1:-python2}"
pyver="${1:-python3}"

# Install build deps
export ASSUME_ALWAYS_YES=yes
Expand All @@ -20,11 +20,6 @@ pkgs='gmake git bash rsync curl par2cmdline readline duplicity'
pkgs="$pkgs rsnapshot"

case "$pyver" in
python2)
pkgs="$pkgs python2 py27-tornado py27-pip"
pkg install $pkgs
pip-2.7 install --user pytest pytest-xdist
;;
python3)
pkgs="$pkgs python38 py38-tornado py38-pytest py38-pytest-xdist"
pkg install $pkgs
Expand Down
8 changes: 2 additions & 6 deletions dev/prep-for-macos-build
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ set -exu

usage()
{
echo "Usage: prep-for-macos-build [python2|python3]"
echo "Usage: prep-for-macos-build [python3]"
}

pyver="${1:-python2}"
pyver="${1:-python3}"

if ! command -v brew; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Expand All @@ -21,10 +21,6 @@ brew link --force readline
# "brew unlink readline" will undo this hack

case "$pyver" in
python2)
easy_install-2.7 --user pip
/Users/anka/Library/Python/2.7/bin/pip install --user pytest pytest-xdist
;;
python3)
brew install python
pip3 install --user pytest pytest-xdist
Expand Down
1 change: 0 additions & 1 deletion dev/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "../config/config.h"

// According to Python, its header has to go first:
// http://docs.python.org/2/c-api/intro.html#include-files
// http://docs.python.org/3/c-api/intro.html#include-files
#include <Python.h>

Expand Down
4 changes: 2 additions & 2 deletions dev/validate-python
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ majver=$("$python" -c 'import sys; print(sys.version_info[0])')
minver=$("$python" -c 'import sys; print(sys.version_info[1])')

# May not be correct yet, i.e. actual requirement may be higher.
if test "$majver" -gt 2 -a "$minver" -lt 7; then
if test "$majver" -lt 3 || test "$majver" -eq 3 && test "$minver" -lt 7; then
# utime follow_symlinks >= 3.3
bup_version_str=$("$python" --version 2>&1)
echo "ERROR: found $bup_version_str (must be >= 3.7 if >= 3)" 1>&2
echo "ERROR: found $bup_version_str (must be >= 3.7)" 1>&2
exit 2
fi
Loading

0 comments on commit c8af075

Please sign in to comment.