I'm attempting my first plugin (The time has come ...
# general
p
I'm attempting my first plugin (The time has come =D) Following this tutorial.. and I'm getting suck at the first chunk. Creating the target. Any advice?
Copy code
geethree@masterblaster:~/exclosure/repos/exclosure$ git diff
diff --git a/pants.toml b/pants.toml
index 0906e21e..1f266364 100644
--- a/pants.toml
+++ b/pants.toml
@@ -2,6 +2,10 @@
 unmatched_build_file_globs = "error"
 
 pants_version = "2.17.0"
+
+# Specifying the path to our plugin's top-level folder using the `pythonpath` option:
+pythonpath = ["%(buildroot)s/pants-plugins"]
+
 backend_packages = [
   "pants.backend.build_files.fmt.black",
   "pants.backend.codegen.protobuf.python",
@@ -23,6 +27,8 @@ backend_packages = [
   # "pants.backend.python.lint.isort",
   # "pants.backend.python.lint.pydocstyle",
   "pants.backend.python.lint.pylint",
+
+  "project_version",
 ]
 
 pants_ignore = [
geethree@masterblaster:~/exclosure/repos/exclosure$ tree pants-plugins/
pants-plugins/
└── project_version
    ├── register.py
    └── targets.py

1 directory, 2 files
geethree@masterblaster:~/exclosure/repos/exclosure$ pants help project_version
07:05:21.86 [INFO] waiting for pantsd to start...
07:05:23.26 [INFO] pantsd started
Traceback (most recent call last):
  File "/home/geethree/.cache/nce/68f5608a60df9b97aab453d453817a4ded400d1d8ec7ede7ec14bcac83421a7b/bindings/venvs/2.17.0/lib/python3.9/site-packages/pants/init/extension_loader.py", line 141, in load_backend
    module = importlib.import_module(backend_module)
  File "/home/geethree/.cache/nce/2b6e146234a4ef2a8946081fc3fbfffe0765b80b690425a49ebe40b47c33445b/cpython-3.9.16+20230507-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/geethree/exclosure/repos/exclosure/pants-plugins/project_version/register.py", line 4, in <module>
    from project_version.target_types import ProjectVersionTarget
ModuleNotFoundError: No module named 'project_version.target_types'
07:05:23.46 [ERROR] Failed to load the project_version.register backend: ModuleNotFoundError("No module named 'project_version.target_types'")


Use --print-stacktrace for more error details and/or -ldebug for more logs. 
See <https://www.pantsbuild.org/v2.17/docs/troubleshooting> for common issues.
Consider reaching out for help: <https://www.pantsbuild.org/v2.17/docs/getting-help>
l
are you missing an
Copy code
__init__.py
within project_version? It seems the problem is in your
register.py
which has a line:
Copy code
from project_version.target_types import ProjectVersionTarget
but your tree only shows a
targets.py
file
As you start your first plugin, you can keep everything in your
register.py
including the definitions of your targets
p
I see. Looks like in mainline pantsbuild/pants the documentation has been updated as well https://github.com/pantsbuild/pants/pull/19369
w
Just to throw it out there, I have an old first-plugin tutorial as well. Similar content, slightly different angle. May be useful as well? I don’t know where it went, but I had a template generator as well at some point. Either as a GH template, or as a CLI command. I’ll try to find that https://sureshjoshi.com/development/first-pants-plugin
👍 1