I'm getting a message: "Unknown entity: prettier" ...
# plugins
i
I'm getting a message: "Unknown entity: prettier" when trying to get the most bare bones plugin working w/
./pants help prettier
🧵
subsystem.py
Copy code
import os.path

from pants.core.util_rules.external_tool import ExternalTool
from pants.engine.platform import Platform
from pants.engine.rules import collect_rules
from pants.option.custom_types import file_option, shell_str


class Prettier(ExternalTool):
    options_scope = "prettier"
    help = "An opinionated code formatter."

    @classmethod
    def register_options(cls, register):
        super().register_options(register)
        register(
            "--skip",
            type=bool,
            default=False,
            help="Don't use prettier when running `./pants fmt` or `./pants lint`.",
        )

    default_version = "2.5.1"
    default_known_versions = [
        "2.5.1|macos_arm64|86c6af269a5d6e15924d8d718ceb534542549ab94d66deade740d1465fa89d79|3168093",
        "2.5.1|macos_x86_64|86c6af269a5d6e15924d8d718ceb534542549ab94d66deade740d1465fa89d79|3168093",
        "2.5.1|linux_arm64|86c6af269a5d6e15924d8d718ceb534542549ab94d66deade740d1465fa89d79|3168093",
        "2.5.1|linux_x86_64|86c6af269a5d6e15924d8d718ceb534542549ab94d66deade740d1465fa89d79|3168093",
    ]

    def generate_url(self, plat: Platform) -> str:
        return "<https://github.com/prettier/prettier/archive/refs/tags/{version}.tar.gz>".format(
            version=self.version
        )

    def generate_exe(self, plat: Platform) -> str:
        prettier = "prettier-{version}".format(version=self.version)
        return "." + os.path.join("", prettier, "bin", "prettier.js")

def rules():
    return collect_rules()
register.py
Copy code
"""Prettier - An opinionated code formatter

<https://prettier.io>
"""

from prettier import subsystem

def rules():
    return [*subsystem.rules()]

def target_types():
    return []
pants.toml
Copy code
[GLOBAL]
pants_version = "2.8.0"
pythonpath = ["%(buildroot)s/pants-plugins"]

backend_packages.add = [
  "pants.backend.python",
  "prettier"
]

[source]
root_patterns = [
  "pants-plugins"
]

[python]
interpreter_constraints = [">=3.9"]
w
mmm… so, a tricky gotcha about
collect_rules()
is that it will not collect a
Subsystem
unless it sees it in the argument list of a
@rule
👍 1
since that subsystem is unused, it doesn’t end up registered
we could probably change that at this point, since the only reason to create a subsystem now (in v2) is to use it in a
@rule
👍 1
but: to confirm that that is what is going on: you can add a
@rule
that consumes the
Subsystem
h
Or add SubsystemRule(Prettier) to your rules function. From pants.engine.rules +1 to changing collect_rules
i
It looked too simple to be true
h
Oh didn't realize that was incorrect, boo. Thanks for flagging!
i
success!
❤️ 1
🎉 1