https://pantsbuild.org/ logo
#development
Title
# development
h

hundreds-father-404

05/28/2020, 8:35 PM
The only issue so far with
object
for
contrib_plugin
is that we need access to the target’s relative path (spec path). Does this mean I need to use
context_aware_object_factory
?
w

witty-crayon-22786

05/28/2020, 8:41 PM
so… that might call for a builtin.
h

hundreds-father-404

05/28/2020, 8:42 PM
Meaning?
w

witty-crayon-22786

05/28/2020, 8:42 PM
oh. you said
object
.
hm. yea, not sure.
h

hundreds-father-404

05/28/2020, 8:43 PM
Yeah, I have an
object
and everything works great, minus needing the spec path. I think CAFO handles this? A CAFO is just a fancy way to create something like an
object
, right?
w

witty-crayon-22786

05/28/2020, 8:43 PM
the difference is that the context it receives allows it to declare targets
(…and also contains the relative path)
adding additional built in functions (or
objects
) to macro/BUILD file evaluation might satisfy these usecases.
h

hundreds-father-404

05/28/2020, 9:18 PM
Oh. Wait. We can just use
Path.cwd()
in this
contrib_setup_py
object!
w

witty-crayon-22786

05/28/2020, 9:18 PM
i don’t think so… would get you the buildroot, afaik
h

hundreds-father-404

05/28/2020, 9:19 PM
Oh, hm. Sad
Can CAOFs not take additional arguments? This is my function:
Copy code
def contrib_setup_py(
    parse_context,
    name: str,
    description: str,
    build_file_aliases: bool = False,
    global_subsystems: bool = False,
    register_goals: bool = False,
    rules: bool = False,
    target_types: bool = False,
    additional_classifiers: Optional[List[str]] = None,
    **kwargs,
) -> PythonArtifact:
w

witty-crayon-22786

05/28/2020, 9:36 PM
the parse context is passed to the outer thing, which returns a closure containing the inner thing.
sec. lemme find an example.
❤️ 1
so, a more modern example is actually this one:
src/python/pants/backend/python/python_requirements.py
which is the equivalent of:
Copy code
def outer(parse_context):
  def inner(requirements_relpath="requirements.txt"):
    # do things with the parse_context and my args
  return inner
the first call takes one arg and creates a callable
h

hundreds-father-404

05/28/2020, 9:40 PM
And the inner can still have any arbitrary args? I’m hoping in a BUILD file that you can say
contrib_setup_py(arg1=..., arg2=...)
w

witty-crayon-22786

05/28/2020, 9:40 PM
yes
the inner callable (or
__call__
in the first case) is effectively directly exposed in the BUILD file.
❤️ 1
h

hundreds-father-404

05/28/2020, 9:41 PM
Okay, will try. Thank you!
It worked! Thanks for the help Stu 😄