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

refined-addition-53644

01/04/2022, 11:44 AM
How to fix errors like
Unable to import
generated by
pylint
when running
Copy code
./pants lint ::
This is from an internal pants plugin
Copy code
12:40:29.39 [ERROR] Completed: Lint using Pylint - Pylint failed (exit code 30).
************* Module pants-plugins.internal_plugins.register
pants-plugins/internal_plugins/register.py:1:0: C0114: Missing module docstring (missing-module-docstring)
pants-plugins/internal_plugins/register.py:1:0: E0401: Unable to import 'pants.backend.python.goals.setup_py' (import-error)
pants-plugins/internal_plugins/register.py:2:0: E0401: Unable to import 'pants.engine.fs' (import-error)
pants-plugins/internal_plugins/register.py:3:0: E0401: Unable to import 'pants.engine.rules' (import-error)
pants-plugins/internal_plugins/register.py:4:0: E0401: Unable to import 'pants.engine.target' (import-error)
pants-plugins/internal_plugins/register.py:5:0: E0401: Unable to import 'pants.engine.unions' (import-error)
pants-plugins/internal_plugins/register.py:8:0: C0115: Missing class docstring (missing-class-docstring)
pants-plugins/internal_plugins/register.py:10:4: C0116: Missing function or method docstring (missing-function-docstring)
pants-plugins/internal_plugins/register.py:8:0: R0903: Too few public methods (1/2) (too-few-public-methods)
pants-plugins/internal_plugins/register.py:58:0: C0116: Missing function or method docstring (missing-function-docstring)
It's only the linting is failing. I can use this plugin successfully otherwise.
c

curved-television-6568

01/04/2022, 12:11 PM
Do you have a dependency on
pantsbuild.pants
for you plugin ? That is, is there
python_requirement
for
pantsbuild.pants
to have a dependency on in any of your BUILD files?
There is a
pants_requirements
target you can use for this particular purpose, and will give you a requirement matching that of the version of pants you are using to build your plugin, by default.
r

refined-addition-53644

01/04/2022, 1:14 PM
Thank you very much! I made the changes as suggested in the documentation line you have posted. This is how the
pants.toml
looks like
Copy code
[GLOBAL]
pants_version = "2.8.0"
pythonpath = ["%(buildroot)s/pants-plugins"]
backend_packages.add = [
    "pants.backend.python",
    "pants.backend.python.lint.black",
    "pants.backend.python.lint.docformatter",
    "pants.backend.experimental.docker",
    "pants.backend.python.lint.flake8",
    "pants.backend.experimental.docker.lint.hadolint",
    "pants.backend.python.lint.pylint",
    "pants.backend.python.typecheck.mypy",
    "pants.backend.python.lint.isort",
    "pants.backend.plugin_development",
    "internal_plugins"
]
pants_ignore.add = ["cdk.out/", "infrastructure/"]

[source]
root_patterns=[
    "src/pyfleet-etl",
    "src/pyfleet-vehicle-spec",
    "pants-plugins"]

[anonymous-telemetry]
enabled = false

[setup-py-generation]
generate_setup_default = true

[python-infer]
inits = true

[python]
interpreter_constraints = ["CPython==3.9.*"]
But I get this error when running any
pants
command
Copy code
Traceback (most recent call last):
  File "/Users/developer/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.wXPFFy/install/lib/python3.9/site-packages/pants/init/extension_loader.py", line 128, in load_backend
    module = importlib.import_module(backend_module)
  File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/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 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pants.backend.plugin_development'
14:14:52.43 [ERROR] Failed to load the pants.backend.plugin_development.register backend: ModuleNotFoundError("No module named 'pants.backend.plugin_development'")


Use --print-stacktrace for more error details and/or -ldebug for more logs. 
See <https://www.pantsbuild.org/v2.8/docs/troubleshooting> for common issues.
Consider reaching out for help: <https://www.pantsbuild.org/v2.8/docs/getting-help>
c

curved-television-6568

01/04/2022, 2:12 PM
Ah, that backend was introduced in pants 2.9.. try in 2.8, use
pants_requirement
instead, as described in the docs for your version of pants: https://www.pantsbuild.org/docs/plugins-overview#building-in-repo-plugins-with-pants (sorry for not checking which version of pants you were using first)
🙏 1
7 Views