proud-appointment-36730
07/11/2022, 8:38 PMproud-appointment-36730
07/11/2022, 8:39 PMdef myorg_docker_image(**kwargs):
# If someone specifies a source and does not embed instructions into BUILD file, fail fast
if kwargs['source'] or not kwargs['instructions']:
raise ValueError("Cannot use Dockerfiles")
if not are_dependencies_encoded_in_instructions(kwargs['instructions']):
raise ValueError("Must encode dependencies of docker image into instructions kwarg")
docker_image(**kwargs)
witty-crayon-22786
07/11/2022, 8:41 PMbitter-ability-32190
07/11/2022, 8:42 PMwitty-crayon-22786
07/11/2022, 8:42 PMobject
which raises the relevant exception type… trying to find an examplewitty-crayon-22786
07/11/2022, 8:42 PMproud-appointment-36730
07/11/2022, 8:46 PMwitty-crayon-22786
07/11/2022, 8:48 PMproud-appointment-36730
07/11/2022, 8:50 PMenough-analyst-54434
07/11/2022, 8:50 PM--build-file-prelude-globs
with a file that just does `from builtins import *`work?witty-crayon-22786
07/11/2022, 8:50 PMBUILD
files. so as a workaround for https://github.com/pantsbuild/pants/issues/15420, you could define an object
for an exception typewitty-crayon-22786
07/11/2022, 8:51 PMimport
is bannedenough-analyst-54434
07/11/2022, 8:52 PMwitty-crayon-22786
07/11/2022, 8:53 PMproud-appointment-36730
07/11/2022, 8:57 PMfrom builtins import *
and it doesn't appear to work. Little confused by the example (first foray into customizing pants) but I'll see if I can poke at it for a bit and make something workwitty-crayon-22786
07/11/2022, 9:12 PMobjects
example make sense? it would involve creating a very tiny plugin, with a register.py
file. see https://www.pantsbuild.org/docs/plugins-overview#enabling-plugins-with-registerpy (in particular, the second tab in that code block), and defining a def build_file_aliases
function in it.enough-analyst-54434
07/11/2022, 9:13 PM$ cat expose-builtins
exec(f"from builtins {'IMPORT'.lower()} *")
$ cat macro-uses-builtins
def foo(name=None):
if not name:
raise Exception("A name is required.")
python_sources(name=name)
$ cat BUILD.example
foo(name="jake")
foo()
$ ./pants --build-file-prelude-globs='*-builtins' list :
15:12:53.20 [ERROR] 1 Exception encountered:
Engine traceback:
in select
in pants.backend.project_info.list_targets.list_targets
in pants.engine.internals.specs_rules.resolve_addresses_from_specs
in pants.engine.internals.specs_rules.resolve_addresses_from_raw_specs
in pants.engine.internals.specs_rules.addresses_from_raw_specs_without_file_owners
in pants.engine.internals.build_files.ensure_address_family ()
in pants.engine.internals.build_files.parse_address_family ()
Traceback (most recent call last):
File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/engine/internals/mapper.py", line 47, in parse
target_adaptors = parser.parse(filepath, build_file_content, extra_symbols, defaults)
File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/engine/internals/parser.py", line 167, in parse
exec(build_file_content, global_symbols)
File "<string>", line 2, in <module>
File "macro-uses-builtins", line 3, in foo
raise Exception("A name is required.")
Exception: A name is required.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/engine/internals/selectors.py", line 705, in native_engine_generator_send
res = func.send(arg)
File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/engine/internals/build_files.py", line 181, in parse_address_family
for fc in digest_contents
File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/engine/internals/build_files.py", line 181, in <listcomp>
for fc in digest_contents
File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/engine/internals/mapper.py", line 49, in parse
raise MappingError(f"Failed to parse ./{filepath}:\n{e}")
pants.base.exceptions.MappingError: Failed to parse ./BUILD.example:
A name is required.
proud-appointment-36730
07/11/2022, 9:15 PMenough-analyst-54434
07/11/2022, 9:16 PMexpose-builtins
thing.enough-analyst-54434
07/11/2022, 9:17 PMenough-analyst-54434
07/11/2022, 9:17 PMenough-analyst-54434
07/11/2022, 9:17 PMproud-appointment-36730
07/11/2022, 9:23 PMproud-appointment-36730
07/11/2022, 9:55 PMwitty-crayon-22786
07/11/2022, 10:24 PM@rule
. we definitely need to clean up the boundary between macros
and @rules
before stabilizing the plugin API.witty-crayon-22786
07/11/2022, 10:25 PMproud-appointment-36730
07/11/2022, 10:30 PMrule
?witty-crayon-22786
07/11/2022, 10:31 PM@rules
are invalidated. and the synchronous API of macros doesn’t have a way to declare its dependencies (…and thus isn’t allowed to have dependencies currently)proud-appointment-36730
07/11/2022, 10:32 PMwitty-crayon-22786
07/11/2022, 10:42 PM