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

require python-3.5 or later #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
fail-fast: false
matrix:
imgtag:
- 2.7-buster
- 3.4-stretch
- 3.5-buster
- 3.6-buster
- 3.7-buster
Expand All @@ -30,9 +28,6 @@ jobs:
run: |
apt-get -q -y update
apt-get -q -y install openssh-client openssh-server rsync sudo
if [ 3.4-stretch = "${{matrix.imgtag}}" ]; then
sed -i -e '/^mesg n/d' /root/.profile
fi
- name: Python dependencies
run: |
pip install -r dev-requirements.txt
Expand Down
21 changes: 8 additions & 13 deletions fabric/context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

"""

from contextlib import contextmanager
import six
from contextlib import contextmanager, ExitStack
import socket
import select

Expand All @@ -28,16 +27,12 @@
from fabric import state
from fabric.utils import isatty

if six.PY2 is True:
from contextlib import nested
else:
from contextlib import ExitStack

class nested(ExitStack):
def __init__(self, *managers):
super(nested, self).__init__()
for manager in managers:
self.enter_context(manager)
class nested(ExitStack):
def __init__(self, *managers):
super(nested, self).__init__()
for manager in managers:
self.enter_context(manager)


if not win32:
Expand Down Expand Up @@ -130,7 +125,7 @@ def _setenv(variables):
clean_revert = variables.pop('clean_revert', False)
previous = {}
new = []
for key, value in six.iteritems(variables):
for key, value in variables.items():
if key in state.env:
previous[key] = state.env[key]
else:
Expand All @@ -140,7 +135,7 @@ def _setenv(variables):
yield
finally:
if clean_revert:
for key, value in six.iteritems(variables):
for key, value in variables.items():
# If the current env value for this key still matches the
# value we set it to beforehand, we are OK to revert it to the
# pre-block value.
Expand Down
9 changes: 4 additions & 5 deletions fabric/contrib/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import hashlib
import os
import six

from io import StringIO
from functools import partial

from fabric.api import run, sudo, hide, settings, env, put, abort
Expand Down Expand Up @@ -163,12 +162,12 @@ def upload_template(filename, destination, context=None, use_jinja=False,
target = destination.replace(' ', r'\ ')
func("cp %s %s.bak" % (target, target))

if six.PY3 is True and isinstance(text, bytes):
if isinstance(text, bytes):
text = text.decode('utf-8')

# Upload the file.
return put(
local_path=six.StringIO(text),
local_path=StringIO(text),
remote_path=destination,
use_sudo=use_sudo,
mirror_local_mode=mirror_local_mode,
Expand Down Expand Up @@ -413,7 +412,7 @@ def append(filename, text, use_sudo=False, partial=False, escape=True,
"""
func = use_sudo and sudo or run
# Normalize non-list input to be a list
if isinstance(text, six.string_types):
if isinstance(text, str):
text = [text]
for line in text:
regex = '^' + _escape_for_regex(line) + ('' if partial else '$')
Expand Down
3 changes: 1 addition & 2 deletions fabric/decorators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Convenience decorators for use in fabfiles.
"""
import six
import types
from functools import wraps

Expand Down Expand Up @@ -55,7 +54,7 @@ def inner_decorator(*args, **kwargs):
return func(*args, **kwargs)
_values = values
# Allow for single iterable argument as well as *args
if len(_values) == 1 and not isinstance(_values[0], six.string_types):
if len(_values) == 1 and not isinstance(_values[0], str):
_values = _values[0]
setattr(inner_decorator, attribute, list(_values))
# Don't replace @task new-style task objects with inner_decorator by
Expand Down
6 changes: 2 additions & 4 deletions fabric/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from select import select
from collections import deque

import six

from fabric.state import env, output, win32
from fabric.auth import get_password, set_password
import fabric.network
Expand Down Expand Up @@ -87,7 +85,7 @@ def loop(self):
raise CommandTimeout(timeout=self.timeout)
continue

if six.PY3 is True and isinstance(bytelist, six.binary_type):
if isinstance(bytelist, bytes):
# Note that we have to decode this right away, even if an error
# is thrown only later in the code, because e.g. '' != b'' (see
# first if below).
Expand Down Expand Up @@ -238,7 +236,7 @@ def _get_prompt_response(self):
Iterate through the request prompts dict and return the response and
original request if we find a match
"""
for tup in six.iteritems(env.prompts):
for tup in env.prompts.items():
if _endswith(self.capture, tup[0]):
return tup
return None, None
Expand Down
8 changes: 3 additions & 5 deletions fabric/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
from importlib import import_module
from collections import Mapping

import six

# For checking callables against the API, & easy mocking
from fabric import api, state, colors
from fabric.contrib import console, files, project
Expand Down Expand Up @@ -376,7 +374,7 @@ def _is_task(name, value):

def _sift_tasks(mapping):
tasks, collections = [], []
for name, value in six.iteritems(mapping):
for name, value in mapping.items():
if _is_task(name, value):
tasks.append(name)
elif isinstance(value, Mapping):
Expand Down Expand Up @@ -407,7 +405,7 @@ def _print_docstring(docstrings, name):
if not docstrings:
return False
docstring = crawl(name, state.commands).__doc__
if isinstance(docstring, six.string_types):
if isinstance(docstring, str):
return docstring


Expand Down Expand Up @@ -641,7 +639,7 @@ def main(fabfile_locations=None):
# Handle --hosts, --roles, --exclude-hosts (comma separated string =>
# list)
for key in ['hosts', 'roles', 'exclude_hosts']:
if key in state.env and isinstance(state.env[key], six.string_types):
if key in state.env and isinstance(state.env[key], str):
state.env[key] = state.env[key].split(',')

# Feed the env.tasks : tasks that are asked to be executed.
Expand Down
17 changes: 4 additions & 13 deletions fabric/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import os
import re
import time
import six
import socket
import sys
from io import StringIO

from fabric.auth import get_password, set_password
from fabric.utils import handle_prompt_abort, warn
Expand Down Expand Up @@ -216,7 +216,7 @@ def key_filenames():
from fabric.state import env
keys = env.key_filename
# For ease of use, coerce stringish key filename into list
if isinstance(env.key_filename, six.string_types) or env.key_filename is None:
if isinstance(env.key_filename, str) or env.key_filename is None:
keys = [keys]
# Strip out any empty strings (such as the default value...meh)
keys = list(filter(bool, keys))
Expand Down Expand Up @@ -244,7 +244,7 @@ def key_from_env(passphrase=None):
if output.debug:
sys.stderr.write("Trying to load it as %s\n" % pkey_class)
try:
return pkey_class.from_private_key(six.StringIO(env.key), passphrase)
return pkey_class.from_private_key(StringIO(env.key), passphrase)
except Exception as e:
# File is valid key, but is encrypted: raise it, this will
# cause cxn loop to prompt for passphrase & retry
Expand Down Expand Up @@ -624,10 +624,6 @@ def connect(user, host, port, cache, seek_gateway=True):


def _password_prompt(prompt, stream):
# NOTE: Using encode-to-ascii to prevent (Windows, at least) getpass from
# choking if given Unicode.
if six.PY3 is False:
prompt = prompt.encode('ascii', 'ignore')
return getpass.getpass(prompt, stream)

def prompt_for_password(prompt=None, no_colon=False, stream=None):
Expand Down Expand Up @@ -690,12 +686,7 @@ def host_prompting_wrapper(*args, **kwargs):
handle_prompt_abort("the target host connection string")
prompt = "No hosts found. Please specify (single) " \
"host string for connection: "
# WARNING: do not use six.moves.input, because test cases to not
# overwrite that method with a faked method from Fudge
if six.PY3 is True:
host_string = input(prompt)
else:
host_string = raw_input(prompt) # noqa: F821
host_string = input(prompt)
env.update(to_dict(host_string))
return func(*args, **kwargs)
host_prompting_wrapper.undecorated = func
Expand Down
24 changes: 7 additions & 17 deletions fabric/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os.path
import posixpath
import re
import six
import subprocess
import sys
import time
Expand Down Expand Up @@ -213,12 +212,7 @@ def prompt(text, key=None, default='', validate=None):
value = None
while value is None:
# Get input
# WARNING: do not use six.moves.input, because test cases to not
# overwrite that method with a faked method from Fudge
if six.PY3 is True:
value = input(prompt_str) or default # noqa: F821
else:
value = raw_input(prompt_str) or default # noqa: F821
value = input(prompt_str) or default # noqa: F821
# Handle validation
if validate:
# Callable
Expand Down Expand Up @@ -702,7 +696,7 @@ def _prefix_env_vars(command, local=False):

exports = ' '.join(
'%s%s="%s"' % (set_cmd, k, v if k == 'PATH' else _shell_escape(v))
for k, v in six.iteritems(env_vars)
for k, v in env_vars.items()
)
shell_env_str = '%s%s && ' % (exp_cmd, exports)
else:
Expand Down Expand Up @@ -1225,16 +1219,12 @@ def local(command, capture=False, shell=None, pty=True, encoding='utf-8'):
dev_null.close()

# Handle error condition (deal with stdout being None, too)
if six.PY3:
if encoding == "binary":
out = _stdoutBytes(stdout or b'')
err = stderr or b'' # noqa: E222
else:
out = _stdoutString(stdout.decode(encoding).strip() if stdout else "")
err = stderr.decode(encoding).strip() if stderr else "" # noqa: E222
if encoding == "binary":
out = _stdoutBytes(stdout or b'')
err = stderr or b'' # noqa: E222
else:
out = _stdoutString(stdout.strip() if stdout else "")
err = stderr.strip() if stderr else "" # noqa: E222
out = _stdoutString(stdout.decode(encoding).strip() if stdout else "")
err = stderr.decode(encoding).strip() if stderr else "" # noqa: E222

out.command = given_command
out.real_command = wrapped_command
Expand Down
3 changes: 1 addition & 2 deletions fabric/sftp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import posixpath
import six
import stat
import re
import uuid
Expand Down Expand Up @@ -253,7 +252,7 @@ def put(self, local_path, remote_path, use_sudo,
if (local_is_path and mirror_local_mode) or (mode is not None):
lmode = os.stat(local_path).st_mode if mirror_local_mode else mode
# Cast to octal integer in case of string
if isinstance(lmode, six.string_types):
if isinstance(lmode, str):
lmode = int(lmode, 8)
lmode = lmode & int('0o7777', 8)
rmode = rattrs.st_mode
Expand Down
5 changes: 2 additions & 3 deletions fabric/task_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import six
from fabric.utils import abort, indent
from fabric import state

Expand Down Expand Up @@ -46,7 +45,7 @@ def merge(hosts, roles, exclude, roledefs):
))

# Coerce strings to one-item lists
if isinstance(hosts, six.string_types):
if isinstance(hosts, str):
hosts = [hosts]

# Look up roles, turn into flat list of hosts
Expand Down Expand Up @@ -82,7 +81,7 @@ def parse_kwargs(kwargs):
hosts = []
roles = []
exclude_hosts = []
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
if key == 'host':
hosts = [value]
elif key == 'hosts':
Expand Down
3 changes: 1 addition & 2 deletions fabric/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import inspect
import six
import sys
import textwrap

Expand Down Expand Up @@ -402,7 +401,7 @@ def execute(task, *args, **kwargs):
# This prevents Fabric from continuing on to any other tasks.
# Otherwise, pull in results from the child run.
ran_jobs = jobs.run()
for name, d in six.iteritems(ran_jobs):
for name, d in ran_jobs.items():
if d['exit_code'] != 0:
if isinstance(d['results'], NetworkError) and \
_is_network_error_ignored():
Expand Down
15 changes: 13 additions & 2 deletions fabric/thread_handling.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import threading
import six
import sys


def reraise(tp, value, tb=None):
try:
if value is None:
value = tp()
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
finally:
value = None
tb = None


class ThreadHandler(object):
def __init__(self, name, callable, *args, **kwargs):
# Set up exception handling
Expand All @@ -23,4 +34,4 @@ def wrapper(*args, **kwargs):
def raise_if_needed(self):
if self.exception:
e = self.exception
six.reraise(e[0], e[1], e[2])
reraise(e[0], e[1], e[2])
Loading