Unverified Commit a116df12 authored by Duncan Macleod's avatar Duncan Macleod
Browse files

remove all use of six

and replace with standard python3 syntax
parent aea1745b
Pipeline #458394 passed with stages
in 5 minutes and 28 seconds
......@@ -12,7 +12,6 @@ Build-Depends:
python3-future,
python3-requests,
python3-setuptools,
python3-six,
Standards-Version: 3.9.1
X-Python3-Version: >=3.6
......@@ -26,7 +25,6 @@ Depends:
python3-igwn-auth-utils,
python3-requests,
python3-setuptools,
python3-six,
Provides: ${python3:Provides}
Description: Gravitational-wave Candidate Event Database - Python 3
The gravitational-wave candidate event database (GraceDB) is a prototype
......
......@@ -36,7 +36,6 @@ Requires: python%{python3_pkgversion}-cryptography
Requires: python%{python3_pkgversion}-future
Requires: python%{python3_pkgversion}-igwn-auth-utils
Requires: python%{python3_pkgversion}-requests
Requires: python%{python3_pkgversion}-six
Requires: python%{python3_pkgversion}-safe-netrc
%{?python_provide:%python_provide python%{python3_pkgversion}-%{srcname}}
%description -n python%{python3_pkgversion}-%{srcname}
......
from __future__ import absolute_import, print_function
import json
import os
import six
import sys
import textwrap
from requests import Response
......@@ -226,7 +225,7 @@ def main(args=None):
status=response.status_code, reason=response.reason))
elif isinstance(response, dict):
print(json.dumps(response, indent=4))
elif isinstance(response, six.string_types):
elif isinstance(response, str):
print(response)
elif isinstance(response, bytes):
print(response.decode())
......
import argparse
from six import with_metaclass
import sys
from . import command_registry
......@@ -179,9 +178,7 @@ class RegisteredCommandMeta(type):
return cls
class RegisteredCommandBase(
with_metaclass(RegisteredCommandMeta, CommandBase)
):
class RegisteredCommandBase(CommandBase, metaclass=RegisteredCommandMeta):
@classmethod
def _register(cls):
......
import six
import textwrap
from .base import RegisteredSubCommandBase
......@@ -144,8 +143,7 @@ class InfoCommand(RegisteredSubCommandBase):
# Convert dict to list of key (value) strings
if isinstance(data, dict):
data = ['{k} ({v})'.format(k=k, v=v) for k, v in
six.iteritems(data)]
data = ['{k} ({v})'.format(k=k, v=v) for k, v in data.items(data)]
# Join list into comma-separated string
if isinstance(data, list):
......
......@@ -3,7 +3,6 @@
import datetime
import pytest
import shlex
import six
try:
from unittest import mock
except ImportError:
......@@ -302,7 +301,7 @@ VOEVENT_TEST_DICT = {
'mass_gap': [None, 0.7],
}
# Convert into a list of tuples
VOEVENT_TEST_DATA = zip(*list(six.itervalues(VOEVENT_TEST_DICT)))
VOEVENT_TEST_DATA = zip(*VOEVENT_TEST_DICT.values())
@pytest.mark.parametrize(",".join(list(VOEVENT_TEST_DICT)), # noqa: E302
VOEVENT_TEST_DATA)
def test_create_voevent_subcommand(
......
......@@ -2,7 +2,6 @@
# Ex: 'gracedb confirm_as_gw' because it has no subcommands.
# NOT 'gracedb add' because it has subcommands like 'gracedb add event'
import pytest
import six
try:
from unittest import mock
except ImportError:
......@@ -164,7 +163,7 @@ def test_ping_subcommand(CLI):
@pytest.mark.parametrize(
"cmd,cli_func",
list(six.iteritems(InfoCommand.options))
list(InfoCommand.options.items())
)
def test_info_subcommand(CLI, cmd, cli_func):
"""Test info subcommand"""
......
import re
import pytest
import six
try:
from unittest import mock
except ImportError:
......@@ -71,7 +70,7 @@ def test_cli_client_setup(CLI):
'service-url': 'testserver.com',
'creds': 'cert_file,key_file',
}
args = ['--{k}={v}'.format(k=k, v=v) for k, v in six.iteritems(arg_dict)]
args = ['--{k}={v}'.format(k=k, v=v) for k, v in arg_dict.items()]
client_class = 'ligo.gracedb.cli.client.CommandLineClient'
with mock.patch(client_class) as mock_client:
......
......@@ -44,7 +44,7 @@ log.warn("this is a warning")
import logging
import sys
import traceback
from six.moves.queue import Queue
from queue import Queue
from threading import Lock, Thread
__all__ = ('GraceDbLogHandler',)
......
......@@ -18,11 +18,8 @@
from io import open
# import mimetypes
import os
import six
import sys
from six.moves import map
from six.moves.urllib.parse import urlencode
from urllib.parse import urlparse
from urllib.parse import urlencode, urlparse
from .alias import alias, aliased
from .exceptions import HTTPError
......@@ -116,7 +113,7 @@ class GraceDb(GraceDBClient):
# Check version type
if (api_version is not None and not
isinstance(api_version, six.string_types)):
isinstance(api_version, str)):
# Raise error is not a string
raise TypeError('api_version should be a string')
......@@ -274,7 +271,7 @@ class GraceDb(GraceDBClient):
# Loop over code_dict items, if we match either the key or
# value (case-insensitive), return the code.
input_lower = input_value.lower()
for code, display in six.iteritems(code_dict):
for code, display in code_dict.items():
if (input_lower == code.lower()
or input_lower == display.lower()):
return code
......@@ -336,7 +333,7 @@ class GraceDb(GraceDBClient):
# Process label args - convert non-empty strings to list
# to ensure consistent processing
if labels is not None:
if isinstance(labels, six.string_types):
if isinstance(labels, str):
# Convert to list
labels = [labels]
elif isinstance(labels, list):
......@@ -370,7 +367,7 @@ class GraceDb(GraceDBClient):
fields.update({'labels': labels})
# Update fields with additional keyword arguments
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
fields.update({key: value})
# Assemble files dict and encode.
......@@ -626,11 +623,11 @@ class GraceDb(GraceDBClient):
# Process label args - convert non-empty strings to list
# to ensure consistent processing
if labels:
if isinstance(labels, six.string_types):
if isinstance(labels, str):
labels = [labels]
elif isinstance(labels, (list, tuple)):
# Validate each entry
if any(not isinstance(label, six.string_types)
if any(not isinstance(label, str)
for label in labels):
err_msg = "One of the provided labels is not a string"
raise TypeError(err_msg)
......@@ -643,10 +640,10 @@ class GraceDb(GraceDBClient):
raise ValueError(("Label '{0}' does not exist in the "
"database").format(label))
if events:
if isinstance(events, six.string_types):
if isinstance(events, str):
events = [events]
elif isinstance(events, (list, tuple)):
if any([not isinstance(e, six.string_types) for e in events]):
if any([not isinstance(e, str) for e in events]):
err_msg = \
"One of the provided event graceids is not a string"
raise TypeError(err_msg)
......@@ -655,7 +652,7 @@ class GraceDb(GraceDBClient):
.format(type(events)))
# Validate category, convert to short form if necessary
if not isinstance(category, six.string_types):
if not isinstance(category, str):
err_msg = "category arg is {0}, should be a string".format(
type(category))
raise TypeError(err_msg)
......@@ -665,7 +662,7 @@ class GraceDb(GraceDBClient):
# superevent category
if not category:
raise ValueError("category must be one of: {0}".format(
list(six.itervalues(self.superevent_categories))))
list(self.superevent_categories.items())))
# Set up request body for POST
request_body = {
......@@ -942,7 +939,7 @@ class GraceDb(GraceDBClient):
... print(s['superevent_id'])
"""
# If columns is a comma-separated string, split it to a list
if isinstance(columns, six.string_types):
if isinstance(columns, str):
columns = columns.split(',')
# If orderby is a list (should be), convert it to a comma-separated
......@@ -1762,7 +1759,7 @@ class GraceDb(GraceDBClient):
voevent_type = self._getCode(voevent_type.lower(), self.voevent_types)
if not voevent_type:
raise ValueError("voevent_type must be one of: {0}".format(
", ".join(list(six.itervalues(self.voevent_types)))))
", ".join(self.voevent_types.values())))
# Require skymaps for 'update' and 'initial'
if voevent_type == 'IN':
......
......@@ -2,7 +2,6 @@ try:
from unittest import mock
except ImportError: # python < 3
import mock
import six
import pytest
......@@ -69,7 +68,7 @@ def test_create_event(safe_client, group, pipeline, search, offline, labels):
else:
assert 'search' not in body
if labels:
if isinstance(labels, six.string_types):
if isinstance(labels, str):
labels = [labels]
req_labels = []
for t in call_kwargs['data']:
......@@ -330,11 +329,11 @@ def test_creation_args(
assert body['preferred_event'] == preferred_event
assert body['category'] == category
if events:
if isinstance(events, six.string_types):
if isinstance(events, str):
events = [events]
assert body['events'] == events
if labels:
if isinstance(labels, six.string_types):
if isinstance(labels, str):
labels = [labels]
assert body['labels'] == labels
......
......@@ -2,7 +2,6 @@ try:
from unittest import mock
except ImportError: # python < 3
import mock
import six
import pytest
......@@ -109,11 +108,11 @@ def test_creation_args(
assert body['preferred_event'] == preferred_event
assert body['category'] == category
if events:
if isinstance(events, six.string_types):
if isinstance(events, str):
events = [events]
assert body['events'] == events
if labels:
if isinstance(labels, six.string_types):
if isinstance(labels, str):
labels = [labels]
assert body['labels'] == labels
......
......@@ -146,7 +146,7 @@ def test_create_voevent_bad_voevent_type(safe_client):
mock_si_dict = {'voevent-types': {'PR': 'preliminary'}}
err_msg = "voevent_type must be one of: {vts}".format(
vts=",'".join(list(mock_si_dict['voevent-types'].values())))
vts=",'".join(mock_si_dict['voevent-types'].values()))
with mock.patch(si_prop, mock_si_dict), \
mock.patch(template_prop, mock_template_dict): # noqa: E127
with pytest.raises(ValueError, match=err_msg):
......
import re
import six
import mimetypes
import requests
from functools import wraps
......@@ -26,7 +25,7 @@ def event_or_superevent(func):
# If a string, converts to list for ease of processing
def handle_str_or_list_arg(arg, arg_name):
if arg:
if isinstance(arg, six.string_types):
if isinstance(arg, str):
arg = [arg]
elif isinstance(arg, list):
pass
......
......@@ -99,7 +99,6 @@ setup(
packages=find_packages(),
classifiers=CLASSIFIERS,
install_requires=['future>=0.15.0',
'six>=1.9.0',
'cryptography>=1.7.2, <=36.0.2',
'requests>=2.6.0',
'igwn-auth-utils>=0.3.1',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment