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

sopel: drop support for Python < 3.6 #2062

Merged
merged 16 commits into from
Jun 27, 2021
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
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ include your changes.
the name of the thing you're changing in at the beginning of the message,
followed by a colon: the plugin name for plugins, "docs" for documentation
files, "coretasks" for `coretasks.py`, "db" for the database feature, etc.
* Python files should always have `# coding=utf-8` as the first line (or the
second, if the first is `#!/usr/bin/env python`), and `from __future__ import
unicode_literals, absolute_import, print_function, division` as the first
line after the module docstring.
* Python files should always have `from __future__ import generator_stop`
as the first line after the module docstring.

Documenting Code
----------------
Expand Down
9 changes: 1 addition & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ First, either clone the repository with ``git clone
git://github.com/sopel-irc/sopel.git`` or download a tarball `from GitHub
<https://github.com/sopel-irc/sopel/releases/latest>`_.

Note: Sopel requires Python 2.7.x or Python 3.3+ to run. On Python 2.7,
Sopel requires ``backports.ssl_match_hostname`` to be installed. Use
``pip install backports.ssl_match_hostname`` or
``yum install python-backports.ssl_match_hostname`` to install it, or download
and install it manually `from PyPI <https://pypi.org/project/backports.ssl_match_hostname>`_.

Important: Sopel 8.0 will drop support for many old Python versions,
including Python 2.7!
Note: Sopel requires Python 3.6+ to run.

In the source directory (whether cloned or from the tarball) run ``pip install
-e .``. You can then run ``sopel`` to configure and start the bot.
Expand Down
20 changes: 0 additions & 20 deletions checkstyle.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/sh

find_source_files() {
find . -name '*.py' -size +0 -print | grep -ve './docs' -e 'env' -e './contrib' -e './conftest.py'
}
files=$(find_source_files)
# For now, go through all the checking stages and only die at the end
exit_code=0

Expand All @@ -12,20 +8,4 @@ if ! flake8; then
exit_code=1
fi

# Find files which use the unicode type but (heuristically) don't make it py3
# safe
dgw marked this conversation as resolved.
Show resolved Hide resolved
fail_py3_unicode=false
for file in $(find_source_files); do
if grep -qle 'unicode(' -e 'class .*(unicode)' $file; then
if ! grep -ql 'unicode = str' $file; then
echo "Suspicious 'unicode' use: $file"
fail_py3_unicode=true
fi
fi
done
if $fail_py3_unicode; then
echo "ERROR: Above files use unicode() but do not make it safe for Python 3."
exit_code=1
fi

exit $exit_code
36 changes: 9 additions & 27 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
coveralls<2.0; python_version < '3.5'
coveralls>=2.0; python_version >= '3.5'
flake8<3.6.0; python_version == '3.3'
flake8>=3.7.0,<3.8.0; python_version != '3.3'
coveralls>=2.0
flake8
flake8-coding
flake8-future-import<0.4.6
flake8-import-order; python_version > '3.3'
flake8-import-order<=1.18.1; python_version <= '3.3'
# transitive dependency of Sphinx
# added f-strings in 2.x, but it's not worth doing a whole suite of version markers
MarkupSafe<2.0
pytest<3.3; python_version == '3.3'
pytest>=4.6,<4.7; python_version != '3.3'
pytest-vcr==1.0.2; python_version != '3.3'
pytest-vcr==0.3.0; python_version == '3.3'
PyYAML<5.1; python_version == '3.3'
PyYAML<5.3; python_version == '3.4'
flake8-future-import
flake8-import-order
pytest>=4.6,<4.7
pytest-vcr==1.0.2
requests-mock==1.9.1
setuptools<40.0; python_version == '3.3'
# use Sphinx 3.x until dev begins on Sopel 8 and we drop the dead snakes
sphinx<4.0
# autoprogram extension added type annotations in 0.1.6
# such annotations require Python 3.5
sphinxcontrib-autoprogram<0.1.6; python_version < '3.5'
sphinx
# further constrain autoprogram version because the new (in 2021) maintainer
# already demonstrated a willingness to make major changes in patch versions
sphinxcontrib-autoprogram<=0.1.7; python_version >= '3.5'
vcrpy==2.1.1; python_version == '2.7'
vcrpy<1.12.0; python_version == '3.3'
vcrpy<2.1.0; python_version == '3.4'
vcrpy<3.0.0; python_version >= '3.5'
sphinxcontrib-autoprogram<=0.1.7
vcrpy<3.0.0
3 changes: 1 addition & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
#
from __future__ import generator_stop
# Sopel IRC Bot documentation build configuration file, created by
# sphinx-quickstart on Mon Jul 16 23:45:29 2012.
#
Expand Down
3 changes: 1 addition & 2 deletions pytest_run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding=utf-8
"""This is a script for running pytest from the command line.

This script exists so that the project directory gets added to sys.path, which
Expand All @@ -11,7 +10,7 @@

Exirel marked this conversation as resolved.
Show resolved Hide resolved
https://sopel.chat
"""
from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import generator_stop
Exirel marked this conversation as resolved.
Show resolved Hide resolved

if __name__ == "__main__":
import sys
Expand Down
24 changes: 4 additions & 20 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
xmltodict<0.12.0; python_version == '3.3'
xmltodict==0.12; python_version != '3.3'
xmltodict==0.12
pytz
praw>=4.0.0,<6.0.0
# transitive dependency of praw; v0.18 introduced f-string syntax
update-checker<0.18; python_version < '3.6'
geoip2<3.0; python_version <= '3.5' and python_version != '2.7'
geoip2>=3.0,<4.0; python_version == '2.7'
geoip2>=4.0,<5.0; python_version >= '3.6'
# transitive dependency of geoip2; v2 dropped py2.7 & py3 < 3.6
maxminddb<2.0; python_version < '3.6'
ipaddress<2.0; python_version < '3.3'
geoip2>=4.0,<5.0
requests>=2.0.0,<3.0.0
# transitive dependency of requests
# 2.0 will drop EOL Python 2.7 & 3.5, just like Sopel 8 plans to
urllib3<1.27; python_version != '3.3' and python_version != '3.4'
urllib3<1.23; python_version == '3.3'
urllib3<1.25; python_version == '3.4'
dnspython<2.0; python_version == '2.7'
dnspython<1.16.0; python_version == '3.3'
dnspython<3.0; python_version >= '3.4'
sqlalchemy<1.3; python_version == '3.3'
sqlalchemy<1.4; python_version != '3.3'
dnspython<3.0
sqlalchemy<1.4
19 changes: 6 additions & 13 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ classifiers =
License :: Eiffel Forum License (EFL)
License :: OSI Approved :: Eiffel Forum License
Operating System :: POSIX :: Linux
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Exirel marked this conversation as resolved.
Show resolved Hide resolved
Programming Language :: Python :: 3.9
Topic :: Communications :: Chat :: Internet Relay Chat

[options]
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4
python_requires = >=3.6, <4
packages = find:
zip_safe = false

Expand All @@ -53,19 +50,15 @@ ignore =
# These are forbidding certain __future__ imports. The future-import plugin
# has errors both for having and not having them; we want to have these until
# Sopel no longer supports Python versions that require them.
FI50,FI51,FI53,FI54,FI55,
FI55,
# These would require future imports that are not needed any more on Sopel's
# oldest supported Python version (2.7).
FI12,FI16,FI17,
# We ignore the error for missing generator_stop because it's only available
# in Python 3.5+ (switch this to FI55 in the above list when Sopel drops
# support for Python older than 3.5)
FI15,
# oldest supported Python version (3.6).
FI10,FI11,FI12,FI13,FI14,FI16,FI17,
# Ignore "annotations" future import, since it's not available before 3.7
FI18
exclude =
docs/*,
env/*,
contrib/*,
conftest.py
accept-encodings = utf-8
no-accept-encodings = True
22 changes: 10 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# coding=utf-8
from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import generator_stop

import sys

Expand Down Expand Up @@ -34,16 +33,17 @@

# We check Python's version ourselves in case someone installed Sopel on an
# old version of pip (<9.0.0), which doesn't know about `python_requires`.
if sys.version_info < (2, 7) or (
sys.version_info.major >= 3 and sys.version_info < (3, 3)
):
if sys.version_info < (3, 6):
# Maybe not the best way to do this, but this question is tiring.
raise ImportError('Sopel requires Python 2.7+ or 3.3+.')
# Py2 EOL: https://www.python.org/dev/peps/pep-0373/#maintenance-releases
if sys.version_info.major == 2:
raise ImportError('Sopel requires Python 3.6+.')

# Py3.6 EOL: https://www.python.org/dev/peps/pep-0494/#lifespan
if sys.version_info < (3, 7):
# TODO check this warning before releasing Sopel 8.0
print(
'Warning: Python 2.x has reached end of life and will receive '
'no further updates. Sopel 8.0 will drop support for it.',
'Warning: Python 3.6 will reach end of life by the end of 2021 '
'and will receive no further updates. '
'Sopel 9.0 will drop support for it.',
file=sys.stderr,
)

Expand All @@ -54,8 +54,6 @@ def read_reqs(path):


requires = read_reqs('requirements.txt')
if sys.version_info[0] < 3:
requires.append('backports.ssl_match_hostname')
dev_requires = requires + read_reqs('dev-requirements.txt')

setup(
Expand Down
3 changes: 1 addition & 2 deletions sopel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
# coding=utf-8
from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import generator_stop

import sys

Expand Down
14 changes: 6 additions & 8 deletions sopel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
# ASCII ONLY IN THIS FILE THOUGH!!!!!!!
# Python does some stupid bullshit of respecting LC_ALL over the encoding on the
# file, so in order to undo Python's ridiculous fucking idiocy, we have to have
Expand All @@ -10,7 +9,7 @@
#
# Licensed under the Eiffel Forum License 2.

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import generator_stop

from collections import namedtuple
import locale
Expand All @@ -35,12 +34,11 @@
]

loc = locale.getlocale()
if sys.version_info.major > 2:
if not loc[1] or 'UTF-8' not in loc[1]:
print('WARNING!!! You are running with a non-UTF8 locale environment '
'variables (e.g. LC_ALL is set to "C"), which makes Python 3 do '
'stupid things. If you get strange errors, please set it to '
'something like "en_US.UTF-8".', file=sys.stderr)
if not loc[1] or 'UTF-8' not in loc[1]:
print('WARNING!!! You are running with a non-UTF8 locale environment '
'variable (e.g. LC_ALL is set to "C"), which makes Python 3 do '
'stupid things. If you get strange errors, please set it to '
'something like "en_US.UTF-8".', file=sys.stderr)


__version__ = pkg_resources.get_distribution('sopel').version
Expand Down
20 changes: 5 additions & 15 deletions sopel/bot.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# coding=utf-8
# Copyright 2008, Sean B. Palmer, inamidst.com
# Copyright © 2012, Elad Alfassa <elad@fedoraproject.org>
# Copyright 2012-2015, Elsie Powell, http://embolalia.com
# Copyright 2019, Florian Strzelecki <florian.strzelecki@gmail.com>
#
# Licensed under the Eiffel Forum License 2.

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import generator_stop

from ast import literal_eval
from datetime import datetime
import itertools
import logging
import re
import signal
import sys
import threading
import time

Expand Down Expand Up @@ -44,14 +42,6 @@
SIGNALS = QUIT_SIGNALS + RESTART_SIGNALS


if sys.version_info.major >= 3:
unicode = str
basestring = str
py3 = True
else:
py3 = False


class Sopel(irc.AbstractBot):
def __init__(self, config, daemon=False):
super(Sopel, self).__init__(config)
Expand Down Expand Up @@ -358,7 +348,7 @@ def __setup_plugins_check_manual_url_callbacks(self, name):
# nothing to check
return

for key, callback in tools.iteritems(self.memory['url_callbacks']):
for key, callback in self.memory['url_callbacks'].items():
is_checked = getattr(
callback, '_sopel_url_callbacks_checked', False)
if is_checked:
Expand Down Expand Up @@ -1129,7 +1119,7 @@ def register_url_callback(self, pattern, callback):
if 'url_callbacks' not in self.memory:
self.memory['url_callbacks'] = tools.SopelMemory()

if isinstance(pattern, basestring):
if isinstance(pattern, str):
pattern = re.compile(pattern)

# Mark the callback as checked: using this method is safe.
Expand Down Expand Up @@ -1180,7 +1170,7 @@ def unregister_url_callback(self, pattern, callback):
# nothing to unregister
return

if isinstance(pattern, basestring):
if isinstance(pattern, str):
pattern = re.compile(pattern)

try:
Expand Down Expand Up @@ -1216,7 +1206,7 @@ def search_url_callbacks(self, url):
# nothing to search
return

for regex, function in tools.iteritems(self.memory['url_callbacks']):
for regex, function in self.memory['url_callbacks'].items():
match = regex.search(url)
if match:
yield function, match
Expand Down
3 changes: 1 addition & 2 deletions sopel/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding=utf-8
from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import generator_stop

# Shortcut imports
from .utils import ( # noqa
Expand Down
3 changes: 1 addition & 2 deletions sopel/cli/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding=utf-8
"""Sopel Config Command Line Interface (CLI): ``sopel-config``"""
from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import generator_stop

import argparse
import os
Expand Down
3 changes: 1 addition & 2 deletions sopel/cli/plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding=utf-8
"""Sopel Plugins Command Line Interface (CLI): ``sopel-plugins``"""
from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import generator_stop

import argparse
import inspect
Expand Down
Loading