Skip to content

Commit

Permalink
Remove deprecated Get[P](S) syntax in favor of Get(P, S) (#10148)
Browse files Browse the repository at this point in the history
Closes #9899.

[ci skip-jvm-tests]
  • Loading branch information
Eric-Arellano committed Jun 24, 2020
1 parent e4db7d4 commit 0ebbeb0
Show file tree
Hide file tree
Showing 63 changed files with 562 additions and 565 deletions.
Expand Up @@ -51,18 +51,19 @@ async def create_awslambda(
buildroot: BuildRoot,
workspace: Workspace,
) -> AWSLambdaGoal:
targets_to_valid_field_sets = await Get[TargetsToValidFieldSets](
targets_to_valid_field_sets = await Get(
TargetsToValidFieldSets,
TargetsToValidFieldSetsRequest(
AWSLambdaFieldSet,
goal_description=f"the `{options.name}` goal",
error_if_no_valid_targets=True,
)
),
)
awslambdas = await MultiGet(
Get[CreatedAWSLambda](AWSLambdaFieldSet, field_set)
Get(CreatedAWSLambda, AWSLambdaFieldSet, field_set)
for field_set in targets_to_valid_field_sets.field_sets
)
merged_digest = await Get[Digest](MergeDigests(awslambda.digest for awslambda in awslambdas))
merged_digest = await Get(Digest, MergeDigests(awslambda.digest for awslambda in awslambdas))
result = workspace.materialize_directory(
DirectoryToMaterialize(merged_digest, path_prefix=str(distdir.relpath))
)
Expand Down
Expand Up @@ -78,9 +78,9 @@ async def create_python_awslambda(
)
)

pex_result = await Get[TwoStepPex](TwoStepPexFromTargetsRequest, pex_request)
input_digest = await Get[Digest](
MergeDigests((pex_result.pex.digest, lambdex_setup.requirements_pex.digest))
pex_result = await Get(TwoStepPex, TwoStepPexFromTargetsRequest, pex_request)
input_digest = await Get(
Digest, MergeDigests((pex_result.pex.digest, lambdex_setup.requirements_pex.digest))
)

# NB: Lambdex modifies its input pex in-place, so the input file is also the output file.
Expand All @@ -94,7 +94,7 @@ async def create_python_awslambda(
output_files=(pex_filename,),
description=f"Setting up handler in {pex_filename}",
)
result = await Get[ProcessResult](Process, process)
result = await Get(ProcessResult, Process, process)
# Note that the AWS-facing handler function is always lambdex_handler.handler, which
# is the wrapper injected by lambdex that manages invocation of the actual handler.
return CreatedAWSLambda(
Expand All @@ -107,15 +107,16 @@ async def create_python_awslambda(

@rule(desc="Set up lambdex")
async def setup_lambdex(lambdex: Lambdex) -> LambdexSetup:
requirements_pex = await Get[Pex](
requirements_pex = await Get(
Pex,
PexRequest(
output_filename="lambdex.pex",
requirements=PexRequirements(lambdex.get_requirement_specs()),
interpreter_constraints=PexInterpreterConstraints(
lambdex.default_interpreter_constraints
),
entry_point=lambdex.get_entry_point(),
)
),
)
return LambdexSetup(requirements_pex=requirements_pex,)

Expand Down
33 changes: 19 additions & 14 deletions src/python/pants/backend/codegen/protobuf/python/rules.py
Expand Up @@ -25,35 +25,38 @@ class GeneratePythonFromProtobufRequest(GenerateSourcesRequest):
async def generate_python_from_protobuf(
request: GeneratePythonFromProtobufRequest, protoc: Protoc
) -> GeneratedSources:
download_protoc_request = Get[DownloadedExternalTool](
ExternalToolRequest, protoc.get_request(Platform.current)
download_protoc_request = Get(
DownloadedExternalTool, ExternalToolRequest, protoc.get_request(Platform.current)
)

output_dir = "_generated_files"
# TODO(#9650): replace this with a proper intrinsic to create empty directories.
create_output_dir_request = Get[ProcessResult](
create_output_dir_request = Get(
ProcessResult,
Process(
("/bin/mkdir", output_dir),
description=f"Create the directory {output_dir}",
output_directories=(output_dir,),
)
),
)

# Protoc needs all transitive dependencies on `protobuf_libraries` to work properly. It won't
# actually generate those dependencies; it only needs to look at their .proto files to work
# with imports.
transitive_targets = await Get[TransitiveTargets](Addresses([request.protocol_target.address]))
all_sources_request = Get[SourceFiles](
transitive_targets = await Get(TransitiveTargets, Addresses([request.protocol_target.address]))
all_sources_request = Get(
SourceFiles,
AllSourceFilesRequest(
(tgt.get(Sources) for tgt in transitive_targets.closure),
for_sources_types=(ProtobufSources,),
# NB: By stripping the source roots, we avoid having to set the value `--proto_path`
# for Protobuf imports to be discoverable.
strip_source_roots=True,
)
),
)
stripped_target_sources_request = Get[SourceFiles](
AllSourceFilesRequest([request.protocol_target[ProtobufSources]], strip_source_roots=True)
stripped_target_sources_request = Get(
SourceFiles,
AllSourceFilesRequest([request.protocol_target[ProtobufSources]], strip_source_roots=True),
)

(
Expand All @@ -68,17 +71,19 @@ async def generate_python_from_protobuf(
stripped_target_sources_request,
)

input_digest = await Get[Digest](
input_digest = await Get(
Digest,
MergeDigests(
(
all_sources.snapshot.digest,
downloaded_protoc_binary.digest,
create_output_dir_result.output_digest,
)
)
),
)

result = await Get[ProcessResult](
result = await Get(
ProcessResult,
Process(
(
downloaded_protoc_binary.exe,
Expand All @@ -89,9 +94,9 @@ async def generate_python_from_protobuf(
input_digest=input_digest,
description=f"Generating Python sources from {request.protocol_target.address}.",
output_directories=(output_dir,),
)
),
)
normalized_snapshot = await Get[Snapshot](RemovePrefix(result.output_digest, output_dir))
normalized_snapshot = await Get(Snapshot, RemovePrefix(result.output_digest, output_dir))
return GeneratedSources(normalized_snapshot)


Expand Down
64 changes: 32 additions & 32 deletions src/python/pants/backend/native/subsystems/native_toolchain.py
Expand Up @@ -134,9 +134,9 @@ async def select_libc_objects(platform: Platform, native_toolchain: NativeToolch
@rule
async def select_assembler(platform: Platform, native_toolchain: NativeToolchain) -> Assembler:
if platform == Platform.darwin:
assembler = await Get[Assembler](XCodeCLITools, native_toolchain._xcode_cli_tools)
assembler = await Get(Assembler, XCodeCLITools, native_toolchain._xcode_cli_tools)
else:
assembler = await Get[Assembler](Binutils, native_toolchain._binutils)
assembler = await Get(Assembler, Binutils, native_toolchain._binutils)
return assembler


Expand All @@ -156,18 +156,18 @@ class BaseLinker:
async def select_base_linker(platform: Platform, native_toolchain: NativeToolchain) -> BaseLinker:
if platform == Platform.darwin:
# TODO(#5663): turn this into LLVM when lld works.
linker = await Get[Linker](XCodeCLITools, native_toolchain._xcode_cli_tools)
linker = await Get(Linker, XCodeCLITools, native_toolchain._xcode_cli_tools)
else:
linker = await Get[Linker](Binutils, native_toolchain._binutils)
linker = await Get(Linker, Binutils, native_toolchain._binutils)
base_linker = BaseLinker(linker=linker)
return base_linker


@rule
async def select_gcc_linker(native_toolchain: NativeToolchain) -> GCCLinker:
base_linker = await Get[BaseLinker](NativeToolchain, native_toolchain)
base_linker = await Get(BaseLinker, NativeToolchain, native_toolchain)
linker = base_linker.linker
libc_objects = await Get[LibcObjects](NativeToolchain, native_toolchain)
libc_objects = await Get(LibcObjects, NativeToolchain, native_toolchain)
linker_with_libc = linker.append_field("extra_object_files", libc_objects.crti_object_paths)
return GCCLinker(linker_with_libc)

Expand Down Expand Up @@ -202,14 +202,14 @@ def select_gcc_install_location(gcc: GCC) -> GCCInstallLocationForLLVM:
async def select_llvm_c_toolchain(
platform: Platform, native_toolchain: NativeToolchain
) -> LLVMCToolchain:
provided_clang = await Get[CCompiler](LLVM, native_toolchain._llvm)
provided_clang = await Get(CCompiler, LLVM, native_toolchain._llvm)

if platform == Platform.darwin:
xcode_clang = await Get[CCompiler](XCodeCLITools, native_toolchain._xcode_cli_tools)
xcode_clang = await Get(CCompiler, XCodeCLITools, native_toolchain._xcode_cli_tools)
joined_c_compiler = provided_clang.sequence(xcode_clang)
else:
gcc_install = await Get[GCCInstallLocationForLLVM](GCC, native_toolchain._gcc)
provided_gcc = await Get[CCompiler](GCC, native_toolchain._gcc)
gcc_install = await Get(GCCInstallLocationForLLVM, GCC, native_toolchain._gcc)
provided_gcc = await Get(CCompiler, GCC, native_toolchain._gcc)
joined_c_compiler = (
provided_clang.sequence(provided_gcc).append_field(
"extra_args", gcc_install.as_clang_argv
Expand All @@ -220,7 +220,7 @@ async def select_llvm_c_toolchain(

working_c_compiler = joined_c_compiler.prepend_field("extra_args", ["-x", "c", "-std=c11"])

llvm_linker_wrapper = await Get[LLVMLinker](NativeToolchain, native_toolchain)
llvm_linker_wrapper = await Get(LLVMLinker, NativeToolchain, native_toolchain)
working_linker = llvm_linker_wrapper.for_compiler(working_c_compiler)

return LLVMCToolchain(CToolchain(working_c_compiler, working_linker))
Expand All @@ -230,18 +230,18 @@ async def select_llvm_c_toolchain(
async def select_llvm_cpp_toolchain(
platform: Platform, native_toolchain: NativeToolchain
) -> LLVMCppToolchain:
provided_clangpp = await Get[CppCompiler](LLVM, native_toolchain._llvm)
provided_clangpp = await Get(CppCompiler, LLVM, native_toolchain._llvm)

# On OSX, we use the libc++ (LLVM) C++ standard library implementation. This is feature-complete
# for OSX, but not for Linux (see https://libcxx.llvm.org/ for more info).
if platform == Platform.darwin:
xcode_clangpp = await Get[CppCompiler](XCodeCLITools, native_toolchain._xcode_cli_tools)
xcode_clangpp = await Get(CppCompiler, XCodeCLITools, native_toolchain._xcode_cli_tools)
joined_cpp_compiler = provided_clangpp.sequence(xcode_clangpp)
extra_llvm_linking_library_dirs: Tuple[str, ...] = tuple()
linker_extra_args: Tuple[str, ...] = tuple()
else:
gcc_install = await Get[GCCInstallLocationForLLVM](GCC, native_toolchain._gcc)
provided_gpp = await Get[CppCompiler](GCC, native_toolchain._gcc)
gcc_install = await Get(GCCInstallLocationForLLVM, GCC, native_toolchain._gcc)
provided_gpp = await Get(CppCompiler, GCC, native_toolchain._gcc)
joined_cpp_compiler = (
provided_clangpp.sequence(provided_gpp)
# NB: we use g++'s headers on Linux, and therefore their C++ standard
Expand Down Expand Up @@ -272,7 +272,7 @@ async def select_llvm_cpp_toolchain(
],
)

llvm_linker_wrapper = await Get[LLVMLinker](NativeToolchain, native_toolchain)
llvm_linker_wrapper = await Get(LLVMLinker, NativeToolchain, native_toolchain)
working_linker = (
llvm_linker_wrapper.for_compiler(working_cpp_compiler)
.append_field("linking_library_dirs", extra_llvm_linking_library_dirs)
Expand All @@ -286,24 +286,24 @@ async def select_llvm_cpp_toolchain(
async def select_gcc_c_toolchain(
platform: Platform, native_toolchain: NativeToolchain
) -> GCCCToolchain:
provided_gcc = await Get[CCompiler](GCC, native_toolchain._gcc)
provided_gcc = await Get(CCompiler, GCC, native_toolchain._gcc)

if platform == Platform.darwin:
# GCC needs access to some headers that are only provided by the XCode toolchain
# currently (e.g. "_stdio.h"). These headers are unlikely to change across versions, so this is
# probably safe.
xcode_clang = await Get[CCompiler](XCodeCLITools, native_toolchain._xcode_cli_tools)
xcode_clang = await Get(CCompiler, XCodeCLITools, native_toolchain._xcode_cli_tools)
joined_c_compiler = provided_gcc.sequence(xcode_clang)
else:
joined_c_compiler = provided_gcc

# GCC needs an assembler, so we provide that (platform-specific) tool here.
assembler = await Get[Assembler](NativeToolchain, native_toolchain)
assembler = await Get(Assembler, NativeToolchain, native_toolchain)
working_c_compiler = joined_c_compiler.sequence(assembler).prepend_field(
"extra_args", ["-x", "c", "-std=c11"]
)

gcc_linker_wrapper = await Get[GCCLinker](NativeToolchain, native_toolchain)
gcc_linker_wrapper = await Get(GCCLinker, NativeToolchain, native_toolchain)
working_linker = gcc_linker_wrapper.for_compiler(working_c_compiler)

return GCCCToolchain(CToolchain(working_c_compiler, working_linker))
Expand All @@ -313,21 +313,21 @@ async def select_gcc_c_toolchain(
async def select_gcc_cpp_toolchain(
platform: Platform, native_toolchain: NativeToolchain
) -> GCCCppToolchain:
provided_gpp = await Get[CppCompiler](GCC, native_toolchain._gcc)
provided_gpp = await Get(CppCompiler, GCC, native_toolchain._gcc)

if platform == Platform.darwin:
# GCC needs access to some headers that are only provided by the XCode toolchain
# currently (e.g. "_stdio.h"). These headers are unlikely to change across versions, so this is
# probably safe.
# TODO: we should be providing all of these (so we can eventually phase out XCodeCLITools
# entirely).
xcode_clangpp = await Get[CppCompiler](XCodeCLITools, native_toolchain._xcode_cli_tools)
xcode_clangpp = await Get(CppCompiler, XCodeCLITools, native_toolchain._xcode_cli_tools)
joined_cpp_compiler = provided_gpp.sequence(xcode_clangpp)
else:
joined_cpp_compiler = provided_gpp

# GCC needs an assembler, so we provide that (platform-specific) tool here.
assembler = await Get[Assembler](NativeToolchain, native_toolchain)
assembler = await Get(Assembler, NativeToolchain, native_toolchain)
working_cpp_compiler = joined_cpp_compiler.sequence(assembler).prepend_field(
"extra_args",
[
Expand All @@ -342,7 +342,7 @@ async def select_gcc_cpp_toolchain(
],
)

gcc_linker_wrapper = await Get[GCCLinker](NativeToolchain, native_toolchain)
gcc_linker_wrapper = await Get(GCCLinker, NativeToolchain, native_toolchain)
working_linker = gcc_linker_wrapper.for_compiler(working_cpp_compiler)

return GCCCppToolchain(CppToolchain(working_cpp_compiler, working_linker))
Expand All @@ -359,12 +359,12 @@ async def select_c_toolchain(toolchain_variant_request: ToolchainVariantRequest)
use_gcc = toolchain_variant_request.variant == ToolchainVariant.gnu
toolchain_resolved: Union[GCCCToolchain, LLVMCToolchain]
if use_gcc:
toolchain_resolved = await Get[GCCCToolchain](
NativeToolchain, toolchain_variant_request.toolchain
toolchain_resolved = await Get(
GCCCToolchain, NativeToolchain, toolchain_variant_request.toolchain
)
else:
toolchain_resolved = await Get[LLVMCToolchain](
NativeToolchain, toolchain_variant_request.toolchain
toolchain_resolved = await Get(
LLVMCToolchain, NativeToolchain, toolchain_variant_request.toolchain
)
return toolchain_resolved.c_toolchain

Expand All @@ -374,12 +374,12 @@ async def select_cpp_toolchain(toolchain_variant_request: ToolchainVariantReques
use_gcc = toolchain_variant_request.variant == ToolchainVariant.gnu
toolchain_resolved: Union[GCCCppToolchain, LLVMCppToolchain]
if use_gcc:
toolchain_resolved = await Get[GCCCppToolchain](
NativeToolchain, toolchain_variant_request.toolchain
toolchain_resolved = await Get(
GCCCppToolchain, NativeToolchain, toolchain_variant_request.toolchain
)
else:
toolchain_resolved = await Get[LLVMCppToolchain](
NativeToolchain, toolchain_variant_request.toolchain
toolchain_resolved = await Get(
LLVMCppToolchain, NativeToolchain, toolchain_variant_request.toolchain
)
return toolchain_resolved.cpp_toolchain

Expand Down
8 changes: 4 additions & 4 deletions src/python/pants/backend/pants_info/list_backends.py
Expand Up @@ -163,11 +163,11 @@ def format_section(
async def list_backends(
backend_options: BackendsOptions, global_options: GlobalOptions, console: Console,
) -> Backends:
discovered_register_pys = await Get[Snapshot](PathGlobs(["**/*/register.py"]))
register_pys_content = await Get[FilesContent](Digest, discovered_register_pys.digest)
discovered_register_pys = await Get(Snapshot, PathGlobs(["**/*/register.py"]))
register_pys_content = await Get(FilesContent, Digest, discovered_register_pys.digest)

source_root_stripped_sources = await Get[SourceRootStrippedSources](
StripSnapshotRequest(snapshot=discovered_register_pys)
source_root_stripped_sources = await Get(
SourceRootStrippedSources, StripSnapshotRequest(snapshot=discovered_register_pys)
)
file_to_stripped_file_mapping = source_root_stripped_sources.get_file_to_stripped_file_mapping()
stripped_paths = []
Expand Down
17 changes: 9 additions & 8 deletions src/python/pants/backend/project_info/cloc.py
Expand Up @@ -97,20 +97,21 @@ async def run_cloc(
return CountLinesOfCode(exit_code=0)

input_files_filename = "input_files.txt"
input_file_digest = await Get[Digest](
InputFilesContent([FileContent(path=input_files_filename, content=file_content)]),
input_file_digest = await Get(
Digest, InputFilesContent([FileContent(path=input_files_filename, content=file_content)]),
)
downloaded_cloc_binary = await Get[DownloadedExternalTool](
ExternalToolRequest, cloc_binary.get_request(Platform.current)
downloaded_cloc_binary = await Get(
DownloadedExternalTool, ExternalToolRequest, cloc_binary.get_request(Platform.current)
)
digest = await Get[Digest](
digest = await Get(
Digest,
MergeDigests(
(
input_file_digest,
downloaded_cloc_binary.digest,
*(sources_snapshot.snapshot.digest for sources_snapshot in sources_snapshots),
)
)
),
)

report_filename = "report.txt"
Expand All @@ -131,8 +132,8 @@ async def run_cloc(
description=f"Count lines of code for {pluralize(len(all_file_names), 'file')}",
)

exec_result = await Get[ProcessResult](Process, req)
files_content = await Get[FilesContent](Digest, exec_result.output_digest)
exec_result = await Get(ProcessResult, Process, req)
files_content = await Get(FilesContent, Digest, exec_result.output_digest)

file_outputs = {fc.path: fc.content.decode() for fc in files_content}

Expand Down

0 comments on commit 0ebbeb0

Please sign in to comment.