コード例 #1
0
async def setup_kwargs_plugin(request: CustomSetupKwargsRequest) -> SetupKwargs:

    version_digest_contents = await Get(
        DigestContents,
        PathGlobs(
            [f"{request.target.address.spec_path}/VERSION"],
            description_of_origin="`setup_py()` plugin",
            glob_match_error_behavior=GlobMatchErrorBehavior.error,
        ),
    )
    version = version_digest_contents[0].content.decode().strip()

    package_name = request.target[PythonProvidesField].value.name

    local_version = parse(version)
    if isinstance(local_version, LegacyVersion):
        raise ValueError(f"Version {local_version} of {package_name} is not valid.")

    desc_digest_contents = await Get(
        DigestContents,
        PathGlobs(
            [f"{request.target.address.spec_path}/README.md"],
            description_of_origin="`setup_py()` plugin",
            glob_match_error_behavior=GlobMatchErrorBehavior.error,
        ),
    )
    long_description = desc_digest_contents[0].content.decode().strip()

    changelog_digest_contents = await Get(
        DigestContents,
        PathGlobs(
            [f"{request.target.address.spec_path}/CHANGELOG.md"],
            description_of_origin="`setup_py()` plugin",
            glob_match_error_behavior=GlobMatchErrorBehavior.error,
        ),
    )
    changelog = changelog_digest_contents[0].content.decode().strip()

    return SetupKwargs(
        {
            **request.explicit_kwargs,
            "version": version,
            "long_description": f"{long_description}\n{changelog}",
            "long_description_content_type": "text/markdown"
         },
        address=request.target.address
    )
コード例 #2
0
def setup_kwargs_plugin(request: PluginSetupKwargsRequest) -> SetupKwargs:
    return SetupKwargs(
        {
            **request.explicit_kwargs, "plugin_demo": "hello world"
        },
        address=request.target.address)
コード例 #3
0
def setup_kwargs_plugin(request: PluginSetupKwargsRequest) -> SetupKwargs:
    if "setup_script" in request.explicit_kwargs:
        kwargs = request.explicit_kwargs
    else:
        kwargs = {**request.explicit_kwargs, "plugin_demo": "hello world"}
    return SetupKwargs(kwargs, address=request.target.address)
コード例 #4
0
async def pants_setup_kwargs(request: PantsSetupKwargsRequest,
                             pants_releases: PantsReleases) -> SetupKwargs:
    kwargs = request.explicit_kwargs.copy()

    # Validate that required fields are set.
    if not kwargs["name"].startswith("pantsbuild.pants"):
        raise ValueError(
            f"Invalid `name` kwarg in the `provides` field for {request.target.address}. The name "
            f"must start with 'pantsbuild.pants', but was {kwargs['name']}.")
    if "description" not in kwargs:
        raise ValueError(
            f"Missing a `description` kwarg in the `provides` field for {request.target.address}."
        )

    # Add classifiers. We preserve any that were already set.
    standard_classifiers = [
        "Intended Audience :: Developers",
        "License :: OSI Approved :: Apache Software License",
        "Operating System :: MacOS :: MacOS X",
        "Operating System :: POSIX :: Linux",
        "Programming Language :: Python",
        "Topic :: Software Development :: Build Tools",
    ]
    kwargs["classifiers"] = [
        *standard_classifiers, *kwargs.get("classifiers", [])
    ]

    # Determine the long description by reading from ABOUT.rst and the release notes.
    notes_file = pants_releases.notes_file_for_version(PANTS_SEMVER)
    digest_contents = await Get(
        DigestContents,
        PathGlobs(
            ["src/python/pants/ABOUT.rst", notes_file],
            description_of_origin="Pants release files",
            glob_match_error_behavior=GlobMatchErrorBehavior.error,
        ),
    )
    long_description = "\n".join(file_content.content.decode()
                                 for file_content in digest_contents)

    # Hardcode certain kwargs and validate that they weren't already set.
    hardcoded_kwargs = dict(
        version=VERSION,
        long_description=long_description,
        long_description_content_type="text/x-rst",
        url="https://github.com/pantsbuild/pants",
        project_urls={
            "Documentation": "https://www.pantsbuild.org/",
            "Source": "https://github.com/pantsbuild/pants",
            "Tracker": "https://github.com/pantsbuild/pants/issues",
        },
        license="Apache License, Version 2.0",
        zip_safe=True,
    )
    conflicting_hardcoded_kwargs = set(kwargs.keys()).intersection(
        hardcoded_kwargs.keys())
    if conflicting_hardcoded_kwargs:
        raise ValueError(
            f"These kwargs should not be set in the `provides` field for {request.target.address} "
            "because Pants's internal plugin will automatically set them: "
            f"{sorted(conflicting_hardcoded_kwargs)}")
    kwargs.update(hardcoded_kwargs)

    return SetupKwargs(kwargs, address=request.target.address)
コード例 #5
0
async def setup_kwargs_plugin(request: GraplSetupKwargsRequest) -> SetupKwargs:

    explicit_kwargs = request.explicit_kwargs

    if "name" not in explicit_kwargs:
        raise ValueError(
            f"Must provide a `name` key in the `provides` field for {request.target.address}"
        )

    if "description" not in explicit_kwargs:
        raise ValueError(
            f"Must provide a `description` key in the `provides` field for {request.target.address}"
        )

    if "version" not in explicit_kwargs:
        raise ValueError(
            f"Must provide a `version` key in the `provides` field for {request.target.address}"
        )

    # Look for a README.md file as a sibling to the BUILD file this
    # target is defined in.
    default_readme_path = f"{request.target.address.spec_path}/README.md"

    if "long_description" in explicit_kwargs:
        raise ValueError(
            f"Do not provide a `long_description` in the `provides` field for {request.target.address}. "
            f"Instead, either place a `README.md` file at {default_readme_path} "
            "OR specify a path to an appropriate Markdown file, relative to the Pants root "
            "in the `readme` key in the `provides` field")

    # "readme" is a key that we (Grapl) use; it's not in standard
    # Pants. There may be some changes coming soon, though:
    # https://github.com/pantsbuild/pants/issues/11554
    readme_path = (explicit_kwargs.pop("readme")
                   if "readme" in explicit_kwargs else default_readme_path)

    logger.info(f"Reading long_description from {readme_path}")
    digest_contents = await Get(
        DigestContents,
        PathGlobs(
            [readme_path],
            description_of_origin=
            f"README resolution in `setup_py()` plugin ({__file__}) for {request.target.address}",
            glob_match_error_behavior=GlobMatchErrorBehavior.error,
        ),
    )
    long_description = "\n".join(file_content.content.decode()
                                 for file_content in digest_contents)
    explicit_kwargs["long_description"] = long_description

    # Set hardcoded values, raising an exception if any of them are
    # overridden by the user.
    conflicts = set(explicit_kwargs.keys()).intersection(
        HARDCODED_KWARGS.keys())
    if conflicts:
        raise ValueError(
            f"These kwargs should not be set in the `provides` field for {request.target.address} "
            "because our internal plugin will automatically set them: "
            f"{sorted(conflicts)}")
    explicit_kwargs.update(HARDCODED_KWARGS)

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