Skip to content

Commit

Permalink
Remove text_type and binary_type wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Jun 28, 2019
1 parent c41dee9 commit 25dc22f
Show file tree
Hide file tree
Showing 47 changed files with 134 additions and 226 deletions.
8 changes: 3 additions & 5 deletions contrib/go/src/python/pants/contrib/go/tasks/go_test.py
Expand Up @@ -3,7 +3,6 @@

from contextlib import contextmanager

from future.utils import text_type
from pants.base.build_environment import get_buildroot
from pants.base.workunit import WorkUnitLabel
from pants.task.testrunner_task_mixin import PartitionedTestRunnerTaskMixin, TestResult
Expand Down Expand Up @@ -52,8 +51,8 @@ def _validate_target(self, target):
self.ensure_workspace(target)

class _GoTestTargetInfo(datatype([
('import_path', text_type),
('gopath', text_type),
('import_path', str),
('gopath', str),
])): pass

def _generate_args_for_targets(self, targets):
Expand All @@ -62,8 +61,7 @@ def _generate_args_for_targets(self, targets):
reconstructed for spawning test commands regardless of how the targets are partitioned.
"""
return {
t: self._GoTestTargetInfo(import_path=text_type(t.import_path),
gopath=text_type(self.get_gopath(t)))
t: self._GoTestTargetInfo(import_path=t.import_path, gopath=self.get_gopath(t))
for t in targets
}

Expand Down
4 changes: 1 addition & 3 deletions src/python/pants/backend/graph_info/tasks/cloc.py
Expand Up @@ -3,8 +3,6 @@

import os

from future.utils import text_type

from pants.backend.graph_info.subsystems.cloc_binary import ClocBinary
from pants.base.workunit import WorkUnitLabel
from pants.engine.fs import FilesContent, PathGlobs, PathGlobsAndRoot
Expand Down Expand Up @@ -48,7 +46,7 @@ def console_output(self, targets):
list_file_snapshot = self.context._scheduler.capture_snapshots((
PathGlobsAndRoot(
PathGlobs(('input_files_list',)),
text_type(tmpdir),
tmpdir,
),
))[0]

Expand Down
1 change: 0 additions & 1 deletion src/python/pants/backend/jvm/subsystems/BUILD
Expand Up @@ -132,7 +132,6 @@ python_library(
name = 'zinc',
sources = ['zinc.py'],
dependencies = [
'3rdparty/python:future',
':dependency_context',
':jvm_tool_mixin',
':shader',
Expand Down
6 changes: 2 additions & 4 deletions src/python/pants/backend/jvm/subsystems/zinc.py
Expand Up @@ -5,8 +5,6 @@
from hashlib import sha1
from threading import Lock

from future.utils import text_type

from pants.backend.jvm.subsystems.dependency_context import DependencyContext
from pants.backend.jvm.subsystems.java import Java
from pants.backend.jvm.subsystems.jvm_tool_mixin import JvmToolMixin
Expand Down Expand Up @@ -323,7 +321,7 @@ def _run_bootstrapper(self, bridge_jar, context):
]
input_jar_snapshots = context._scheduler.capture_snapshots((PathGlobsAndRoot(
PathGlobs(tuple([bootstrapper] + bootstrapper_args[1::2])),
text_type(get_buildroot()),
get_buildroot(),
),))
argv = tuple(['.jdk/bin/java'] +
['-cp', bootstrapper, Zinc.ZINC_BOOTSTRAPER_MAIN] +
Expand Down Expand Up @@ -377,7 +375,7 @@ def compile_compiler_bridge(self, context):
else:
bridge_jar_snapshot = context._scheduler.capture_snapshots((PathGlobsAndRoot(
PathGlobs((self._relative_to_buildroot(bridge_jar),)),
text_type(get_buildroot())
get_buildroot()
),))[0]
bridge_jar_digest = bridge_jar_snapshot.directory_digest
return ClasspathEntry(bridge_jar, bridge_jar_digest)
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/backend/jvm/tasks/jvm_compile/javac/BUILD
Expand Up @@ -4,7 +4,6 @@
python_library(
dependencies = [
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python:future',
'src/python/pants/backend/jvm/subsystems:java',
'src/python/pants/backend/jvm/subsystems:jvm_platform',
'src/python/pants/backend/jvm/subsystems:shader',
Expand Down
Expand Up @@ -5,8 +5,6 @@
import os
import subprocess

from future.utils import text_type

from pants.backend.jvm import argfile
from pants.backend.jvm.subsystems.java import Java
from pants.backend.jvm.subsystems.jvm_platform import JvmPlatform
Expand Down Expand Up @@ -173,7 +171,7 @@ def compile(self, ctx, args, dependency_classpath, upstream_analysis,
raise TaskError('javac exited with return code {rc}'.format(rc=return_code))
self.context._scheduler.materialize_directories((
DirectoryToMaterialize(
text_type(ctx.classes_dir.path),
ctx.classes_dir.path,
self.post_compile_extra_resources_digest(ctx, prepend_post_merge_relative_path=False)),
))

Expand Down Expand Up @@ -215,12 +213,8 @@ def _execute_hermetic_compile(self, cmd, ctx):
for f in input_snapshot.files if f.endswith('.java')
)

# TODO(#6071): Our ExecuteProcessRequest expects a specific string type for arguments,
# which py2 doesn't default to. This can be removed when we drop python 2.
argv = [text_type(arg) for arg in cmd]

exec_process_request = ExecuteProcessRequest(
argv=tuple(argv),
argv=tuple(cmd),
input_files=input_snapshot.directory_digest,
output_files=output_files,
description='Compiling {} with javac'.format(ctx.target.address.spec),
Expand All @@ -238,5 +232,5 @@ def _execute_hermetic_compile(self, cmd, ctx):
])
classes_directory = ctx.classes_dir.path
self.context._scheduler.materialize_directories((
DirectoryToMaterialize(text_type(classes_directory), merged_directories),
DirectoryToMaterialize(classes_directory, merged_directories),
))
4 changes: 2 additions & 2 deletions src/python/pants/backend/jvm/tasks/jvm_compile/jvm_compile.py
Expand Up @@ -5,7 +5,7 @@
import os
from multiprocessing import cpu_count

from future.utils import PY2, PY3, text_type
from future.utils import PY2, PY3
from twitter.common.collections import OrderedSet

from pants.backend.jvm.subsystems.dependency_context import DependencyContext
Expand Down Expand Up @@ -902,7 +902,7 @@ def find_libs_path_globs(self, names):
libs_unrooted = [self._unroot_lib_path(l) for l in libs_abs]
path_globs = PathGlobsAndRoot(
PathGlobs(tuple(libs_unrooted)),
text_type(self._underlying.home))
self._underlying.home)
return (libs_unrooted, path_globs)

@property
Expand Down
Expand Up @@ -6,7 +6,7 @@
import os
import re

from future.utils import PY3, text_type
from future.utils import PY3

from pants.backend.jvm.subsystems.dependency_context import DependencyContext # noqa
from pants.backend.jvm.subsystems.rsc import Rsc
Expand Down Expand Up @@ -571,13 +571,10 @@ def _runtool_hermetic(self, main, tool_name, distribution, input_digest, ctx):
additional_snapshots = [native_image_snapshot]
initial_args = [native_image_path]
else:
# TODO(#6071): Our ExecuteProcessRequest expects a specific string type for arguments,
# which py2 doesn't default to. This can be removed when we drop python 2.
str_jvm_options = [text_type(opt) for opt in self.get_options().jvm_options]
additional_snapshots = []
initial_args = [
distribution.java,
] + str_jvm_options + [
] + self.get_options().jvm_options + [
'-cp', os.pathsep.join(tool_classpath),
main,
]
Expand All @@ -596,7 +593,7 @@ def _runtool_hermetic(self, main, tool_name, distribution, input_digest, ctx):
if pathglobs:
root = PathGlobsAndRoot(
PathGlobs(tuple(pathglobs)),
text_type(get_buildroot()))
get_buildroot())
# dont capture snapshot, if pathglobs is empty
path_globs_input_digest = self.context._scheduler.capture_snapshots((root,))[0].directory_digest

Expand All @@ -616,7 +613,7 @@ def _runtool_hermetic(self, main, tool_name, distribution, input_digest, ctx):
# TODO: These should always be unicodes
# Since this is always hermetic, we need to use `underlying.home` because
# ExecuteProcessRequest requires an existing, local jdk location.
jdk_home=text_type(distribution.underlying_home),
jdk_home=distribution.underlying_home,
)
res = self.context.execute_process_synchronously_without_raising(
epr,
Expand All @@ -635,7 +632,7 @@ def _runtool_hermetic(self, main, tool_name, distribution, input_digest, ctx):
self.context._scheduler.materialize_directories((
DirectoryToMaterialize(
# NB the first element here is the root to materialize into, not the dir to snapshot
text_type(get_buildroot()),
get_buildroot(),
res.output_directory_digest),
))

Expand Down
1 change: 0 additions & 1 deletion src/python/pants/backend/jvm/tasks/jvm_compile/zinc/BUILD
Expand Up @@ -4,7 +4,6 @@
python_library(
dependencies = [
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python:future',
'src/python/pants/backend/jvm/subsystems:java',
'src/python/pants/backend/jvm/subsystems:jvm_platform',
'src/python/pants/backend/jvm/subsystems:scala_platform',
Expand Down
Expand Up @@ -2,8 +2,6 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).


from future.utils import text_type

from pants.backend.jvm.tasks.jvm_compile.analysis import Analysis
from pants.backend.jvm.zinc.zinc_analysis import ZincAnalysis as UnderlyingAnalysis

Expand Down Expand Up @@ -43,6 +41,3 @@ def __hash__(self):

def __str__(self):
return str(self.underlying_analysis)

def __unicode__(self):
return text_type(self.underlying_analysis)
Expand Up @@ -10,8 +10,6 @@
from contextlib import closing
from xml.etree import ElementTree

from future.utils import text_type

from pants.backend.jvm.subsystems.java import Java
from pants.backend.jvm.subsystems.jvm_platform import JvmPlatform
from pants.backend.jvm.subsystems.scala_platform import ScalaPlatform
Expand Down Expand Up @@ -456,9 +454,6 @@ def _compile_hermetic(self, jvm_options, ctx, classes_dir, jar_file,
])

argv = image_specific_argv + ['@{}'.format(argfile_snapshot.files[0])]
# TODO(#6071): Our ExecuteProcessRequest expects a specific string type for arguments,
# which py2 doesn't default to. This can be removed when we drop python 2.
argv = [text_type(arg) for arg in argv]

merged_input_digest = self.context._scheduler.merge_directories(
tuple(s.directory_digest for s in snapshots) +
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/backend/native/targets/BUILD
Expand Up @@ -4,7 +4,6 @@

python_library(
dependencies=[
'3rdparty/python:future',
'src/python/pants/base:build_environment',
'src/python/pants/base:exceptions',
'src/python/pants/base:payload',
Expand Down
Expand Up @@ -3,8 +3,6 @@

import re

from future.utils import text_type

from pants.base.hash_utils import stable_json_sha1
from pants.base.payload import Payload
from pants.base.payload_field import PayloadField
Expand All @@ -22,9 +20,9 @@ def _compute_fingerprint(self):


class ConanRequirement(datatype([
('pkg_spec', text_type),
('include_relpath', text_type),
('lib_relpath', text_type),
('pkg_spec', str),
('include_relpath', str),
('lib_relpath', str),
('lib_names', tuple),
])):
"""A specification for a conan package to be resolved against a remote repository.
Expand Down Expand Up @@ -54,9 +52,9 @@ def __new__(cls, pkg_spec, include_relpath=None, lib_relpath=None, lib_names=Non
"""
return super().__new__(
cls,
text_type(pkg_spec),
include_relpath=text_type(include_relpath or 'include'),
lib_relpath=text_type(lib_relpath or 'lib'),
pkg_spec,
include_relpath=include_relpath or 'include',
lib_relpath=lib_relpath or 'lib',
lib_names=tuple(lib_names or ()))

def parse_conan_stdout_for_pkg_sha(self, stdout):
Expand Down
Expand Up @@ -4,8 +4,6 @@
import itertools
import re

from future.utils import text_type

from pants.base.exiter import PANTS_FAILED_EXIT_CODE, PANTS_SUCCEEDED_EXIT_CODE
from pants.engine.console import Console
from pants.engine.fs import Digest, FilesContent
Expand Down Expand Up @@ -83,7 +81,7 @@ def get_multi_matcher(self):


class RegexMatchResult(datatype([
('path', text_type), ('matching', tuple), ('nonmatching', tuple)
('path', str), ('matching', tuple), ('nonmatching', tuple)
])):
"""The result of running regex matches on a source file."""

Expand Down
10 changes: 3 additions & 7 deletions src/python/pants/backend/python/rules/python_test_runner.py
@@ -1,9 +1,6 @@
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).


from future.utils import text_type

from pants.backend.python.rules.inject_init import InjectedInitDigest
from pants.backend.python.rules.resolve_requirements import (ResolvedRequirementsPex,
ResolveRequirementsRequest)
Expand Down Expand Up @@ -58,9 +55,8 @@ def run_python_test(test_target, pytest, python_setup, source_root_config, subpr
resolved_requirements_pex = yield Get(
ResolvedRequirementsPex, ResolveRequirementsRequest(
output_filename=output_pytest_requirements_pex_filename,
# TODO(#7061): This text_type() wrapping can be removed after we drop py2!
requirements=tuple(sorted(text_type(requirement) for requirement in all_requirements)),
interpreter_constraints=tuple(sorted(text_type(constraint) for constraint in interpreter_constraints)),
requirements=tuple(sorted(all_requirements)),
interpreter_constraints=tuple(sorted(interpreter_constraints)),
entry_point="pytest:main",
)
)
Expand Down Expand Up @@ -106,7 +102,7 @@ def run_python_test(test_target, pytest, python_setup, source_root_config, subpr
DirectoriesToMerge(directories=tuple(all_input_digests)),
)

interpreter_search_paths = text_type(create_path_env_var(python_setup.interpreter_search_paths))
interpreter_search_paths = create_path_env_var(python_setup.interpreter_search_paths)
pex_exe_env = {'PATH': interpreter_search_paths}
# TODO(#6071): merge the two dicts via ** unpacking once we drop Py2.
pex_exe_env.update(subprocess_encoding_environment.invocation_environment_dict)
Expand Down
@@ -1,8 +1,6 @@
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from future.utils import text_type

from pants.backend.python.subsystems.python_native_code import PexBuildEnvironment, PythonNativeCode
from pants.backend.python.subsystems.python_setup import PythonSetup
from pants.engine.fs import Digest, Snapshot, UrlToFetch
Expand Down Expand Up @@ -38,7 +36,7 @@ def resolve_requirements(request, python_setup, pex_build_environment):
digest = Digest('61bb79384db0da8c844678440bd368bcbfac17bbdb865721ad3f9cb0ab29b629', 1826945)
pex_snapshot = yield Get(Snapshot, UrlToFetch(url, digest))

interpreter_search_paths = text_type(create_path_env_var(python_setup.interpreter_search_paths))
interpreter_search_paths = create_path_env_var(python_setup.interpreter_search_paths)
env = {"PATH": interpreter_search_paths}
# TODO(#6071): merge the two dicts via ** unpacking once we drop Py2.
env.update(pex_build_environment.invocation_environment_dict)
Expand Down
Expand Up @@ -5,8 +5,6 @@
import os
from textwrap import dedent

from future.utils import text_type

from pants.backend.native.subsystems.native_toolchain import NativeToolchain
from pants.backend.native.targets.native_library import NativeLibrary
from pants.backend.python.python_requirement import PythonRequirement
Expand Down Expand Up @@ -160,9 +158,8 @@ def invocation_environment_dict(self):
@rule(PexBuildEnvironment, [PythonNativeCode])
def create_pex_native_build_environment(python_native_code):
return PexBuildEnvironment(
# TODO(#6071): drop the text_type wrapping.
cpp_flags=[text_type(v) for v in python_native_code.get_options().cpp_flags],
ld_flags=[text_type(v) for v in python_native_code.get_options().ld_flags],
cpp_flags=python_native_code.get_options().cpp_flags,
ld_flags=python_native_code.get_options().ld_flags,
)


Expand Down
Expand Up @@ -3,8 +3,6 @@

import os

from future.utils import text_type

from pants.engine.rules import optionable_rule, rule
from pants.subsystem.subsystem import Subsystem
from pants.util.objects import datatype, string_optional
Expand Down Expand Up @@ -43,12 +41,9 @@ def invocation_environment_dict(self):

@rule(SubprocessEncodingEnvironment, [SubprocessEnvironment])
def create_subprocess_encoding_environment(subprocess_environment):
def ensure_string_optional(value):
return text_type(value) if value is not None else None

return SubprocessEncodingEnvironment(
lang=ensure_string_optional(subprocess_environment.get_options().lang),
lc_all=ensure_string_optional(subprocess_environment.get_options().lc_all),
lang=subprocess_environment.get_options().lang,
lc_all=subprocess_environment.get_options().lc_all,
)


Expand Down

0 comments on commit 25dc22f

Please sign in to comment.