Esempio n. 1
0
class FiledepsSubsystem(LineOriented, GoalSubsystem):
    name = "filedeps"
    help = "List all source and BUILD files a target depends on."

    absolute = BoolOption(
        "--absolute",
        default=False,
        help=softwrap(
            """
            If True, output with absolute path. If unspecified, output with path relative to
            the build root.
            """
        ),
    )
    globs = BoolOption(
        "--globs",
        default=False,
        help=softwrap(
            """
            Instead of outputting filenames, output the original globs used in the BUILD
            file. This will not include exclude globs (i.e. globs that start with `!`).
            """
        ),
    )
    transitive = BoolOption(
        "--transitive",
        default=False,
        help=softwrap(
            """
            If True, list files from all dependencies, including transitive dependencies. If
            unspecified, only list files from the target.
            """
        ),
    )
Esempio n. 2
0
class JavaInferSubsystem(Subsystem):
    options_scope = "java-infer"
    help = "Options controlling which dependencies will be inferred for Java targets."

    imports = BoolOption(
        "--imports",
        default=True,
        help=
        ("Infer a target's dependencies by parsing import statements from sources."
         ),
    )
    consumed_types = BoolOption(
        "--consumed-types",
        default=True,
        help=
        ("Infer a target's dependencies by parsing consumed types from sources."
         ),
    )
    third_party_imports = BoolOption(
        "--third-party-imports",
        default=True,
        help=
        "Infer a target's third-party dependencies using Java import statements.",
    )
    # TODO: Move to `coursier` or a generic `jvm` subsystem.
    third_party_import_mapping = DictOption[Any](
        "--third-party-import-mapping",
        help=
        ("A dictionary mapping a Java package path to a JVM artifact coordinate "
         "(GROUP:ARTIFACT) without the version.\n\n"
         "See `jvm_artifact` for more information on the mapping syntax."),
    )
Esempio n. 3
0
class StatsAggregatorSubsystem(Subsystem):
    options_scope = "stats"
    help = "An aggregator for Pants stats, such as cache metrics."

    log = BoolOption(
        "--log",
        default=False,
        help=softwrap("""
            At the end of the Pants run, log all counter metrics and summaries of
            observation histograms, e.g. the number of cache hits and the time saved by
            caching.

            For histogram summaries to work, you must add `hdrhistogram` to `[GLOBAL].plugins`.
            """),
        advanced=True,
    )
    memory_summary = BoolOption(
        "--memory-summary",
        default=False,
        help=softwrap("""
            At the end of the Pants run, report a summary of memory usage.

            Keys are the total size in bytes, the count, and the name. Note that the total size
            is for all instances added together, so you can use total_size // count to get the
            average size.
            """),
        advanced=True,
    )
Esempio n. 4
0
class TestSubsystem(GoalSubsystem):
    name = "test"
    help = "Run tests."

    # Prevent this class from being detected by pytest as a test class.
    __test__ = False

    @classmethod
    def activated(cls, union_membership: UnionMembership) -> bool:
        return TestFieldSet in union_membership

    debug = BoolOption(
        "--debug",
        default=False,
        help=
        ("Run tests sequentially in an interactive process. This is necessary, for "
         "example, when you add breakpoints to your code."),
    )
    force = BoolOption(
        "--force",
        default=False,
        help=
        "Force the tests to run, even if they could be satisfied from cache.",
    )
    output = EnumOption(
        "--output",
        default=ShowOutput.FAILED,
        help="Show stdout/stderr for these tests.",
    )
    use_coverage = BoolOption(
        "--use-coverage",
        default=False,
        help="Generate a coverage report if the test runner supports it.",
    )
    open_coverage = BoolOption(
        "--open-coverage",
        default=False,
        help=
        ("If a coverage report file is generated, open it on the local system if the "
         "system supports this."),
    )
    xml_dir = StrOption(
        "--xml-dir",
        metavar="<DIR>",
        default=None,
        advanced=True,
        help=
        ("Specifying a directory causes Junit XML result files to be emitted under "
         "that dir for each test run that supports producing them."),
    )
    extra_env_vars = StrListOption(
        "--extra-env-vars",
        help=
        ("Additional environment variables to include in test processes. "
         "Entries are strings in the form `ENV_VAR=value` to use explicitly; or just "
         "`ENV_VAR` to copy the value of a variable in Pants's own environment."
         ),
    )
Esempio n. 5
0
class UpdateBuildFilesSubsystem(GoalSubsystem):
    name = "update-build-files"
    help = (
        "Format and fix safe deprecations in BUILD files.\n\n"
        "This does not handle the full Pants upgrade. You must still manually change "
        "`pants_version` in `pants.toml` and you may need to manually address some deprecations. "
        f"See {doc_url('upgrade-tips')} for upgrade tips.\n\n"
        "This goal is run without arguments. It will run over all BUILD files in your "
        "project.")

    @classmethod
    def activated(cls, union_membership: UnionMembership) -> bool:
        return RewrittenBuildFileRequest in union_membership

    check = BoolOption(
        "--check",
        default=False,
        help=
        ("Do not write changes to disk, only write back what would change. Return code "
         "0 means there would be no changes, and 1 means that there would be. "
         ),
    )
    fmt = BoolOption(
        "--fmt",
        default=True,
        help=
        ("Format BUILD files using Black or Yapf.\n\n"
         "Set `[black].args` / `[yapf].args`, `[black].config` / `[yapf].config` , "
         "and `[black].config_discovery` / `[yapf].config_discovery` to change "
         "Black's or Yapf's behavior. Set "
         "`[black].interpreter_constraints` / `[yapf].interpreter_constraints` "
         "and `[python].interpreter_search_path` to change which interpreter is "
         "used to run the formatter."),
    )
    formatter = EnumOption(
        "--formatter",
        default=Formatter.BLACK,
        help="Which formatter Pants should use to format BUILD files.",
    )
    fix_safe_deprecations = BoolOption(
        "--fix-safe-deprecations",
        default=True,
        help=
        ("Automatically fix deprecations, such as target type renames, that are safe "
         "because they do not change semantics."),
    )
    fix_python_macros = BoolOption(
        "--fix-python-macros",
        default=False,
        help=
        ("Update references to targets generated from `python_requirements` and "
         "`poetry_requirements` from the old deprecated macro mechanism to the new target "
         f"generation mechanism described at {doc_url('targets#target-generation')}.\n\n"
         ),
    )
Esempio n. 6
0
class UpdateBuildFilesSubsystem(GoalSubsystem):
    name = "update-build-files"
    help = softwrap(f"""
        Format and fix safe deprecations in BUILD files.

        This does not handle the full Pants upgrade. You must still manually change
        `pants_version` in `pants.toml` and you may need to manually address some deprecations.
        See {doc_url('upgrade-tips')} for upgrade tips.

        This goal is run without arguments. It will run over all BUILD files in your
        project.
        """)

    @classmethod
    def activated(cls, union_membership: UnionMembership) -> bool:
        return RewrittenBuildFileRequest in union_membership

    check = BoolOption(
        "--check",
        default=False,
        help=softwrap("""
            Do not write changes to disk, only write back what would change. Return code
            0 means there would be no changes, and 1 means that there would be.
            """),
    )
    fmt = BoolOption(
        "--fmt",
        default=True,
        help=softwrap("""
            Format BUILD files using Black or Yapf.

            Set `[black].args` / `[yapf].args`, `[black].config` / `[yapf].config` ,
            and `[black].config_discovery` / `[yapf].config_discovery` to change
            Black's or Yapf's behavior. Set
            `[black].interpreter_constraints` / `[yapf].interpreter_constraints`
            and `[python].interpreter_search_path` to change which interpreter is
            used to run the formatter.
            """),
    )
    formatter = EnumOption(
        "--formatter",
        default=Formatter.BLACK,
        help="Which formatter Pants should use to format BUILD files.",
    )
    fix_safe_deprecations = BoolOption(
        "--fix-safe-deprecations",
        default=True,
        help=softwrap("""
            Automatically fix deprecations, such as target type renames, that are safe
            because they do not change semantics.
            """),
    )
Esempio n. 7
0
class HelmSubsystem(TemplatedExternalTool):
    options_scope = "helm"
    help = "The Helm command line (https://helm.sh)"

    default_version = "3.8.0"
    default_known_versions = [
        "3.8.0|linux_arm64 |23e08035dc0106fe4e0bd85800fd795b2b9ecd9f32187aa16c49b0a917105161|12324642",
        "3.8.0|linux_x86_64|8408c91e846c5b9ba15eb6b1a5a79fc22dd4d33ac6ea63388e5698d1b2320c8b|13626774",
        "3.8.0|macos_arm64 |751348f1a4a876ffe089fd68df6aea310fd05fe3b163ab76aa62632e327122f3|14078604",
        "3.8.0|macos_x86_64|532ddd6213891084873e5c2dcafa577f425ca662a6594a3389e288fc48dc2089|14318316",
    ]
    default_url_template = "https://get.helm.sh/helm-v{version}-{platform}.tar.gz"
    default_url_platform_mapping = {
        "linux_arm64": "linux-arm64",
        "linux_x86_64": "linux-amd64",
        "macos_arm64": "darwin-arm64",
        "macos_x86_64": "darwin-amd64",
    }

    _registries = DictOption[Any]("--registries",
                                  help=registries_help,
                                  fromfile=True)
    lint_strict = BoolOption("--lint-strict",
                             default=False,
                             help="Enables strict linting of Helm charts")
    default_registry_repository = StrOption(
        "--default-registry-repository",
        default=None,
        help=softwrap("""
            Default location where to push Helm charts in the available registries
            when no specific one has been given.

            If no registry repository is given, charts will be pushed to the root of
            the OCI registry.
            """),
    )
    tailor = BoolOption(
        "--tailor",
        default=True,
        help="If true, add `helm_chart` targets with the `tailor` goal.",
        advanced=True,
    )

    def generate_exe(self, plat: Platform) -> str:
        mapped_plat = self.default_url_platform_mapping[plat.value]
        bin_path = os.path.join(mapped_plat, "helm")
        return bin_path

    @memoized_method
    def remotes(self) -> HelmRemotes:
        return HelmRemotes.from_dict(self._registries)
Esempio n. 8
0
class DependeesSubsystem(LineOriented, GoalSubsystem):
    name = "dependees"
    help = "List all targets that depend on any of the input files/targets."

    transitive = BoolOption(
        "--transitive",
        default=False,
        help="List all transitive dependees. If unspecified, list direct dependees only.",
    )
    closed = BoolOption(
        "--closed",
        default=False,
        help="Include the input targets in the output, along with the dependees.",
    )
Esempio n. 9
0
class ThriftSubsystem(Subsystem):
    options_scope = "thrift"
    help = "General Thrift IDL settings (https://thrift.apache.org/)."

    dependency_inference = BoolOption(
        "--dependency-inference",
        default=True,
        help="Infer Thrift dependencies on other Thrift files by analyzing import statements.",
    )
    tailor = BoolOption(
        "--tailor",
        default=True,
        help="If true, add `thrift_sources` targets with the `tailor` goal.",
        advanced=True,
    )
Esempio n. 10
0
class ShellSetup(Subsystem):
    options_scope = "shell-setup"
    help = "Options for Pants's Shell support."

    _executable_search_path = StrListOption(
        "--executable-search-paths",
        default=["<PATH>"],
        help=
        ("The PATH value that will be used to find shells and to run certain processes "
         "like the shunit2 test runner.\n\n"
         'The special string "<PATH>" will expand to the contents of the PATH env var.'
         ),
        advanced=True,
        metavar="<binary-paths>",
    )
    dependency_inference = BoolOption(
        "--dependency-inference",
        default=True,
        help=
        "Infer Shell dependencies on other Shell files by analyzing `source` statements.",
        advanced=True,
    )

    @memoized_method
    def executable_search_path(self, env: Environment) -> tuple[str, ...]:
        def iter_path_entries():
            for entry in self._executable_search_path:
                if entry == "<PATH>":
                    path = env.get("PATH")
                    if path:
                        yield from path.split(os.pathsep)
                else:
                    yield entry

        return tuple(OrderedSet(iter_path_entries()))
Esempio n. 11
0
class IPython(PythonToolBase):
    options_scope = "ipython"
    help = "The IPython enhanced REPL (https://ipython.org/)."

    default_version = "ipython==7.16.1"  # The last version to support Python 3.6.
    default_main = ConsoleScript("ipython")

    register_lockfile = True
    default_lockfile_resource = ("pants.backend.python.subsystems",
                                 "ipython.lock")
    default_lockfile_path = "src/python/pants/backend/python/subsystems/ipython.lock"
    default_lockfile_url = git_url(default_lockfile_path)

    ignore_cwd = BoolOption(
        "--ignore-cwd",
        advanced=True,
        default=True,
        help=softwrap("""
            Whether to tell IPython not to put the CWD on the import path.

            Normally you want this to be True, so that imports come from the hermetic
            environment Pants creates.

            However IPython<7.13.0 doesn't support this option, so if you're using an earlier
            version (e.g., because you have Python 2.7 code) then you will need to set this to False,
            and you may have issues with imports from your CWD shading the hermetic environment.
            """),
    )
Esempio n. 12
0
class AnonymousTelemetry(Subsystem):
    options_scope = "anonymous-telemetry"
    help = "Options related to sending anonymous stats to the Pants project, to aid development."

    enabled = BoolOption(
        "--enabled",
        default=False,
        help=(
            f"Whether to send anonymous telemetry to the Pants project.\nTelemetry is sent "
            f"asynchronously, with silent failure, and does not impact build times or "
            f"outcomes.\n{_telemetry_docs_referral}."
        ),
        advanced=True,
    )
    repo_id = StrOption(
        "--repo-id",
        default=None,
        help=(
            f"An anonymized ID representing this repo.\nFor private repos, you likely want the "
            f"ID to not be derived from, or algorithmically convertible to, anything "
            f"identifying the repo.\nFor public repos the ID may be visible in that repo's "
            f"config file, so anonymity of the repo is not guaranteed (although user anonymity "
            f"is always guaranteed).\n{_telemetry_docs_referral}."
        ),
        advanced=True,
    )
Esempio n. 13
0
class ScalaInferSubsystem(Subsystem):
    options_scope = "scala-infer"
    help = "Options controlling which dependencies will be inferred for Scala targets."

    imports = BoolOption(
        "--imports",
        default=True,
        help=
        "Infer a target's dependencies by parsing import statements from sources.",
    )
    consumed_types = BoolOption(
        "--consumed-types",
        default=True,
        help=
        "Infer a target's dependencies by parsing consumed types from sources.",
    )
Esempio n. 14
0
class TerraformTool(TemplatedExternalTool):
    options_scope = "download-terraform"
    name = "terraform"
    help = "Terraform (https://terraform.io)"

    default_version = "1.0.7"
    default_url_template = (
        "https://releases.hashicorp.com/terraform/{version}/terraform_{version}_{platform}.zip"
    )
    default_url_platform_mapping = {
        "macos_arm64": "darwin_arm64",
        "macos_x86_64": "darwin_amd64",
        "linux_x86_64": "linux_amd64",
    }

    @classproperty
    def default_known_versions(cls):
        return [
            "1.0.7|macos_arm64 |cbab9aca5bc4e604565697355eed185bb699733811374761b92000cc188a7725|32071346",
            "1.0.7|macos_x86_64|80ae021d6143c7f7cbf4571f65595d154561a2a25fd934b7a8ccc1ebf3014b9b|33020029",
            "1.0.7|linux_x86_64|bc79e47649e2529049a356f9e60e06b47462bf6743534a10a4c16594f443be7b|32671441",
        ]

    tailor = BoolOption(
        "--tailor",
        default=True,
        help="If true, add `terraform_module` targets with the `tailor` goal.",
        advanced=True,
    )
Esempio n. 15
0
class RunSubsystem(GoalSubsystem):
    name = "run"
    help = softwrap("""
        Runs a binary target.

        This goal propagates the return code of the underlying executable.

        If your application can safely be restarted while it is running, you can pass
        `restartable=True` on your binary target (for supported types), and the `run` goal
        will automatically restart them as all relevant files change. This can be particularly
        useful for server applications.
        """)

    @classmethod
    def activated(cls, union_membership: UnionMembership) -> bool:
        return RunFieldSet in union_membership

    args = ArgsListOption(
        example="val1 val2 --debug",
        tool_name="the executed target",
        passthrough=True,
    )
    cleanup = BoolOption(
        "--cleanup",
        default=True,
        help=softwrap("""
            Whether to clean up the temporary directory in which the binary is chrooted.
            Set this to false to retain the directory, e.g., for debugging.

            Note that setting the global --process-cleanup option to false will also conserve
            this directory, along with those of all other processes that Pants executes.
            This option is more selective and controls just the target binary's directory.
            """),
    )
Esempio n. 16
0
class RunSubsystem(GoalSubsystem):
    name = "run"
    help = (
        "Runs a binary target.\n\n"
        "This goal propagates the return code of the underlying executable.\n\n"
        "If your application can safely be restarted while it is running, you can pass "
        "`restartable=True` on your binary target (for supported types), and the `run` goal "
        "will automatically restart them as all relevant files change. This can be particularly "
        "useful for server applications.")

    @classmethod
    def activated(cls, union_membership: UnionMembership) -> bool:
        return RunFieldSet in union_membership

    args = ArgsListOption(
        example="val1 val2 --debug",
        tool_name="the executed target",
        passthrough=True,
    )
    cleanup = BoolOption(
        "--cleanup",
        default=True,
        help=
        "Whether to clean up the temporary directory in which the binary is chrooted. "
        "Set to false to retain the directory, e.g., for debugging.",
    )
Esempio n. 17
0
class LintSubsystem(GoalSubsystem):
    name = "lint"
    help = "Run all linters and/or formatters in check mode."

    @classmethod
    def activated(cls, union_membership: UnionMembership) -> bool:
        return LintTargetsRequest in union_membership or LintFilesRequest in union_membership

    only = StrListOption(
        "--only",
        help=only_option_help("lint", "linter", "flake8", "shellcheck"),
    )
    skip_formatters = BoolOption(
        "--skip-formatters",
        default=False,
        help=softwrap(
            f"""
            If true, skip running all formatters in check-only mode.

            FYI: when running `{bin_name()} fmt lint ::`, there should be little performance
            benefit to using this flag. Pants will reuse the results from `fmt` when running `lint`.
            """
        ),
    )
    batch_size = IntOption(
        "--batch-size",
        advanced=True,
        default=128,
        help=style_batch_size_help(uppercase="Linter", lowercase="linter"),
    )
Esempio n. 18
0
class Protoc(TemplatedExternalTool):
    options_scope = "protoc"
    help = "The protocol buffer compiler (https://developers.google.com/protocol-buffers)."

    default_version = "3.11.4"
    default_known_versions = [
        "3.11.4|linux_arm64 |f24c9fa1fc4a7770b8a5da66e515cb8a638d086ad2afa633abb97137c5f029a8|1481946",
        "3.11.4|linux_x86_64|6d0f18cd84b918c7b3edd0203e75569e0c8caecb1367bbbe409b45e28514f5be|1591191",
        "3.11.4|macos_arm64 |8c6af11e1058efe953830ecb38324c0e0fd2fb67df3891896d138c535932e7db|2482119",
        "3.11.4|macos_x86_64|8c6af11e1058efe953830ecb38324c0e0fd2fb67df3891896d138c535932e7db|2482119",
    ]
    default_url_template = (
        "https://github.com/protocolbuffers/protobuf/releases/download/"
        "v{version}/protoc-{version}-{platform}.zip")
    default_url_platform_mapping = {
        "linux_arm64": "linux-aarch_64",
        "linux_x86_64": "linux-x86_64",
        "macos_arm64":
        "osx-x86_64",  # May require rosetta, but output is arch-independent
        "macos_x86_64": "osx-x86_64",
    }

    dependency_inference = BoolOption(
        "--dependency-inference",
        default=True,
        help=
        ("Infer Protobuf dependencies on other Protobuf files by analyzing import statements."
         ),
    )

    def generate_exe(self, plat: Platform) -> str:
        return "./bin/protoc"
Esempio n. 19
0
class ThriftPythonSubsystem(Subsystem):
    options_scope = "python-thrift"
    help = "Options specific to generating Python from Thrift using Apache Thrift"

    gen_options = StrListOption(
        "--options",
        help=softwrap("""
            Code generation options specific to the Python code generator to pass to the
            Apache `thift` binary via the `-gen py` argument.
            See `thrift -help` for supported values.
            """),
    )
    infer_runtime_dependency = BoolOption(
        "--infer-runtime-dependency",
        default=True,
        help=softwrap("""
            If True, will add a dependency on a `python_requirement` target exposing the `thrift`
            module (usually from the `thrift` requirement).

            If `[python].enable_resolves` is set, Pants will only infer dependencies on
            `python_requirement` targets that use the same resolve as the particular
            `thrift_source` / `thrift_source` target uses, which is set via its
            `python_resolve` field.

            Unless this option is disabled, Pants will error if no relevant target is found or
            more than one is found which causes ambiguity.
            """),
        advanced=True,
    )
Esempio n. 20
0
class ScalaSubsystem(Subsystem):
    options_scope = "scala"
    help = "Scala programming language"

    _version_for_resolve = DictOption[str](
        "--version-for-resolve",
        help=softwrap("""
            A dictionary mapping the name of a resolve to the Scala version to use for all Scala
            targets consuming that resolve.

            All Scala-compiled jars on a resolve\'s classpath must be "compatible" with one another and
            with all Scala-compiled first-party sources from `scala_sources` (and other Scala target types)
            using that resolve. The option sets the Scala version that will be used to compile all
            first-party sources using the resolve. This ensures that the compatibility property is
            maintained for a resolve. To support multiple Scala versions, use multiple resolves.
            """),
    )
    tailor_source_targets = BoolOption(
        "--tailor-source-targets",
        default=True,
        help=softwrap("""
            If true, add `scala_sources`, `scala_junit_tests`, and `scalatest_tests` targets with
            the `tailor` goal."""),
        advanced=True,
    )

    def version_for_resolve(self, resolve: str) -> str:
        version = self._version_for_resolve.get(resolve)
        if version:
            return version
        return DEFAULT_SCALA_VERSION
    class Foo(Subsystem):
        options_scope = "foo"
        help = "A foo."

        opt2 = BoolOption("--opt2",
                          default=True,
                          advanced=True,
                          help="Option 2")
Esempio n. 22
0
class Hadolint(TemplatedExternalTool):
    options_scope = "hadolint"
    name = "Hadolint"
    help = "A linter for Dockerfiles."

    default_version = "v2.10.0"
    default_known_versions = [
        "v2.10.0|macos_x86_64|59f0523069a857ae918b8ac0774230013f7bcc00c1ea28119c2311353120867a|2514960",
        "v2.10.0|macos_arm64 |59f0523069a857ae918b8ac0774230013f7bcc00c1ea28119c2311353120867a|2514960",  # same as mac x86
        "v2.10.0|linux_x86_64|8ee6ff537341681f9e91bae2d5da451b15c575691e33980893732d866d3cefc4|2301804",
        "v2.10.0|linux_arm64 |b53d5ab10707a585c9e72375d51b7357522300b5329cfa3f91e482687176e128|27954520",
    ]
    default_url_template = (
        "https://github.com/hadolint/hadolint/releases/download/{version}/hadolint-{platform}"
    )
    default_url_platform_mapping = {
        "macos_arm64": "Darwin-x86_64",
        "macos_x86_64": "Darwin-x86_64",
        "linux_arm64": "Linux-arm64",
        "linux_x86_64": "Linux-x86_64",
    }

    skip = SkipOption("lint")
    args = ArgsListOption(example="--format json")
    config = FileOption(
        "--config",
        default=None,
        advanced=True,
        help=lambda cls: softwrap(f"""
            Path to an YAML config file understood by Hadolint
            (https://github.com/hadolint/hadolint#configure).

            Setting this option will disable `[{cls.options_scope}].config_discovery`. Use
            this option if the config is located in a non-standard location.
            """),
    )
    config_discovery = BoolOption(
        "--config-discovery",
        default=True,
        advanced=True,
        help=lambda cls: softwrap(f"""
            If true, Pants will include all relevant config files during runs
            (`.hadolint.yaml` and `.hadolint.yml`).

            Use `[{cls.options_scope}].config` instead if your config is in a
            non-standard location.
            """),
    )

    def config_request(self) -> ConfigFilesRequest:
        # Refer to https://github.com/hadolint/hadolint#configure for how config files are
        # discovered.
        return ConfigFilesRequest(
            specified=self.config,
            specified_option_name=f"[{self.options_scope}].config",
            discovery=self.config_discovery,
            check_existence=[".hadolint.yaml", ".hadolint.yml"],
        )
Esempio n. 23
0
class PexRuntimeEnvironment(Subsystem):
    options_scope = "pex"
    help = "How Pants uses Pex to run Python subprocesses."

    # TODO(#9760): We'll want to deprecate this in favor of a global option which allows for a
    #  per-process override.
    _executable_search_paths = StrListOption(
        "--executable-search-paths",
        default=["<PATH>"],
        help=softwrap("""
            The PATH value that will be used by the PEX subprocess and any subprocesses it
            spawns.

            The special string `"<PATH>"` will expand to the contents of the PATH env var.
            """),
        advanced=True,
        metavar="<binary-paths>",
    )
    _verbosity = IntOption(
        "--verbosity",
        default=0,
        help=
        "Set the verbosity level of PEX logging, from 0 (no logging) up to 9 (max logging).",
        advanced=True,
    )
    venv_use_symlinks = BoolOption(
        "--venv-use-symlinks",
        default=False,
        help=softwrap("""
            When possible, use venvs whose site-packages directories are populated with symlinks.

            Enabling this can save space in the `--named-caches-dir` directory
            and lead to slightly faster execution times for Pants Python goals. Some
            distributions do not work with symlinked venvs though, so you may not be able to
            enable this optimization as a result.
            """),
        advanced=True,
    )

    @memoized_method
    def path(self, env: Environment) -> tuple[str, ...]:
        def iter_path_entries():
            for entry in self._executable_search_paths:
                if entry == "<PATH>":
                    path = env.get("PATH")
                    if path:
                        yield from path.split(os.pathsep)
                else:
                    yield entry

        return tuple(OrderedSet(iter_path_entries()))

    @property
    def verbosity(self) -> int:
        level = self._verbosity
        if level < 0 or level > 9:
            raise ValueError("verbosity level must be between 0 and 9")
        return level
Esempio n. 24
0
class Black(PythonToolBase):
    options_scope = "black"
    name = "Black"
    help = "The Black Python code formatter (https://black.readthedocs.io/)."

    default_version = "black==22.1.0"
    default_main = ConsoleScript("black")

    register_interpreter_constraints = True
    default_interpreter_constraints = ["CPython>=3.7,<4"]

    register_lockfile = True
    default_lockfile_resource = ("pants.backend.python.lint.black", "black.lock")
    default_lockfile_path = "src/python/pants/backend/python/lint/black/black.lock"
    default_lockfile_url = git_url(default_lockfile_path)
    default_extra_requirements = ['typing-extensions>=3.10.0.0; python_version < "3.10"']

    skip = SkipOption("fmt", "lint")
    args = ArgsListOption(example="--target-version=py37 --quiet")
    export = ExportToolOption()
    config = FileOption(
        "--config",
        default=None,
        advanced=True,
        help=lambda cls: softwrap(
            f"""
            Path to a TOML config file understood by Black
            (https://github.com/psf/black#configuration-format).

            Setting this option will disable `[{cls.options_scope}].config_discovery`. Use
            this option if the config is located in a non-standard location.
            """
        ),
    )
    config_discovery = BoolOption(
        "--config-discovery",
        default=True,
        advanced=True,
        help=lambda cls: softwrap(
            f"""
            If true, Pants will include any relevant pyproject.toml config files during runs.

            Use `[{cls.options_scope}].config` instead if your config is in a
            non-standard location.
            """
        ),
    )

    def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
        # Refer to https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#where-black-looks-for-the-file
        # for how Black discovers config.
        candidates = {os.path.join(d, "pyproject.toml"): b"[tool.black]" for d in ("", *dirs)}
        return ConfigFilesRequest(
            specified=self.config,
            specified_option_name=f"[{self.options_scope}].config",
            discovery=self.config_discovery,
            check_content=candidates,
        )
Esempio n. 25
0
class ListSubsystem(LineOriented, GoalSubsystem):
    name = "list"
    help = "Lists all targets matching the file or target arguments."

    documented = BoolOption(
        "--documented",
        default=False,
        help="Print only targets that are documented with a description.",
    )
Esempio n. 26
0
class ThriftSubsystem(Subsystem):
    options_scope = "thrift"
    help = "General Thrift IDL settings (https://thrift.apache.org/)."

    dependency_inference = BoolOption(
        "--dependency-inference",
        default=True,
        help=("Infer Thrift dependencies on other Thrift files by analyzing import statements."),
    )
Esempio n. 27
0
class SoapSubsystem(Subsystem):
    options_scope = "soap"
    help = "General SOAP/WSDL codegen settings."

    tailor = BoolOption(
        "--tailor",
        default=True,
        help="If true, add `wsdl_sources` targets with the `tailor` goal.",
        advanced=True,
    )
Esempio n. 28
0
class AvroSubsystem(Subsystem):
    options_scope = "avro"
    help = "General Avro codegen settings."

    tailor = BoolOption(
        "--tailor",
        default=True,
        help="If true, add `avro_sources` targets with the `tailor` goal.",
        advanced=True,
    )
Esempio n. 29
0
class CCInferSubsystem(Subsystem):
    options_scope = "cc-infer"
    help = "Options controlling which dependencies will be inferred for CC targets."

    includes = BoolOption(
        "--includes",
        default=True,
        help=
        "Infer a target's dependencies by parsing #include statements from sources.",
    )

    # TODO: This option may move to a proper `cc` subsystem once compilation is implemented. It may also
    # change depending on how we want to model in-repo includes.
    include_from_source_roots = BoolOption(
        "--include-from-source-roots",
        default=True,
        help=
        "Infer a target's dependencies by trying to include relative to source roots.",
    )
Esempio n. 30
0
class PeekSubsystem(Outputting, GoalSubsystem):
    """Display detailed target information in JSON form."""

    name = "peek"
    help = "Display BUILD target info"

    exclude_defaults = BoolOption(
        "--exclude-defaults",
        default=False,
        help="Whether to leave off values that match the target-defined default values.",
    )