Skip to content

Commit

Permalink
Merge pull request #1361 from roots/remove-python2-support
Browse files Browse the repository at this point in the history
Remove Python 2 support
  • Loading branch information
swalkinshaw authored Feb 20, 2022
2 parents fa1a5a4 + f409fe3 commit d1021e0
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['2.x', '3.x']
python-version: ['3.x']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### HEAD
* Remove Python 2 support ([#1361](https://github.com/roots/trellis/pull/1361))

### 1.14.0: February 16th, 2022
* Fix #1026 - Preserve nested path for copied folders between deploys ([#1364](https://github.com/roots/trellis/pull/1364))
* Fix #1354 - Ensure correct PHP version is set ([#1365](https://github.com/roots/trellis/pull/1365))
Expand Down
3 changes: 1 addition & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ Vagrant.configure('2') do |config|

config.vm.provision provisioner do |ansible|
if local_provisioning?
ansible.extra_vars = { ansible_python_interpreter: vconfig.fetch('vagrant_ansible_python_interpreter') }
ansible.install_mode = 'pip'
ansible.pip_install_cmd = 'sudo apt-get install -y -qq python3-distutils && curl https://bootstrap.pypa.io/get-pip.py | sudo python3'
ansible.pip_install_cmd = 'sudo apt-get install -y -qq python3-pip'
ansible.provisioning_path = provisioning_path
ansible.version = vconfig.fetch('vagrant_ansible_version')
end
Expand Down
7 changes: 0 additions & 7 deletions dev.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
---
- name: Set ansible_python_interpreter
hosts: web:&development
gather_facts: false
become: yes
roles:
- { role: python_interpreter, tags: [always] }

- name: "WordPress Server: Install LEMP Stack with PHP and MariaDB MySQL"
hosts: web:&development
become: yes
Expand Down
3 changes: 0 additions & 3 deletions lib/trellis/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions lib/trellis/plugins/callback/output.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os.path
import sys

Expand Down
3 changes: 0 additions & 3 deletions lib/trellis/plugins/callback/vars.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import re
import sys
import os
Expand Down
4 changes: 0 additions & 4 deletions lib/trellis/plugins/filter/filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function, unicode_literals)
__metaclass__ = type

import types

from ansible import errors
Expand Down
11 changes: 6 additions & 5 deletions lib/trellis/plugins/vars/version.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible import __version__
from ansible.errors import AnsibleError
from distutils.version import LooseVersion
from operator import eq, ge, gt
from sys import version_info
from platform import python_version, python_version_tuple

try:
from __main__ import display
Expand All @@ -17,6 +13,11 @@
version_requirement = '2.10.0'
version_tested_max = '2.10.16'

if python_version_tuple()[0] == '2':
raise AnsibleError(('Trellis no longer supports Python 2 (you are using version {}).'
' Python 2 reached end of life in 2020 and is unmaintained.\n'
'Python 3 is required as of Trellis version v1.15.0.').format(python_version()))

if not ge(LooseVersion(__version__), LooseVersion(version_requirement)):
raise AnsibleError(('Trellis no longer supports Ansible {}.\n'
'Please upgrade to Ansible {} or higher.').format(__version__, version_requirement))
Expand Down
3 changes: 0 additions & 3 deletions lib/trellis/utils/__init__.py

This file was deleted.

4 changes: 1 addition & 3 deletions lib/trellis/utils/output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os.path
Expand All @@ -9,7 +8,6 @@

from ansible import __version__
from ansible.module_utils._text import to_text
from ansible.module_utils.six import string_types

def system(vagrant_version=None):
# Get most recent Trellis CHANGELOG entry
Expand Down Expand Up @@ -91,7 +89,7 @@ def display(obj, result):
# Must pass unicode strings to Display.display() to prevent UnicodeError tracebacks
if isinstance(msg, list):
msg = '\n'.join([to_text(x) for x in msg])
elif not isinstance(msg, string_types):
elif not isinstance(msg, str):
msg = to_text(msg)

# Wrap text
Expand Down
20 changes: 5 additions & 15 deletions roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ site_keys_by_env_pair: "[
{% endfor %}
]"

_apt_packages_default:
apt_packages_default:
build-essential: "{{ apt_package_state }}"
curl: "{{ apt_package_state }}"
dbus: "{{ apt_package_state }}"
Expand All @@ -29,22 +29,12 @@ _apt_packages_default:
imagemagick: "{{ apt_package_state }}"
libgs-dev: "{{ apt_package_state }}"
libnss-myhostname: "{{ apt_package_state }}"
python: "{{ apt_package_state }}"
python3: "{{ apt_package_state }}"
python3-software-properties: "{{ apt_package_state }}"
python3-mysqldb: "{{ apt_package_state }}"
python3-pycurl: "{{ apt_package_state }}"
unzip: "{{ apt_package_state }}"

apt_packages_python:
'2':
python-software-properties: "{{ apt_package_state }}"
python-mysqldb: "{{ apt_package_state }}"
python-pycurl: "{{ apt_package_state }}"
'3':
python3-software-properties: "{{ apt_package_state }}"
python3-mysqldb: "{{ apt_package_state }}"
python3-pycurl: "{{ apt_package_state }}"

python_major_version: "{{ ansible_python_version[0] }}"
apt_packages_default: "{{ _apt_packages_default | combine(apt_packages_python[python_major_version]) }}"

apt_packages_custom: {}
apt_packages: "{{ apt_packages_default | combine(apt_packages_custom) }}"

Expand Down
9 changes: 2 additions & 7 deletions roles/letsencrypt/library/test_challenges.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/usr/bin/python
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import socket

try:
from httplib import HTTPConnection, HTTPException
except ImportError:
# Python 3
from http.client import HTTPConnection, HTTPException
from http.client import HTTPConnection, HTTPException

DOCUMENTATION = '''
---
Expand Down
6 changes: 2 additions & 4 deletions roles/letsencrypt/templates/renew-certs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python

from __future__ import print_function
#!/usr/bin/env python3

import os
import sys
Expand Down Expand Up @@ -29,7 +27,7 @@
'Not creating a new certificate.'.format(bundled_hashed_cert_path))

else:
cmd = ('/usr/bin/env python {{ acme_tiny_software_directory }}/acme_tiny.py '
cmd = ('/usr/bin/env python3 {{ acme_tiny_software_directory }}/acme_tiny.py '
'--quiet '
'--ca {{ letsencrypt_ca }} '
'--account-key {{ letsencrypt_account_key }} '
Expand Down
11 changes: 0 additions & 11 deletions roles/python_interpreter/tasks/main.yml

This file was deleted.

7 changes: 0 additions & 7 deletions server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
roles:
- { role: connection, tags: [connection, always] }

- name: Set ansible_python_interpreter
hosts: web:&{{ env }}
gather_facts: false
become: yes
roles:
- { role: python_interpreter, tags: [always] }

- name: WordPress Server - Install LEMP Stack with PHP and MariaDB MySQL
hosts: web:&{{ env }}
become: yes
Expand Down
1 change: 0 additions & 1 deletion vagrant.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ vagrant_memory: 1024 # in MB
vagrant_box: 'bento/ubuntu-20.04'
vagrant_box_version: '>= 202012.23.0'
vagrant_ansible_version: '2.10.7'
vagrant_ansible_python_interpreter: '/usr/bin/python3'
vagrant_skip_galaxy: false
vagrant_mount_type: 'nfs'

Expand Down

0 comments on commit d1021e0

Please sign in to comment.