Can I have resources on a in-repo plugin? it seems...
# general
m
Can I have resources on a in-repo plugin? it seems in-repo plugin ignore the BUILD files. I have a plugin at
pants-plugin/jvm_stage
, BUILD file:
Copy code
python_sources(resolve="pants-plugins", dependencies=[":java_resources"])
resources(name="java_resources", sources=["*.java", "strip_jar.lock"])

java_sources(name="strip_jar", resolve="strip_jar_dev")

jvm_artifact(
    name="reproducible-builds-jvm-stripper",
    group="net.bzzt",
    artifact="reproducible-builds-jvm-stripper",    
    version="0.9",
    resolve="strip_jar_dev",
    packages=["io.github.zlika.reproducible.**"]
)
then in the plugin I'm trying:
Copy code
@rule
def generate_strip_jar_lockfile_request(
    _: StripJarToolLockfileSentinel,
) -> GenerateJvmLockfileFromTool:
    return GenerateJvmLockfileFromTool(
        artifact_inputs=FrozenOrderedSet(
            {
                "net.bzzt:reproducible-builds-jvm-stripper:0.9",                
            }
        ),
        artifact_option_name="n/a",
        lockfile_option_name="n/a",
        resolve_name=StripJarToolLockfileSentinel.resolve_name,
        read_lockfile_dest=DEFAULT_TOOL_LOCKFILE,
        write_lockfile_dest="pants-plugins/jvm_stage/strip_jar.lock",
        default_lockfile_resource=(
            "jvm_stage",
            "strip_jar.lock",
        ),
    )
When I'm trying the plugin it fails with:
Copy code
Engine traceback:
  in select
  in pants.core.goals.package.package_asset
  in jvm_stage.rules.package_jvm_stage (modules/maitred-node/src/unit/maitred/node:main)
  in jvm_stage.strip_jar.resolve_fallible_result_to_strip_jar
  in jvm_stage.strip_jar.strip_jar
  in jvm_stage.strip_jar.build_processors
  in pants.jvm.resolve.coursier_fetch.materialize_classpath_for_tool
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/resources.py", line 97, in open_binary
    return open(full_path, mode='rb')
FileNotFoundError: [Errno 2] No such file or directory: '/Users/somdoron/git/unit-finance/strip_jar.lock'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/somdoron/.cache/pants/setup/bootstrap-Darwin-arm64/pants.sVxb8A/install/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 705, in native_engine_generator_send
    res = func.send(arg)
  File "/Users/somdoron/.cache/pants/setup/bootstrap-Darwin-arm64/pants.sVxb8A/install/lib/python3.9/site-packages/pants/jvm/resolve/coursier_fetch.py", line 744, in materialize_classpath_for_tool
    lockfile_bytes = importlib.resources.read_binary(
  File "/opt/homebrew/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/resources.py", line 126, in read_binary
    with open_binary(package, resource) as fp:
  File "/opt/homebrew/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/resources.py", line 111, in open_binary
    raise FileNotFoundError(message)
FileNotFoundError: 'strip_jar.lock' resource not found in 'jvm_stage'
What am I missing?
1
I've managed to solve it by using the path of the lock file instead of
DEFAULT_TOOL_LOCKFILE
h
Am I understanding correctly that your plugin is trying to create
strip_jar.lock
? So that warning about it not existing is correct?
m
it was suppose to exist as resource, anyway, the issue was
init.py
file was missing, it works now with the example above.
h
Ah great