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

Deprecate Subsystem.get_options() in favor of Subsystem.options #10493

Merged
merged 2 commits into from Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/python/pants/auth/basic_auth.py
Expand Up @@ -87,14 +87,14 @@ def authenticate(
if not provider:
raise BasicAuthException("No basic auth provider specified.")

provider_config = self.get_options().providers.get(provider)
provider_config = self.options.providers.get(provider)
if not provider_config:
raise BasicAuthException(f"No config found for provider {provider}.")

url = provider_config.get("url")
if not url:
raise BasicAuthException(f"No url found in config for provider {provider}.")
if not self.get_options().allow_insecure_urls and not url.startswith("https://"):
if not self.options.allow_insecure_urls and not url.startswith("https://"):
raise BasicAuthException(f"Auth url for provider {provider} is not secure: {url}.")

auth = requests.auth.HTTPBasicAuth(creds.username, creds.password) if creds else None
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/auth/cookies.py
Expand Up @@ -53,7 +53,7 @@ def get_cookie_jar(self):

def _get_cookie_file(self):
# We expanduser to make it easy for the user to config the cookies into their homedir.
return os.path.realpath(os.path.expanduser(self.get_options().path))
return os.path.realpath(os.path.expanduser(self.options.path))

@memoized_property
def _lock(self):
Expand Down
Expand Up @@ -26,7 +26,7 @@
TwoStepPexFromTargetsRequest,
)
from pants.backend.python.subsystems import python_native_code, subprocess_environment
from pants.backend.python.subsystems.subprocess_environment import SubprocessEncodingEnvironment
from pants.backend.python.subsystems.subprocess_environment import SubprocessEnvironment
from pants.core.util_rules import strip_source_roots
from pants.engine.fs import Digest, MergeDigests
from pants.engine.process import Process, ProcessResult
Expand Down Expand Up @@ -54,7 +54,7 @@ async def create_python_awslambda(
field_set: PythonAwsLambdaFieldSet,
lambdex_setup: LambdexSetup,
python_setup: PythonSetup,
subprocess_encoding_environment: SubprocessEncodingEnvironment,
subprocess_environment: SubprocessEnvironment,
) -> CreatedAWSLambda:
# Lambdas typically use the .zip suffix, so we use that instead of .pex.
pex_filename = f"{field_set.address.target_name}.zip"
Expand Down Expand Up @@ -93,7 +93,7 @@ async def create_python_awslambda(
lambdex_args = ("build", "-e", field_set.handler.value, pex_filename)
process = lambdex_setup.requirements_pex.create_process(
python_setup=python_setup,
subprocess_encoding_environment=subprocess_encoding_environment,
subprocess_environment=subprocess_environment,
pex_path="./lambdex.pex",
pex_args=lambdex_args,
input_digest=input_digest,
Expand All @@ -117,11 +117,9 @@ async def setup_lambdex(lambdex: Lambdex) -> LambdexSetup:
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(),
requirements=PexRequirements(lambdex.all_requirements),
interpreter_constraints=PexInterpreterConstraints(lambdex.interpreter_constraints),
entry_point=lambdex.entry_point,
),
)
return LambdexSetup(requirements_pex=requirements_pex,)
Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/backend/codegen/protobuf/protoc.py
Expand Up @@ -36,11 +36,10 @@ def register_options(cls, register):
)

def generate_url(self, plat: Platform) -> str:
version = self.options.version
plat_str = match(plat, {Platform.darwin: "osx", Platform.linux: "linux"})
return (
f"https://github.com/protocolbuffers/protobuf/releases/download/"
f"v{version}/protoc-{version}-{plat_str}-x86_64.zip"
f"v{self.version}/protoc-{self.version}-{plat_str}-x86_64.zip"
)

def generate_exe(self, plat: Platform) -> str:
Expand Down
Expand Up @@ -15,4 +15,4 @@ class Binutils(ExternalTool):
def generate_url(self, plat: Platform) -> str:
if plat != Platform.linux:
raise ExternalToolError()
return f"https://binaries.pantsbuild.org/bin/binutils/linux/x86_64/{self.options.version}/binutils.tar.gz"
return f"https://binaries.pantsbuild.org/bin/binutils/linux/x86_64/{self.version}/binutils.tar.gz"
4 changes: 1 addition & 3 deletions src/python/pants/backend/native/subsystems/binaries/gcc.py
Expand Up @@ -25,6 +25,4 @@ class GCC(ExternalTool):

def generate_url(self, plat: Platform) -> str:
plat_str = "mac/10.13" if plat == Platform.darwin else "linux/x86_64"
return (
f"https://binaries.pantsbuild.org/bin/gcc/{plat_str}/{self.options.version}/gcc.tar.gz"
)
return f"https://binaries.pantsbuild.org/bin/gcc/{plat_str}/{self.version}/gcc.tar.gz"
4 changes: 2 additions & 2 deletions src/python/pants/backend/native/subsystems/binaries/llvm.py
Expand Up @@ -26,5 +26,5 @@ class LLVM(ExternalTool):

def generate_url(self, plat: Platform) -> str:
system_id = "apple-darwin" if plat == Platform.darwin else "linux-gnu-ubuntu-16.04"
archive_basename = f"clang+llvm-{self.options.version}-x86_64-{system_id}"
return f"https://releases.llvm.org/{self.options.version}/{archive_basename}.tar.xz"
archive_basename = f"clang+llvm-{self.version}-x86_64-{system_id}"
return f"https://releases.llvm.org/{self.version}/{archive_basename}.tar.xz"
6 changes: 3 additions & 3 deletions src/python/pants/backend/native/subsystems/libc_dev.py
Expand Up @@ -73,7 +73,7 @@ def register_options(cls, register):

def _get_host_libc_from_host_compiler(self):
"""Locate the host's libc-dev installation using a specified host compiler's search dirs."""
compiler_exe = self.get_options().host_compiler
compiler_exe = self.options.host_compiler

# Implicitly, we are passing in the environment of the executing pants process to
# `get_compiler_library_dirs()`.
Expand Down Expand Up @@ -102,7 +102,7 @@ def _get_host_libc_from_host_compiler(self):
def _host_libc(self):
"""Use the --libc-dir option if provided, otherwise invoke a host compiler to find libc
dev."""
libc_dir_option = self.get_options().libc_dir
libc_dir_option = self.options.libc_dir
if libc_dir_option:
maybe_libc_crti = os.path.join(libc_dir_option, self._LIBC_INIT_OBJECT_FILE)
if os.path.isfile(maybe_libc_crti):
Expand All @@ -118,4 +118,4 @@ def _host_libc(self):

@memoized_method
def get_libc_objects(self):
return [self._host_libc.crti_object] if self.get_options().enable_libc_search else []
return [self._host_libc.crti_object] if self.options.enable_libc_search else []
Expand Up @@ -69,7 +69,7 @@ def register_options(cls, register):

@memoized_property
def _all_existing_install_prefixes(self):
return [pfx for pfx in self.get_options().install_prefixes if is_readable_dir(pfx)]
return [pfx for pfx in self.options.install_prefixes if is_readable_dir(pfx)]

# NB: We use @memoized_method in this file for methods which may raise.
@memoized_method
Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/backend/project_info/cloc.py
Expand Up @@ -37,8 +37,10 @@ class ClocBinary(ExternalTool):
]

def generate_url(self, plat: Platform) -> str:
version = self.get_options().version
return f"https://github.com/AlDanial/cloc/releases/download/{version}/cloc-{version}.pl"
return (
f"https://github.com/AlDanial/cloc/releases/download/{self.version}/"
f"cloc-{self.version}.pl"
)


class CountLinesOfCodeSubsystem(GoalSubsystem):
Expand Down
20 changes: 16 additions & 4 deletions src/python/pants/backend/python/dependency_inference/rules.py
Expand Up @@ -3,6 +3,7 @@

import itertools
from pathlib import PurePath
from typing import cast

from pants.backend.python.dependency_inference import module_mapper
from pants.backend.python.dependency_inference.import_parser import find_python_imports
Expand Down Expand Up @@ -38,7 +39,6 @@ class PythonInference(Subsystem):
@classmethod
def register_options(cls, register):
super().register_options(register)

register(
"--imports",
default=False,
Expand All @@ -65,6 +65,18 @@ def register_options(cls, register):
),
)

@property
def imports(self) -> bool:
return cast(bool, self.options.imports)

@property
def inits(self) -> bool:
return cast(bool, self.options.inits)

@property
def conftests(self) -> bool:
return cast(bool, self.options.conftests)


class InferPythonDependencies(InferDependenciesRequest):
infer_from = PythonSources
Expand All @@ -74,7 +86,7 @@ class InferPythonDependencies(InferDependenciesRequest):
async def infer_python_dependencies(
request: InferPythonDependencies, python_inference: PythonInference
) -> InferredDependencies:
if not python_inference.get_options().imports:
if not python_inference.imports:
return InferredDependencies()

stripped_sources = await Get(
Expand Down Expand Up @@ -113,7 +125,7 @@ class InferInitDependencies(InferDependenciesRequest):
async def infer_python_init_dependencies(
request: InferInitDependencies, python_inference: PythonInference
) -> InferredDependencies:
if not python_inference.get_options().inits:
if not python_inference.inits:
return InferredDependencies()

# Locate __init__.py files not already in the Snapshot.
Expand All @@ -139,7 +151,7 @@ class InferConftestDependencies(InferDependenciesRequest):
async def infer_python_conftest_dependencies(
request: InferConftestDependencies, python_inference: PythonInference,
) -> InferredDependencies:
if not python_inference.get_options().conftests:
if not python_inference.conftests:
return InferredDependencies()

# Locate conftest.py files not already in the Snapshot.
Expand Down
25 changes: 12 additions & 13 deletions src/python/pants/backend/python/lint/bandit/rules.py
Expand Up @@ -2,7 +2,7 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from dataclasses import dataclass
from typing import Optional, Tuple
from typing import Tuple

from pants.backend.python.lint.bandit.subsystem import Bandit
from pants.backend.python.rules import download_pex_bin, pex
Expand All @@ -13,7 +13,7 @@
PexRequirements,
)
from pants.backend.python.subsystems import python_native_code, subprocess_environment
from pants.backend.python.subsystems.subprocess_environment import SubprocessEncodingEnvironment
from pants.backend.python.subsystems.subprocess_environment import SubprocessEnvironment
from pants.backend.python.target_types import PythonInterpreterCompatibility, PythonSources
from pants.core.goals.lint import LintRequest, LintResult, LintResults
from pants.core.util_rules import determine_source_files, strip_source_roots
Expand Down Expand Up @@ -52,9 +52,9 @@ class BanditPartition:

def generate_args(*, specified_source_files: SourceFiles, bandit: Bandit) -> Tuple[str, ...]:
args = []
if bandit.options.config is not None:
args.append(f"--config={bandit.options.config}")
args.extend(bandit.options.args)
if bandit.config is not None:
args.append(f"--config={bandit.config}")
args.extend(bandit.args)
args.extend(specified_source_files.files)
return tuple(args)

Expand All @@ -64,26 +64,25 @@ async def bandit_lint_partition(
partition: BanditPartition,
bandit: Bandit,
python_setup: PythonSetup,
subprocess_encoding_environment: SubprocessEncodingEnvironment,
subprocess_environment: SubprocessEnvironment,
) -> LintResult:
requirements_pex_request = Get(
Pex,
PexRequest(
output_filename="bandit.pex",
requirements=PexRequirements(bandit.get_requirement_specs()),
requirements=PexRequirements(bandit.all_requirements),
interpreter_constraints=(
partition.interpreter_constraints
or PexInterpreterConstraints(bandit.default_interpreter_constraints)
or PexInterpreterConstraints(bandit.interpreter_constraints)
),
entry_point=bandit.get_entry_point(),
entry_point=bandit.entry_point,
),
)

config_path: Optional[str] = bandit.options.config
config_digest_request = Get(
Digest,
PathGlobs(
globs=[config_path] if config_path else [],
globs=[bandit.config] if bandit.config else [],
glob_match_error_behavior=GlobMatchErrorBehavior.error,
description_of_origin="the option `--bandit-config`",
),
Expand Down Expand Up @@ -117,7 +116,7 @@ async def bandit_lint_partition(

process = requirements_pex.create_process(
python_setup=python_setup,
subprocess_encoding_environment=subprocess_encoding_environment,
subprocess_environment=subprocess_environment,
pex_path="./bandit.pex",
pex_args=generate_args(specified_source_files=specified_source_files, bandit=bandit),
input_digest=input_digest,
Expand All @@ -133,7 +132,7 @@ async def bandit_lint_partition(
async def bandit_lint(
request: BanditRequest, bandit: Bandit, python_setup: PythonSetup
) -> LintResults:
if bandit.options.skip:
if bandit.skip:
return LintResults()

# NB: Bandit output depends upon which Python interpreter version it's run with
Expand Down
13 changes: 13 additions & 0 deletions src/python/pants/backend/python/lint/bandit/subsystem.py
@@ -1,6 +1,7 @@
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from typing import Optional, Tuple, cast

from pants.backend.python.subsystems.python_tool_base import PythonToolBase
from pants.option.custom_types import file_option, shell_str
Expand Down Expand Up @@ -41,3 +42,15 @@ def register_options(cls, register):
advanced=True,
help="Path to a Bandit YAML config file",
)

@property
def skip(self) -> bool:
return cast(bool, self.options.skip)

@property
def args(self) -> Tuple[str, ...]:
return tuple(self.options.args)

@property
def config(self) -> Optional[str]:
return cast(Optional[str], self.options.config)