I'm trying to implement scripts similar to what's ...
# general
b
I'm trying to implement scripts similar to what's in
build-support/bin
in
pantsbuild/pants
, but having trouble getting it to run. I have the directory in
[source].root_patterns
, and a
pex_binary
in
build-support/bin
but I feel I'm missing something because I get this error:
Copy code
λ › ./pants run build-support/bin/changelog.py                                                                                                                                      odl/ol-django nl/pants-t2
Traceback (most recent call last):
  File "/home/nathan/odl/ol-django/.pants.d/tmpstd0qzkb/changelog.pex/.bootstrap/pex/pex.py", line 489, in execute
  File "/home/nathan/odl/ol-django/.pants.d/tmpstd0qzkb/changelog.pex/.bootstrap/pex/pex.py", line 406, in _wrap_coverage
  File "/home/nathan/odl/ol-django/.pants.d/tmpstd0qzkb/changelog.pex/.bootstrap/pex/pex.py", line 437, in _wrap_profiling
  File "/home/nathan/odl/ol-django/.pants.d/tmpstd0qzkb/changelog.pex/.bootstrap/pex/pex.py", line 545, in _execute
  File "/home/nathan/odl/ol-django/.pants.d/tmpstd0qzkb/changelog.pex/.bootstrap/pex/pex.py", line 672, in execute_entry
  File "/home/nathan/odl/ol-django/.pants.d/tmpstd0qzkb/changelog.pex/.bootstrap/pex/pex.py", line 684, in execute_module
  File "/home/nathan/.pyenv/versions/3.6.10/lib/python3.6/runpy.py", line 201, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/home/nathan/.pyenv/versions/3.6.10/lib/python3.6/runpy.py", line 136, in _get_module_details
    raise error("No module named %s" % mod_name)
ImportError: No module named changelog
e
Does the corresponding BUILD file have a python_library target in addition to the pex_binary target(s)? It's unfortunately needed for now for pants internal book-keeping: https://github.com/pantsbuild/pants/blob/main/build-support/bin/BUILD#L6
b
it did not, that did the trick, thanks!
e
Great. If you look closely at the two methods for specifying a pex_binary entry_point described here: https://www.pantsbuild.org/docs/python-package-goal#approach-1-a-file-name https://www.pantsbuild.org/docs/python-package-goal#approach-2-explicit-entry_point You might miss the
python_library()
at the top of the BUILD file. As you found out - that's critical. It's also easy to miss because its not clear why you should need to have it. You might be able to save pain going forward (I still often forget to add a python_library) by using
./pants tailor
. More on that here: https://www.pantsbuild.org/docs/troubleshooting#import-errors-and-missing-dependencies
b
It makes sense in hindsight, I would've needed it anyway for it to discover sibling modules I'm importing