https://pantsbuild.org/ logo
#general
Title
# general
f

full-oyster-41619

11/03/2020, 9:12 AM
hi, I am upgrading from pants
2.0.0b1
to
2.0.0
. I have a custom versioning function. while moving between version, I've noticed this output when running
./pants -v
(see attach log file) this is my custom versioning registry.py file
Copy code
import logging

from pants.base.build_environment import get_buildroot
from pants.backend.python.goals.setup_py import SetupKwargs, SetupKwargsRequest
from pants.engine.addresses import Addresses
from pants.engine.rules import Get, collect_rules, rule, _uncacheable_rule
from pants.engine.target import Target, TransitiveTargets
from pants.backend.python.target_types import PythonProvidesField
from pants.engine.unions import UnionRule

from utilities.versioning import git


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

# use "@_uncacheable_rule" instead of "@rule" to avoid caching
# Note: from pants team "The API might change a little (probably just a rename), which we'll be happy to help walk through when the time comes that we make it public."
# @rule
@_uncacheable_rule
async def setup_kwargs_plugin(request: CustomSetupKwargsRequest) -> SetupKwargs:
    kwargs = request.explicit_kwargs.copy()
    build_root = get_buildroot()
    target_path = request.target.address.spec_path
    transitive_targets = await Get(TransitiveTargets, Addresses([request.target.address]))
    # in pants v2 files are now the "atomic unit" for Pants, rather than targets
    # <https://www.pantsbuild.org/docs/how-to-upgrade-pants-2-0#files-are-now-the-atomic-unit-rather-than-targets-130-vs-20>
    transitive_dependencies_paths = {tgt.address.spec_path for tgt in transitive_targets.dependencies}
    kwargs["version"] = git.get_version(build_root, target_path, transitive_dependencies_paths)
    logging.info(f'lib name: {kwargs["name"]}, lib version: {kwargs["version"]}')

    return SetupKwargs(kwargs, address=request.target.address)


def rules():
    return (*collect_rules(), UnionRule(SetupKwargsRequest, CustomSetupKwargsRequest))
6 Views