Skip to content

Commit

Permalink
Drop Python 2.7 and 3.6 support (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclay authored Oct 11, 2023
1 parent c780524 commit 3313989
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
9 changes: 2 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ RUN apt-get update -y && \
openssh-client \
openssh-server \
openssl \
python2.7-dev \
python3.8-dev \
python3.8-distutils \
python3.8-venv \
Expand All @@ -41,8 +40,6 @@ COPY files/deadsnakes.list /etc/apt/sources.list.d/deadsnakes.list
# This is done separately to avoid conflicts with official Ubuntu packages.
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
python3.6-dev \
python3.6-venv \
python3.7-dev \
python3.7-distutils \
python3.7-venv \
Expand All @@ -60,8 +57,7 @@ RUN apt-get update -y && \
rm -rf /var/lib/apt/lists/*

RUN rm /etc/apt/apt.conf.d/docker-clean && \
ln -s python2.7 /usr/bin/python2 && \
ln -s python3 /usr/bin/python && \
ln -s python3 /usr/bin/python && \
locale-gen en_US.UTF-8

# Install PowerShell using a binary archive.
Expand Down Expand Up @@ -94,6 +90,5 @@ RUN ln -s /usr/bin/python3.12 /usr/share/container-setup/python
RUN /usr/share/container-setup/python -B /usr/share/container-setup/setup.py

# Make sure the pip entry points in /usr/bin are correct.
RUN rm -f /usr/bin/pip2 && cp -av /usr/local/bin/pip2 /usr/bin/pip2 && /usr/bin/pip2 -V && \
rm -f /usr/bin/pip3 && cp -av /usr/local/bin/pip3 /usr/bin/pip3 && /usr/bin/pip3 -V && \
RUN rm -f /usr/bin/pip3 && cp -av /usr/local/bin/pip3 /usr/bin/pip3 && /usr/bin/pip3 -V && \
rm -f /usr/bin/pip && cp -av /usr/local/bin/pip /usr/bin/pip && /usr/bin/pip -V
12 changes: 1 addition & 11 deletions files/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,7 @@ class Pip:
wheel='0.37.1',
)

_PACKAGES = {
'2.7': dict(
pip='20.3.4', # 21.0 requires Python 3.6+
setuptools='44.1.1', # 45.0.0 requires Python 3.5+
wheel=None,
),
'3.6': dict(
pip='21.3.1', # 22.0 requires Python 3.7+
setuptools='59.6.0', # 59.7.0 requires Python 3.7+
wheel=None,
),
_PACKAGES: dict[str, dict[str, str]] = {
}

def __init__(self, python: Python) -> None:
Expand Down
37 changes: 13 additions & 24 deletions files/quiet_pip.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
"""Custom entry-point for pip that filters out unwanted logging and warnings."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations

import logging
import os
import re
import runpy
import sys
import warnings

BUILTIN_FILTERER_FILTER = logging.Filterer.filter

LOGGING_MESSAGE_FILTER = re.compile("^("
".*Running pip install with root privileges is generally not a good idea.*|" # custom Fedora patch [1]
".*Running pip as the 'root' user can result in broken permissions .*|" # pip 21.1
"DEPRECATION: Python 2.7 will reach the end of its life .*|" # pip 19.2.3
"Ignoring .*: markers .* don't match your environment|"
"Looking in indexes: .*|" # pypi-test-container
"Requirement already satisfied.*"
")$")

# [1] https://src.fedoraproject.org/rpms/python-pip/blob/master/f/emit-a-warning-when-running-with-root-privileges.patch

WARNING_MESSAGE_FILTERS = (
# DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained.
# pip 21.0 will drop support for Python 2.7 in January 2021.
# More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
'DEPRECATION: Python 2.7 reached the end of its life ',
)
# [1] https://src.fedoraproject.org/rpms/python-pip/blob/f34/f/emit-a-warning-when-running-with-root-privileges.patch


def custom_filterer_filter(self, record):
Expand All @@ -44,20 +34,19 @@ def main():
# It also avoids problems with loss of color output and mixing up the order of stdout/stderr messages.
logging.Filterer.filter = custom_filterer_filter

for message_filter in WARNING_MESSAGE_FILTERS:
# Setting filterwarnings in code is necessary because of the following:
# Python 2.7 cannot use the -W option to match warning text after a colon. This makes it impossible to match specific warning messages.
warnings.filterwarnings('ignore', message_filter)

get_pip = os.environ.get('GET_PIP')

if get_pip:
directory, filename = os.path.split(get_pip)
module = os.path.splitext(filename)[0]
sys.path.insert(0, directory)
runpy.run_module(module, run_name='__main__', alter_sys=True)
else:
runpy.run_module('pip.__main__', run_name='__main__', alter_sys=True)
try:
if get_pip:
directory, filename = os.path.split(get_pip)
module = os.path.splitext(filename)[0]
sys.path.insert(0, directory)
runpy.run_module(module, run_name='__main__', alter_sys=True)
else:
runpy.run_module('pip.__main__', run_name='__main__', alter_sys=True)
except ImportError as ex:
print('pip is unavailable: %s' % ex)
sys.exit(1)


if __name__ == '__main__':
Expand Down

0 comments on commit 3313989

Please sign in to comment.