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

fresh-continent-76371

04/12/2023, 6:58 AM
I am currently attempting to populate the
python_artifact(...)
with a
version
value from a file. I am following the guide here - https://www.pantsbuild.org/docs/plugins-setup-py I am hitting a very opaque error, - but it is not obvious which area of the code it is not happy with. (it would seem something is not initialising properly)
Copy code
❯ pants  --print-stacktrace
16:50:33.07 [ERROR] 'NoneType' object has no attribute '__name__'
Traceback (most recent call last):
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/bin/daemon_pants_runner.py", line 130, in single_daemonized_run
    scheduler, options_initializer = self._core.prepare(options_bootstrapper, complete_env)
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/pantsd/pants_daemon_core.py", line 130, in prepare
    build_config = self._options_initializer.build_config(options_bootstrapper, env)
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/init/options_initializer.py", line 111, in build_config
    return _initialize_build_configuration(self._plugin_resolver, options_bootstrapper, env)
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/init/options_initializer.py", line 57, in _initialize_build_configuration
    return load_car_switch_rail_and_plugins(
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/init/extension_loader.py", line 46, in load_car_switch_rail_and_plugins
    load_build_configuration_from_source(bc_builder, car_switch_rail)
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/init/extension_loader.py", line 128, in load_build_configuration_from_source
    load_backend(build_configuration, backend_package)
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/init/extension_loader.py", line 143, in load_backend
    module = importlib.import_module(backend_module)
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-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/user8/projects/svcs.com/acme-eng/se/core/tools/python/pants-plugins/acme/publishing/register.py", line 4, in <module>
    from acme.publishing import versioned
  File "/home/user8/projects/svcs.com/acme-eng/se/core/tools/python/pants-plugins/acme/publishing/versioned.py", line 15, in <module>
    async def shunup_kwargs_plugin(request: CustomshunupKwargsRequest) -> shunupKwargs:
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/engine/rules.py", line 337, in rule
    return inner_rule(*args, **kwargs, rule_type=RuleType.rule, cacheable=True)
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/engine/rules.py", line 327, in inner_rule
    return rule_decorator(*args, **kwargs)
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/engine/rules.py", line 277, in rule_decorator
    return _make_rule(
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/engine/rules.py", line 103, in wrapper
    awaitables = FrozenOrderedshun(collect_awaitables(func))
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/util/memo.py", line 123, in memoize
    result = func(*args, **kwargs)
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/engine/internals/rule_visitor.py", line 134, in collect_awaitables
    return _AwaitableCollector(func).awaitables
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/engine/internals/rule_visitor.py", line 43, in __init__
    self.visit(ast.parse(source))
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/ast.py", line 415, in generic_visit
    self.visit(item)
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/ast.py", line 415, in generic_visit
    self.visit(item)
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/ast.py", line 417, in generic_visit
    self.visit(value)
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/ast.py", line 417, in generic_visit
    self.visit(value)
  File "/home/user8/.cache/nce/cdc3a4cfddcd63b6cebdd75b14970e02d8ef0ac5be4d350e57ab5df56c19e85e/cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/engine/internals/rule_visitor.py", line 123, in visit_Call
    self.awaitables.append(self._get_awaitable(call_node))
  File "/home/user8/.cache/nce/6621291ed4120fa45607b367abf7786ce496f389f27240712a63c31f1c438c21/bindings/venvs/2.15.0/lib/python3.9/site-packages/pants/engine/internals/rule_visitor.py", line 85, in _get_awaitable
    is_effect = func.__name__ == "Effect"
AttributeError: 'NoneType' object has no attribute '__name__'

Use -ldebug for more logs. 
See <https://www.pantsbuild.org/v2.15/docs/troubleshooting> for common issues.
Consider reaching out for help: <https://www.pantsbuild.org/v2.15/docs/getting-help>
the file
versioned.py
is
Copy code
# acme/publishing/versioned.py
# ref: <https://www.pantsbuild.org/docs/plugins-setup-py>
from pants.backend.python.goals.setup_py import SetupKwargs, SetupKwargsRequest
from pants.engine.rules import collect_rules, rule
from pants.engine.target import Target
from pants.engine.unions import UnionRule


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


@rule
async def setup_kwargs_plugin(request: CustomSetupKwargsRequest) -> SetupKwargs:
    digest_contents = await Get(
        DigestContents,
        PathGlobs(
            ["VERSION"],
            description_of_origin="`python_artifact()` plugin",
            glob_match_error_behavior=GlobMatchErrorBehavior.error,
        ),
    )
    version = digest_contents[0].content.decode()
    return SetupKwargs(
        {**request.explicit_kwargs, "version": version},
        address=request.target.address
    )

def rules():
    return [
        *collect_rules(),
        UnionRule(SetupKwargsRequest, CustomSetupKwargsRequest),
    ]
the
acme/publishing/register.py
is
Copy code
from typing import Iterable

from pants.engine.target import Target
from acme.publishing import versioned


def rules():
    return [*versioned.rules()]
👀 1
1
c

curved-television-6568

04/12/2023, 8:47 AM
looking into this. first I just want to confirm that this is a redaction “typo” from the error log?
Copy code
async def shunup_kwargs_plugin(request: CustomshunupKwargsRequest) -> shunupKwargs:
also, I’m guessing this is on Pants 2.15.0, correct?
ok, I’m reproducing.. digging in
Ah, there’s just a few missing imports. The error feedback could be greatly improved here. Add these:
Copy code
from pants.engine.rules import Get
from pants.engine.fs import DigestContents, PathGlobs
and the docs updated to actually import
Get
too..
f

fresh-continent-76371

04/12/2023, 10:51 AM
Ha yes , a redaction typo :-)
Thanks I’ll add that import in a moment ;
That did resolve the issue @curved-television-6568 - thank you, there was an extra import required for the
GlobMatchErrorBehavior
my final imports were
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
👍 1
c

curved-television-6568

04/12/2023, 12:02 PM
OK, yea I didn’t look further than that it loaded properly
f

fresh-continent-76371

04/12/2023, 12:05 PM
I now face a slightly different issue. i have the
BUILD
setup as such >>
Copy code
vcs_version(
    name = "tagged_version",
    generate_to = "VERSION",
    template = "{version}",
)

resource(
    name = "pyproject",
    source = "pyproject.toml",
)

python_distribution(
    name = "myproject",
    dependencies = [
        ":pyproject",
        "//myproject:myproject_sources",
    ],
    generate_setup = True,
    provides = python_artifact(
        name = "myproject",
        dependencies = [
            ":tagged_version",
        ],
    ),
    wheel_config_settings = {"--global-option": [
        "--python-tag",
        "py39.py310.py311",
    ]},
)
with a "static"
/VERSION
file it builds but the python_artitfact( ) is attempting to resolve the "VERSION" file before the
:tagged_version
dependency generates one .
so for example ..
Copy code
❯ ls VERSION   
ls: cannot access 'VERSION': No such file or directory

~/myproj-repo [$✘»!+?] via 🐍 v3.10.6 (.venv-core) 
❯ pants --keep-sandboxes=always package ::
22:06:53.86 [ERROR] 1 Exception encountered:

Engine traceback:
  in `package` goal
  in Snapshotting: VERSION

Exception: Unmatched glob from `python_artifact()` plugin: "VERSION"

Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to <https://www.pantsbuild.org/v2.15/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>.
but if i just manual add the file ...
Copy code
❯ echo 99.88.77 > VERSION   

~/myproj-repo on  115-ci-myproject-library-publishing [$✘»!+?] via 🐍 v3.10.6 (.venv-core) 
❯ pants --keep-sandboxes=always package ::
22:08:42.09 [INFO] Preserving local process execution dir /tmp/pants-sandbox-uMXjX3 for Run setuptools.build_meta for //:myproject
22:08:43.33 [INFO] Wrote dist/myproject-99.88.77-py39.py310.py311-none-any.whl
22:08:43.33 [INFO] Wrote dist/myproject-99.88.77.tar.gz
best I can see, the lifecycle is not "running" tagged_version before the
python_artifact(...)
runs, or the "custom" plugin needs some change to wait for "dependencies" to run before trying to
Get(... VERSION)
looks like I have naively assumed that a dependency in the
python_artifact(...)
would do the right thing.
hmm, okay - i can see that python_artifact is some type of macro - which makes it "not normal" 🙂 now I need to find out how to make this macro depend upon a "dependencies [ ]" list before it runs /
2 Views