Hello everyone, I am trying to write a plugin that...
# plugins
a
Hello everyone, I am trying to write a plugin that will dynamically generate the version number
Copy code
from pants.backend.python.goals.setup_py import SetupKwargsRequest
from pants.engine.target import Target

from pants.engine.rules import collect_rules
from pants.engine.unions import UnionRule
from pants.backend.python.goals.setup_py import SetupKwargs
from pants.engine.rules import rule

class CustomSetupKwargsRequest(SetupKwargsRequest):
    @classmethod
    def is_applicable(cls, _: Target) -> bool:
        return True

@rule
async def setup_kwargs_plugin(request: CustomSetupKwargsRequest) -> SetupKwargs:
    return SetupKwargs(
        {**request.explicit_kwargs, "version": "1.4"}, address=request.target.address
    )


def rules():
    return [
        *collect_rules(),
        UnionRule(SetupKwargsRequest, CustomSetupKwargsRequest),
    ]
And my BUILD file looks like this:
Copy code
python_distribution(
.....
	provides=setup_py(
			name="testapp",
            version="1.0.3",
		),
	setup_py_commands=["sdist", "bdist_wheel"]
)
If I try to remove the version="1.0.3" - it complains Missing a
version
kwarg in the
provides
Am I missing anything?
h
Hello! This all looks right, but it’s possible the plugin is not being activated. Can you please share the
GLOBAL
section of your
pants.toml
?
a
Copy code
[GLOBAL]
pythonpath = ["%(buildroot)s/pants-plugins"]
And directory structure for pants-plugins looks like this • pants-plugins --register.py - will above code
h
K, that part is right. Have you added to
backend_packages
path_<http://to.my|to.my>_plugin
?
Oh, one simple way to debug. Add logging https://www.pantsbuild.org/docs/rules-api-logging#adding-logging You can
<http://logger.info|logger.info>()
inside your
@rule
to confirm the plugin is being loaded
a
this is my full pants.toml
Copy code
[GLOBAL]
pythonpath = ["%(buildroot)s/pants-plugins"]
pants_version = "2.1.0"
backend_packages = ["pants.backend.python"]
[source]
root_patterns = [
  './lib',
  './apps',
  './pkgs',
  '/',
]
h
okay, you haven’t yet activated your plugin then. Re-read https://www.pantsbuild.org/docs/plugins-overview#enabling-plugins-with-registerpy, you need to change
backend_packages
as well
w
the name of your plugin is its module name relative to where you put it on the
pythonpath
, and as Eric said, you need to mention it in
backend_packages
a
oh! 😞
thankyou,
h
You’re welcome! Lots of moving parts here, I’ve been tripped up by things like that before too
❤️ 1
Hey Nadeem, how'd the rest of the plugin development go? Anything we can help with?