Skip to content

Commit ac546a9

Browse files
committed
Closes netbox-community#2000: Remove support for Python 2
1 parent cd2aee3 commit ac546a9

File tree

10 files changed

+17
-59
lines changed

10 files changed

+17
-59
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ addons:
55
postgresql: "9.4"
66
language: python
77
python:
8-
- "2.7"
98
- "3.5"
109
install:
1110
- pip install -r requirements.txt

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ or join us in the #netbox Slack channel on [NetworkToCode](https://networktocode
1616

1717
### Build Status
1818

19-
NetBox is built against both Python 2.7 and 3.5. Python 3.5 or higher is strongly recommended.
20-
2119
| | status |
2220
|-------------|------------|
2321
| **master** | [![Build Status](https://travis-ci.org/digitalocean/netbox.svg?branch=master)](https://travis-ci.org/digitalocean/netbox) |

base_requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# django-filter-1.1.0 breaks with Django-2.1
2-
Django>=1.11,<2.1
2+
Django>=2.0,<2.1
33
django-cors-headers
44
django-debug-toolbar
55
# django-filter-2.0.0 drops Python 2 support (blocked by #2000)

docs/additional-features/netbox-shell.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This will launch a customized version of [the built-in Django shell](https://doc
99
```
1010
$ ./manage.py nbshell
1111
### NetBox interactive shell (jstretch-laptop)
12-
### Python 2.7.6 | Django 1.11.3 | NetBox 2.1.0-dev
12+
### Python 3.5.2 | Django 2.0.8 | NetBox 2.4.3
1313
### lsmodels() will show available models. Use help(<model>) for more info.
1414
```
1515

docs/installation/upgrading.md

-7
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ Once the new code is in place, run the upgrade script (which may need to be run
6464
# ./upgrade.sh
6565
```
6666

67-
!!! warning
68-
The upgrade script will prefer Python3 and pip3 if both executables are available. To force it to use Python2 and pip, use the `-2` argument as below. Note that Python 2 will no longer be supported in NetBox v2.5.
69-
70-
```no-highlight
71-
# ./upgrade.sh -2
72-
```
73-
7467
This script:
7568

7669
* Installs or upgrades any new required Python packages

netbox/extras/reports.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import importlib
55
import inspect
66
import pkgutil
7-
import sys
87

98
from django.conf import settings
109
from django.utils import timezone
@@ -26,22 +25,12 @@ def get_report(module_name, report_name):
2625
"""
2726
file_path = '{}/{}.py'.format(settings.REPORTS_ROOT, module_name)
2827

29-
# Python 3.5+
30-
if sys.version_info >= (3, 5):
31-
spec = importlib.util.spec_from_file_location(module_name, file_path)
32-
module = importlib.util.module_from_spec(spec)
33-
try:
34-
spec.loader.exec_module(module)
35-
except FileNotFoundError:
36-
return None
37-
38-
# Python 2.7
39-
else:
40-
import imp
41-
try:
42-
module = imp.load_source(module_name, file_path)
43-
except IOError:
44-
return None
28+
spec = importlib.util.spec_from_file_location(module_name, file_path)
29+
module = importlib.util.module_from_spec(spec)
30+
try:
31+
spec.loader.exec_module(module)
32+
except FileNotFoundError:
33+
return None
4534

4635
report = getattr(module, report_name, None)
4736
if report is None:

netbox/netbox/settings.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77
from django.contrib.messages import constants as messages
88
from django.core.exceptions import ImproperlyConfigured
99

10+
# Check for Python 3.5+
11+
if sys.version_info < (3, 5):
12+
raise RuntimeError(
13+
"NetBox requires Python 3.5 or higher (current: Python {})".format(sys.version.split()[0])
14+
)
15+
16+
# Check for configuration file
1017
try:
1118
from netbox import configuration
1219
except ImportError:
1320
raise ImproperlyConfigured(
1421
"Configuration file is not present. Please define netbox/netbox/configuration.py per the documentation."
1522
)
1623

17-
# Raise a deprecation warning for Python 2.x
18-
if sys.version_info[0] < 3:
19-
warnings.warn(
20-
"Support for Python 2 will be removed in NetBox v2.5. Please consider migration to Python 3 at your earliest "
21-
"opportunity. Guidance is available in the documentation at http://netbox.readthedocs.io/.",
22-
DeprecationWarning
23-
)
24-
2524
VERSION = '2.4.4-dev'
2625

2726
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

netbox/utilities/middleware.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ def process_exception(self, request, exception):
7272
custom_template = 'exceptions/programming_error.html'
7373
elif isinstance(exception, ImportError):
7474
custom_template = 'exceptions/import_error.html'
75-
elif (
76-
sys.version_info[0] >= 3 and isinstance(exception, PermissionError)
77-
) or (
78-
isinstance(exception, OSError) and exception.errno == 13
79-
):
75+
elif isinstance(exception, PermissionError):
8076
custom_template = 'exceptions/permission_error.html'
8177

8278
# Return a custom error message, or fall back to Django's default 500 error handling

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Django>=1.11,<2.1
1+
Django>=2.0,<2.1
22
django-cors-headers==2.4.0
33
django-debug-toolbar==1.9.1
44
django-filter==1.1.0

upgrade.sh

-16
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,8 @@
55
# Once the script completes, remember to restart the WSGI service (e.g.
66
# gunicorn or uWSGI).
77

8-
# Determine which version of Python/pip to use. Default to v3 (if available)
9-
# but allow the user to force v2.
108
PYTHON="python3"
119
PIP="pip3"
12-
type $PYTHON >/dev/null 2>&1 && type $PIP >/dev/null 2>&1 || PYTHON="python" PIP="pip"
13-
while getopts ":2" opt; do
14-
case $opt in
15-
2)
16-
PYTHON="python"
17-
PIP="pip"
18-
echo "Forcing Python/pip v2"
19-
;;
20-
\?)
21-
echo "Invalid option: -$OPTARG" >&2
22-
exit
23-
;;
24-
esac
25-
done
2610

2711
# Optionally use sudo if not already root, and always prompt for password
2812
# before running the command

0 commit comments

Comments
 (0)