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

salmon-nest-5801

05/05/2021, 11:41 PM
Given this file structure, how can I read the contents of the setup.cfg file in a plugin, given that I have the
request.target.address
of the BUILD file? I've tried using
await Get(DigestContents, ...)
targeting a PathGlob to that file path, but it causes infinite errors complaining about the file system changing 🤔
h

happy-kitchen-89482

05/05/2021, 11:47 PM
Offhand it sounds like that should work. I've seen that infinite filesystem changing loop, and we figured out the cause but of course now I can't remember what it was. @hundreds-father-404 you probably remember?
h

hundreds-father-404

05/05/2021, 11:47 PM
Hello! Hm, what are the errors? Indeed it should be await Get(DigestContents, PathGlobs(["path/to/f.py"]) inside an async @rule
I don't remember that Benjy, hm. Do you remember any of the context for when that happened?
s

salmon-nest-5801

05/05/2021, 11:53 PM
This doesn't work:
Copy code
from pants.backend.python.goals.setup_py import SetupKwargs, SetupKwargsRequest
from pants.engine.fs import DigestContents, GlobMatchErrorBehavior, PathGlobs
from pants.engine.rules import Get, collect_rules, rule
from pants.engine.target import Target
from pants.engine.unions import UnionRule


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


def rules():
    return [
        *collect_rules(),
        UnionRule(SetupKwargsRequest, DeclarativeSetupKwargsRequest),
    ]


@rule
async def setup_kwargs_plugin(request: DeclarativeSetupKwargsRequest) -> SetupKwargs:
    digest_contents = await Get(
        DigestContents,
        PathGlobs(
            [f"{request.target.address.spec_path}/setup.cfg"],
            description_of_origin="python declarative setup plugin",
            glob_match_error_behavior=GlobMatchErrorBehavior,
        ),
    )
    declarative_setup_contents = digest_contents[0].content.decode()
    print(declarative_setup_contents)
    return SetupKwargs({**request.explicit_kwargs}, address=request.target.address)
You get this error:
Copy code
(vims-next) C02F9412MD6R-ML:vims-next taylocj1$ ./pants package backend/base
19:52:14.66 [ERROR] panic at 'called `Result::unwrap()` on an `Err` value: "Could not get field `value`: PyErr { ptype: <class \'AttributeError\'>, pvalue: Some(AttributeError(\'value\')), ptraceback: Some(<traceback object at 0x10e710380>) }"', src/externs/mod.rs:225
19:52:14.66 [ERROR] Please set RUST_BACKTRACE=1, re-run, and then file a bug at <https://github.com/pantsbuild/pants/issues>.
19:52:14.66 [INFO] Filesystem changed during run: retrying `@rule(pants.backend.python.goals.setup_py.package_python_dist)` in 500ms...
repeatedly, over and over, until you manually kill the build
Oh, and the suggested action doesn't help. Setting RUST_BACKTRACE=1 doesn't seem to change anything in the output
h

hundreds-father-404

05/06/2021, 12:38 AM
Ah ha.
GlobMatchErrorBehavior
should be
GlobMatchErrorBehavior.error
. Sorry that's an atrocious error message, that's from the Rust FFI boundary
s

salmon-nest-5801

05/06/2021, 1:46 PM
🤦 Ooof. Sorry about that, missed a tiny bit of the example in the docs, but yep, that's exactly it - works perfectly now. Thanks 😄
h

hundreds-father-404

05/06/2021, 2:37 PM
No need to apologize - the error should have been more helpful. I'll open an issue
2 Views