Skip to content

Commit

Permalink
Round #2 of removing string_types
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Jun 29, 2019
1 parent e32a873 commit 717b593
Show file tree
Hide file tree
Showing 22 changed files with 26 additions and 58 deletions.
12 changes: 5 additions & 7 deletions src/python/pants/backend/jvm/targets/jvm_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from abc import ABCMeta
from hashlib import sha1

from future.utils import string_types

from pants.backend.jvm.targets.jvm_target import JvmTarget
from pants.base.exceptions import TargetDefinitionException
from pants.base.payload import Payload
Expand All @@ -20,8 +18,8 @@ class JarRule(FingerprintedMixin, metaclass=ABCMeta):

def __init__(self, apply_pattern, payload=None):
self.payload = payload or Payload()
if not isinstance(apply_pattern, string_types):
raise ValueError('The supplied apply_pattern is not a string, given: {}'
if not isinstance(apply_pattern, str):
raise ValueError('The supplied apply_pattern is not a str, given: {}'
.format(apply_pattern))
try:
self._apply_pattern = re.compile(apply_pattern)
Expand Down Expand Up @@ -63,7 +61,7 @@ def __init__(self, path):
:param string path: The path of the duplicate entry.
"""
assert path and isinstance(path, string_types), 'A non-empty path must be supplied.'
assert path and isinstance(path, str), 'A non-empty path must be supplied.'
super(Duplicate.Error, self).__init__('Duplicate entry encountered for path {}'.format(path))
self._path = path

Expand Down Expand Up @@ -262,7 +260,7 @@ def __init__(self, entries=None):
if not isinstance(entries, dict):
raise self.ExpectedDictionaryError("entries must be a dictionary of strings.")
for key in entries.keys():
if not isinstance(key, string_types):
if not isinstance(key, str):
raise self.ExpectedDictionaryError(
"entries must be dictionary of strings, got key {} type {}"
.format(key, type(key).__name__))
Expand Down Expand Up @@ -337,7 +335,7 @@ def __init__(self,
binary. Example: ['-Dexample.property=1', '-DMyFlag', '-Xmx4G'] If unspecified, no extra jvm options will be added.
"""
self.address = address # Set in case a TargetDefinitionException is thrown early
if main and not isinstance(main, string_types):
if main and not isinstance(main, str):
raise TargetDefinitionException(self, 'main must be a fully qualified classname')
if deploy_jar_rules and not isinstance(deploy_jar_rules, JarRules):
raise TargetDefinitionException(self,
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ python_library(
name = 'deprecated',
sources = ['deprecated.py'],
dependencies = [
'3rdparty/python:six',
':revision',
'src/python/pants:version',
'src/python/pants/util:memo',
Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/base/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from contextlib import contextmanager
from functools import wraps

import six
from future.utils import PY2
from packaging.version import InvalidVersion, Version

Expand Down Expand Up @@ -68,7 +67,7 @@ def validate_deprecation_semver(version_string, version_description):
"""
if version_string is None:
raise MissingSemanticVersionError('The {} must be provided.'.format(version_description))
if not isinstance(version_string, six.string_types):
if not isinstance(version_string, str):
raise BadSemanticVersionError('The {} must be a version string.'.format(version_description))
try:
# NB: packaging will see versions like 1.a.0 as 1a0, and are "valid"
Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/build_graph/app_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from collections import OrderedDict, namedtuple
from hashlib import sha1

import six
from twitter.common.dirutil import Fileset

from pants.base.build_environment import get_buildroot
Expand Down Expand Up @@ -150,7 +149,7 @@ def __call__(self, rel_path=None, mapper=None, relative_to=None, fileset=None):
# A fileset is either a glob, a string or a list of strings.
if isinstance(fileset, FilesetWithSpec):
pass
elif isinstance(fileset, six.string_types):
elif isinstance(fileset, str):
fileset = [fileset]
else:
fileset = assert_list(fileset, key_arg='fileset')
Expand Down
4 changes: 1 addition & 3 deletions src/python/pants/build_graph/build_file_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from abc import abstractmethod
from collections import defaultdict

import six

from pants.base.build_file_target_factory import BuildFileTargetFactory
from pants.build_graph.target import Target
from pants.util.memo import memoized_property
Expand Down Expand Up @@ -107,7 +105,7 @@ def _is_target_macro_factory(obj):

@classmethod
def _validate_alias(cls, category, alias, obj):
if not isinstance(alias, six.string_types):
if not isinstance(alias, str):
raise TypeError('Aliases must be strings, given {category} entry {alias!r} of type {typ} as '
'the alias of {obj}'
.format(category=category, alias=alias, typ=type(alias).__name__, obj=obj))
Expand Down
4 changes: 1 addition & 3 deletions src/python/pants/build_graph/import_remote_sources_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from abc import ABCMeta, abstractmethod

from future.utils import string_types

from pants.build_graph.address_lookup_error import AddressLookupError
from pants.build_graph.target import Target
from pants.util.memo import memoized_property
Expand Down Expand Up @@ -70,7 +68,7 @@ def imported_target_specs(cls, kwargs=None, payload=None):

specs = []
for item in target_representation.get(field, ()):
if not isinstance(item, string_types):
if not isinstance(item, str):
raise cls.ExpectedAddressError(
'expected imports to contain string addresses, got {obj} (type: {found_class}) instead.'
.format(obj=item, found_class=type(item).__name__)
Expand Down
6 changes: 2 additions & 4 deletions src/python/pants/build_graph/intermediate_target_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from abc import ABC
from hashlib import sha1

from future.utils import string_types

from pants.base.exceptions import TargetDefinitionException
from pants.build_graph.address import Address

Expand Down Expand Up @@ -37,8 +35,8 @@ def _create_intermediate_target(self, address, suffix):
:param string suffix: A string used as a suffix of the intermediate target name.
:returns: The address of a synthetic intermediary target.
"""
if not isinstance(address, string_types):
raise self.ExpectedAddressError("Expected string address argument, got type {type}"
if not isinstance(address, str):
raise self.ExpectedAddressError("Expected str address argument, got type {type}"
.format(type=type(address)))

address = Address.parse(address, self._parse_context.rel_path)
Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/build_graph/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import weakref
from hashlib import sha1

from six import string_types
from twitter.common.collections import OrderedSet

from pants.base.build_environment import get_buildroot
Expand Down Expand Up @@ -371,7 +370,7 @@ def tags(self):
"""
return self._tags

def assert_list(self, putative_list, expected_type=string_types, key_arg=None):
def assert_list(self, putative_list, expected_type=str, key_arg=None):
"""
:API: public
"""
Expand Down
4 changes: 1 addition & 3 deletions src/python/pants/build_graph/target_addressable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import logging

from six import string_types

from pants.base.exceptions import TargetDefinitionException
from pants.build_graph.addressable import Addressable

Expand Down Expand Up @@ -57,7 +55,7 @@ def __init__(self, alias, target_type, *args, **kwargs):
raise TargetDefinitionException(target=self, msg=msg)

for dep_spec in self.dependency_specs:
if not isinstance(dep_spec, string_types):
if not isinstance(dep_spec, str):
msg = ('dependencies passed to Target constructors must be strings. {dep_spec} is not'
' a string. Target type was: {target_type}.'
.format(target_type=self.addressed_type, dep_spec=dep_spec))
Expand Down
5 changes: 1 addition & 4 deletions src/python/pants/build_graph/target_scopes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Copyright 2016 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).


from future.utils import string_types

from pants.build_graph.intermediate_target_factory import IntermediateTargetFactoryBase


Expand All @@ -24,7 +21,7 @@ def _parse(cls, scope):
"""
if not scope:
return ('default',)
if isinstance(scope, string_types):
if isinstance(scope, str):
scope = scope.split(' ')
scope = {str(s).lower() for s in scope if s}
return scope or ('default',)
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/engine/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ python_library(
sources=['build_files.py'],
dependencies=[
'3rdparty/python:future',
'3rdparty/python:six',
':addressable',
':fs',
':mapper',
Expand Down
4 changes: 1 addition & 3 deletions src/python/pants/engine/addressable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from collections.abc import MutableMapping, MutableSequence
from functools import update_wrapper

from future.utils import string_types

from pants.build_graph.address import Address, BuildFileAddress
from pants.engine.objects import Collection, Resolvable, Serializable
from pants.util.objects import TypeConstraintError
Expand Down Expand Up @@ -150,7 +148,7 @@ def _checked_value(self, instance, value):
if value is None:
return None

if isinstance(value, (string_types, Address, Resolvable)):
if isinstance(value, (str, Address, Resolvable)):
return value

# Support untyped dicts that we deserialize on-demand here into the required type.
Expand Down
5 changes: 2 additions & 3 deletions src/python/pants/engine/build_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from collections.abc import MutableMapping, MutableSequence
from os.path import dirname, join

import six
from future.utils import raise_from
from twitter.common.collections import OrderedSet

Expand Down Expand Up @@ -92,7 +91,7 @@ def hydrate_struct(address_mapper, address):

inline_dependencies = []
def maybe_append(outer_key, value):
if isinstance(value, six.string_types):
if isinstance(value, str):
if outer_key != 'dependencies':
inline_dependencies.append(Address.parse(value,
relative_to=address.spec_path,
Expand Down Expand Up @@ -121,7 +120,7 @@ def collect_inline_dependencies(item):
dependencies = [d.value for d in hydrated_inline_dependencies]

def maybe_consume(outer_key, value):
if isinstance(value, six.string_types):
if isinstance(value, str):
if outer_key == 'dependencies':
# Don't recurse into the dependencies field of a Struct, since those will be explicitly
# requested by tasks. But do ensure that their addresses are absolute, since we're
Expand Down
3 changes: 0 additions & 3 deletions src/python/pants/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ python_library(
sources = ['executor.py'],
dependencies = [
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python:six',
'src/python/pants/base:build_environment',
'src/python/pants/util:contextutil',
'src/python/pants/util:dirutil',
Expand Down Expand Up @@ -50,8 +49,6 @@ python_library(
dependencies = [
':executor',
':nailgun_client',
'3rdparty/python:future',
'3rdparty/python:six',
'3rdparty/python/twitter/commons:twitter.common.collections',
'src/python/pants/base:build_environment',
'src/python/pants/pantsd:process_manager',
Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/java/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from abc import ABC, abstractmethod
from contextlib import contextmanager

from six import string_types
from twitter.common.collections import maybe_list

from pants.util.contextutil import environment_as
Expand All @@ -26,7 +25,7 @@ class Executor(ABC):
@staticmethod
def _scrub_args(classpath, main, jvm_options, args):
classpath = maybe_list(classpath)
if not isinstance(main, string_types) or not main:
if not isinstance(main, str) or not main:
raise ValueError('A non-empty main classname is required, given: {}'.format(main))
jvm_options = maybe_list(jvm_options or ())
args = maybe_list(args or ())
Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/java/nailgun_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import time
from contextlib import closing

from future.utils import string_types
from twitter.common.collections import maybe_list

from pants.base.build_environment import get_buildroot
Expand Down Expand Up @@ -87,7 +86,7 @@ def __init__(self, identity, workdir, nailgun_classpath, distribution,
process_name=self._PROCESS_NAME,
metadata_base_dir=metadata_base_dir)

if not isinstance(workdir, string_types):
if not isinstance(workdir, str):
raise ValueError('Workdir must be a path string, not: {workdir}'.format(workdir=workdir))

self._identity = identity
Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/option/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from collections import defaultdict

import Levenshtein
import six
import yaml

from pants.base.deprecated import validate_deprecation_semver, warn_or_error
Expand Down Expand Up @@ -54,7 +53,7 @@ class MutuallyExclusiveOptionError(ParseError):

@staticmethod
def _ensure_bool(s):
if isinstance(s, six.string_types):
if isinstance(s, str):
if s.lower() == 'true':
return True
elif s.lower() == 'false':
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/source/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
python_library(
sources = globs('*.py', exclude=[globs('payload_fields.py')]),
dependencies=[
'3rdparty/python:six',
'3rdparty/python/twitter/commons:twitter.common.dirutil',
'src/python/pants/base:build_environment',
'src/python/pants/base:payload_field',
Expand Down
7 changes: 3 additions & 4 deletions src/python/pants/source/wrapped_globs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from abc import ABC, abstractmethod
from hashlib import sha1

from six import string_types
from twitter.common.dirutil.fileset import Fileset

from pants.base.build_environment import get_buildroot
Expand Down Expand Up @@ -180,7 +179,7 @@ def create_fileset_with_spec(cls, rel_path, *patterns, **kwargs):
NB: this argument is contained within **kwargs!
"""
for pattern in patterns:
if not isinstance(pattern, string_types):
if not isinstance(pattern, str):
raise ValueError("Expected string patterns for {}: got {}".format(cls.__name__, patterns))

raw_exclude = kwargs.pop('exclude', [])
Expand Down Expand Up @@ -233,13 +232,13 @@ def _is_glob_dir_outside_root(glob, root):

@staticmethod
def process_raw_exclude(raw_exclude):
if isinstance(raw_exclude, string_types):
if isinstance(raw_exclude, str):
raise ValueError("Expected exclude parameter to be a list of globs, lists, or strings,"
" but was a string: {}".format(raw_exclude))

# You can't subtract raw strings from globs
def ensure_string_wrapped_in_list(element):
if isinstance(element, string_types):
if isinstance(element, str):
return [element]
else:
return element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def test_jar_rule(self):
self.assertEqual('Skip(apply_pattern=foo)', repr(skip_rule))

def test_invalid_apply_pattern(self):
with self.assertRaisesRegexp(ValueError, r'The supplied apply_pattern is not a string'):
with self.assertRaisesRegexp(ValueError, r'The supplied apply_pattern is not a str'):
Skip(None)
with self.assertRaisesRegexp(ValueError, r'The supplied apply_pattern is not a string'):
with self.assertRaisesRegexp(ValueError, r'The supplied apply_pattern is not a str'):
Duplicate(None, Duplicate.SKIP)
with self.assertRaisesRegexp(ValueError, r'The supplied apply_pattern: \) is not a valid'):
Skip(r')')
Expand Down
1 change: 0 additions & 1 deletion tests/python/pants_test/engine/examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ python_library(
name='parsers',
sources=['parsers.py'],
dependencies=[
'3rdparty/python:six',
'src/python/pants/build_graph',
'src/python/pants/engine:objects',
'src/python/pants/engine:parser',
Expand Down
4 changes: 1 addition & 3 deletions tests/python/pants_test/engine/examples/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from json.decoder import JSONDecoder
from json.encoder import JSONEncoder

import six

from pants.build_graph.address import Address
from pants.engine.objects import Resolvable, Serializable
from pants.engine.parser import ParseError, Parser
Expand Down Expand Up @@ -40,7 +38,7 @@ def __init__(self, symbol_table):
self.symbol_table = symbol_table

def _as_type(self, type_or_name):
return _import(type_or_name) if isinstance(type_or_name, six.string_types) else type_or_name
return _import(type_or_name) if isinstance(type_or_name, str) else type_or_name

@staticmethod
def _object_decoder(obj, symbol_table):
Expand Down

0 comments on commit 717b593

Please sign in to comment.