mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #2000: Remove support for Python 2
This commit is contained in:
@ -5,7 +5,6 @@ addons:
|
|||||||
postgresql: "9.4"
|
postgresql: "9.4"
|
||||||
language: python
|
language: python
|
||||||
python:
|
python:
|
||||||
- "2.7"
|
|
||||||
- "3.5"
|
- "3.5"
|
||||||
install:
|
install:
|
||||||
- pip install -r requirements.txt
|
- pip install -r requirements.txt
|
||||||
|
@ -16,8 +16,6 @@ or join us in the #netbox Slack channel on [NetworkToCode](https://networktocode
|
|||||||
|
|
||||||
### Build Status
|
### Build Status
|
||||||
|
|
||||||
NetBox is built against both Python 2.7 and 3.5. Python 3.5 or higher is strongly recommended.
|
|
||||||
|
|
||||||
| | status |
|
| | status |
|
||||||
|-------------|------------|
|
|-------------|------------|
|
||||||
| **master** | [](https://travis-ci.org/digitalocean/netbox) |
|
| **master** | [](https://travis-ci.org/digitalocean/netbox) |
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# django-filter-1.1.0 breaks with Django-2.1
|
# django-filter-1.1.0 breaks with Django-2.1
|
||||||
Django>=1.11,<2.1
|
Django>=2.0,<2.1
|
||||||
django-cors-headers
|
django-cors-headers
|
||||||
django-debug-toolbar
|
django-debug-toolbar
|
||||||
# django-filter-2.0.0 drops Python 2 support (blocked by #2000)
|
# django-filter-2.0.0 drops Python 2 support (blocked by #2000)
|
||||||
|
@ -9,7 +9,7 @@ This will launch a customized version of [the built-in Django shell](https://doc
|
|||||||
```
|
```
|
||||||
$ ./manage.py nbshell
|
$ ./manage.py nbshell
|
||||||
### NetBox interactive shell (jstretch-laptop)
|
### NetBox interactive shell (jstretch-laptop)
|
||||||
### Python 2.7.6 | Django 1.11.3 | NetBox 2.1.0-dev
|
### Python 3.5.2 | Django 2.0.8 | NetBox 2.4.3
|
||||||
### lsmodels() will show available models. Use help(<model>) for more info.
|
### lsmodels() will show available models. Use help(<model>) for more info.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -64,13 +64,6 @@ Once the new code is in place, run the upgrade script (which may need to be run
|
|||||||
# ./upgrade.sh
|
# ./upgrade.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! warning
|
|
||||||
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.
|
|
||||||
|
|
||||||
```no-highlight
|
|
||||||
# ./upgrade.sh -2
|
|
||||||
```
|
|
||||||
|
|
||||||
This script:
|
This script:
|
||||||
|
|
||||||
* Installs or upgrades any new required Python packages
|
* Installs or upgrades any new required Python packages
|
||||||
|
@ -4,7 +4,6 @@ from collections import OrderedDict
|
|||||||
import importlib
|
import importlib
|
||||||
import inspect
|
import inspect
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import sys
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
@ -26,8 +25,6 @@ def get_report(module_name, report_name):
|
|||||||
"""
|
"""
|
||||||
file_path = '{}/{}.py'.format(settings.REPORTS_ROOT, module_name)
|
file_path = '{}/{}.py'.format(settings.REPORTS_ROOT, module_name)
|
||||||
|
|
||||||
# Python 3.5+
|
|
||||||
if sys.version_info >= (3, 5):
|
|
||||||
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
try:
|
try:
|
||||||
@ -35,14 +32,6 @@ def get_report(module_name, report_name):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Python 2.7
|
|
||||||
else:
|
|
||||||
import imp
|
|
||||||
try:
|
|
||||||
module = imp.load_source(module_name, file_path)
|
|
||||||
except IOError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
report = getattr(module, report_name, None)
|
report = getattr(module, report_name, None)
|
||||||
if report is None:
|
if report is None:
|
||||||
return None
|
return None
|
||||||
|
@ -7,6 +7,13 @@ import warnings
|
|||||||
from django.contrib.messages import constants as messages
|
from django.contrib.messages import constants as messages
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
|
# Check for Python 3.5+
|
||||||
|
if sys.version_info < (3, 5):
|
||||||
|
raise RuntimeError(
|
||||||
|
"NetBox requires Python 3.5 or higher (current: Python {})".format(sys.version.split()[0])
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check for configuration file
|
||||||
try:
|
try:
|
||||||
from netbox import configuration
|
from netbox import configuration
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -14,14 +21,6 @@ except ImportError:
|
|||||||
"Configuration file is not present. Please define netbox/netbox/configuration.py per the documentation."
|
"Configuration file is not present. Please define netbox/netbox/configuration.py per the documentation."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Raise a deprecation warning for Python 2.x
|
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
warnings.warn(
|
|
||||||
"Support for Python 2 will be removed in NetBox v2.5. Please consider migration to Python 3 at your earliest "
|
|
||||||
"opportunity. Guidance is available in the documentation at http://netbox.readthedocs.io/.",
|
|
||||||
DeprecationWarning
|
|
||||||
)
|
|
||||||
|
|
||||||
VERSION = '2.4.4-dev'
|
VERSION = '2.4.4-dev'
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
@ -72,11 +72,7 @@ class ExceptionHandlingMiddleware(object):
|
|||||||
custom_template = 'exceptions/programming_error.html'
|
custom_template = 'exceptions/programming_error.html'
|
||||||
elif isinstance(exception, ImportError):
|
elif isinstance(exception, ImportError):
|
||||||
custom_template = 'exceptions/import_error.html'
|
custom_template = 'exceptions/import_error.html'
|
||||||
elif (
|
elif isinstance(exception, PermissionError):
|
||||||
sys.version_info[0] >= 3 and isinstance(exception, PermissionError)
|
|
||||||
) or (
|
|
||||||
isinstance(exception, OSError) and exception.errno == 13
|
|
||||||
):
|
|
||||||
custom_template = 'exceptions/permission_error.html'
|
custom_template = 'exceptions/permission_error.html'
|
||||||
|
|
||||||
# Return a custom error message, or fall back to Django's default 500 error handling
|
# Return a custom error message, or fall back to Django's default 500 error handling
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Django>=1.11,<2.1
|
Django>=2.0,<2.1
|
||||||
django-cors-headers==2.4.0
|
django-cors-headers==2.4.0
|
||||||
django-debug-toolbar==1.9.1
|
django-debug-toolbar==1.9.1
|
||||||
django-filter==1.1.0
|
django-filter==1.1.0
|
||||||
|
16
upgrade.sh
16
upgrade.sh
@ -5,24 +5,8 @@
|
|||||||
# Once the script completes, remember to restart the WSGI service (e.g.
|
# Once the script completes, remember to restart the WSGI service (e.g.
|
||||||
# gunicorn or uWSGI).
|
# gunicorn or uWSGI).
|
||||||
|
|
||||||
# Determine which version of Python/pip to use. Default to v3 (if available)
|
|
||||||
# but allow the user to force v2.
|
|
||||||
PYTHON="python3"
|
PYTHON="python3"
|
||||||
PIP="pip3"
|
PIP="pip3"
|
||||||
type $PYTHON >/dev/null 2>&1 && type $PIP >/dev/null 2>&1 || PYTHON="python" PIP="pip"
|
|
||||||
while getopts ":2" opt; do
|
|
||||||
case $opt in
|
|
||||||
2)
|
|
||||||
PYTHON="python"
|
|
||||||
PIP="pip"
|
|
||||||
echo "Forcing Python/pip v2"
|
|
||||||
;;
|
|
||||||
\?)
|
|
||||||
echo "Invalid option: -$OPTARG" >&2
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# Optionally use sudo if not already root, and always prompt for password
|
# Optionally use sudo if not already root, and always prompt for password
|
||||||
# before running the command
|
# before running the command
|
||||||
|
Reference in New Issue
Block a user