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

remove Python 2 support #12

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions .coveragerc.py2

This file was deleted.

1 change: 0 additions & 1 deletion .coveragerc.py3
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[report]
exclude_lines =
pragma: no cover
if six.PY2:
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:
runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7, 3.5, 3.6]
python: [3.7, 3.12]
steps:
- name: Checkout source code
uses: actions/checkout@v2
Expand Down
8 changes: 0 additions & 8 deletions HACKING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ Then you can run tests with:

make

The default Python version is 2, to run tests against Python 3 just
prepend `PYTHON=python3` to the make commands above, for
example:

.. code:: shell

PYTHON=python3 make

Tox
---

Expand Down
34 changes: 12 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
PYTHON ?= python
PYTHON_MAJOR = $(shell $(PYTHON) -c "import sys; print(sys.version_info.major)")

# These paths are valid on Debian-based systems, on other systems you
# might have to set these variables from the command line.
COVERAGE ?= $(PYTHON)-coverage
SPHINXBUILD ?= /usr/share/sphinx/scripts/python$(PYTHON_MAJOR)/sphinx-build
COVERAGE ?= python3-coverage
SPHINXBUILD ?= /usr/share/sphinx/scripts/python3/sphinx-build

SOURCE = systemfixtures

Expand All @@ -13,32 +10,25 @@ all: check check-doc
check:
rm -f .coverage
$(COVERAGE) run --source=$(SOURCE) -m testtools.run discover
$(COVERAGE) report -m --fail-under=100 --rcfile=.coveragerc.py$(PYTHON_MAJOR)
$(COVERAGE) report -m --fail-under=100 --rcfile=.coveragerc.py3

check-doc:
SPHINXBUILD=$(SPHINXBUILD) $(MAKE) -C doc doctest

dependencies: dependencies-python$(PYTHON_MAJOR)
sudo apt-get install \
$(PYTHON)-pbr \
$(PYTHON)-six \
$(PYTHON)-fixtures \
$(PYTHON)-testtools \
$(PYTHON)-requests-mock \
$(PYTHON)-fakesleep \
$(PYTHON)-coverage \
$(PYTHON)-sphinx

dependencies-python2:
dependencies:
sudo apt-get install \
$(PYTHON)-subprocess32

dependencies-python3):
python3-pbr \
python3-fixtures \
python3-testtools \
python3-requests-mock \
python3-fakesleep \
python3-coverage \
python3-sphinx

clean:
rm -rf $(SOURCE).egg-info dist
rm -f AUTHORS ChangeLog
find -type f -name "*.pyc" | xargs rm -f
find -type d -name "__pycache_" | xargs rm -rf

.PHONY: all check check-doc dependencies dependencies-python2 dependencies-python3
.PHONY: all check check-doc dependencies
12 changes: 0 additions & 12 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import re
import doctest

import six

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand Down Expand Up @@ -300,16 +298,6 @@ class SixOutputChecker(OutputChecker):
"""

def check_output(self, want, got, optionflags):
if six.PY2:
if want == "12\n": # write() doesn't return number of bytes on PY2
want = ""

want = re.sub("PermissionError: (.*)", "OSError: \\1", want)
want = re.sub("'0o(.+)'\n", "'0\\1'\n", want)
want = re.sub("b'(.*?)'", "'\\1'", want)

got = re.sub("u'(.*?)'", "'\\1'", got)

return OutputChecker.check_output(self, want, got, optionflags)


Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pbr
six
fixtures
testtools
requests-mock
fakesleep
subprocess32; python_version < '3.5'
7 changes: 1 addition & 6 deletions systemfixtures/executable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import socket

import six
import subprocess

from testtools.content import Content
from testtools.content_type import UTF8_TEXT
Expand All @@ -11,10 +10,6 @@
TempDir,
)

if six.PY2:
import subprocess32 as subprocess
if six.PY3:
import subprocess


class FakeExecutable(Fixture):
Expand Down
31 changes: 9 additions & 22 deletions systemfixtures/filesystem.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import six
from os import DirEntry

from fixtures import (
Fixture,
Expand All @@ -8,15 +8,8 @@

from ._overlay import Overlay

if six.PY2:
BUILTIN_OPEN = "__builtin__.open"
if six.PY3:
BUILTIN_OPEN = "builtins.open"
from os import DirEntry


GENERIC_APIS = (
BUILTIN_OPEN,
"builtins.open",
"glob.glob",
"os.mkdir",
"os.rmdir",
Expand Down Expand Up @@ -45,11 +38,7 @@ def _setUp(self):
self._paths = {}
self._ownership = {}

if six.PY2:
# Python 2 doesn't support a fd argument
condition = self._is_fake_path
if six.PY3:
condition = self._is_fake_path_or_fd
condition = self._is_fake_path_or_fd

for api in GENERIC_APIS:
self.useFixture(Overlay(api, self._generic, condition))
Expand Down Expand Up @@ -135,14 +124,12 @@ def _is_fake_fd(self, fileno, *args, **kwargs):
path = self._path_from_fd(fileno)
return path.startswith(self.root.path)

if six.PY3:

def _is_fake_path_or_fd(self, path, *args, **kwargs):
if isinstance(path, int):
path = self._path_from_fd(path)
elif isinstance(path, DirEntry):
path = path.name
return self._is_fake_path(path)
def _is_fake_path_or_fd(self, path, *args, **kwargs):
if isinstance(path, int):
path = self._path_from_fd(path)
elif isinstance(path, DirEntry):
path = path.name
return self._is_fake_path(path)

def _is_fake_symlink(self, src, dst, *args, **kwargs):
return self._is_fake_path(src) or self._is_fake_path(dst)
Expand Down
9 changes: 3 additions & 6 deletions systemfixtures/processes/fixture.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import six
import subprocess

from fixtures import FakePopen
Expand Down Expand Up @@ -53,11 +52,9 @@ class _FakeProcessWithMissingAPIs(popen.FakeProcess):
is merged upstream.
"""

if six.PY3:

@property
def args(self):
return self._args["args"]
@property
def args(self):
return self._args["args"]

def poll(self):
return self.returncode
Expand Down
19 changes: 6 additions & 13 deletions systemfixtures/tests/test_filesystem.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import glob
import os
import sqlite3
import six
import shutil

from testtools import TestCase, skipIf
Expand All @@ -17,10 +16,6 @@
from ..matchers import HasOwnership


if six.PY2:
PermissionError = OSError


class FakeFilesystemTest(TestCase):

def setUp(self):
Expand Down Expand Up @@ -103,14 +98,12 @@ def test_copytree(self):
self.assertEqual(
sorted(os.listdir("./doc")), sorted(os.listdir("/foo")))

if six.PY3:

def test_listdir_with_fd(self):
self.fs.add("/foo")
os.makedirs("/foo/bar")
fd = os.open("/foo", os.O_RDONLY)
self.addCleanup(os.close, fd)
self.assertEqual(["bar"], os.listdir(fd))
def test_listdir_with_fd(self):
self.fs.add("/foo")
os.makedirs("/foo/bar")
fd = os.open("/foo", os.O_RDONLY)
self.addCleanup(os.close, fd)
self.assertEqual(["bar"], os.listdir(fd))

def test_readlink_to_real_path(self):
self.fs.add("/foo")
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py35,py36
envlist = py37,py312
skipsdist = True

[testenv]
Expand All @@ -11,5 +11,7 @@ setenv =
SPHINXBUILD=sphinx-build
whitelist_externals =
make
allowlist_externals =
make
commands =
make
Loading