ambitious-actor-36781
05/12/2022, 11:23 PMinspect.
python module
(mostly inspect, to get attributes, then inspect.getsource() to stick into a jinja template), and want to tie it into Pants.
should I build it as a standalone pex and then have pants call that?
or should I just run it straight from within my pants plugin.hundreds-father-404
05/12/2022, 11:27 PMmy.codegen.foo
translates to src/codegen/custom_template.json
for example (whatever scheme you want)
With that set up, your users simply need to depend on the file. Then Pants will pick up the dependency and automate doing codegen for you: making sure you always use the most up-to-dateambitious-actor-36781
05/12/2022, 11:28 PMhundreds-father-404
05/12/2022, 11:34 PM[GLOBAL].pythonpath
which causes Pantsd to invalidate anytime a file is changed. Bad for performance
But I don't think I'm following that question: you can write a plugin that creates a new target type like transformed_python()
, and then add codegen for it. The rest of your repo can now use that just like any other targetambitious-actor-36781
05/13/2022, 1:18 AMhundreds-father-404
05/13/2022, 1:23 AMpantsbuild/pants
has no idea that your repository my_repo/
exists when we write the code. We're writing generic targets/rules to operate on your code
Does that make sense?ambitious-actor-36781
05/13/2022, 1:27 AMambitious-actor-36781
05/13/2022, 1:41 AMinspect
which I think this means that our codegen needs to know about the entire project.hundreds-father-404
05/13/2022, 1:45 AMBut we're using inspect which I think this means that our codegen needs to know about the entire project.I'm curious how the code is working? What's the
inspect
doing?
Note, for example, that Python dep inference from pantsbuild/pants knows about your whole repo to create it's module_mapping. But, we only need file names. We don't have to parse individual files. Which means it should not be invalidated infrequently
--
To clarify, manual generation via a Pex is one valid approach. You run the risk of it becoming stale, like forgetting to rerun generation.
But depending on how niche this is + your engineering resources, manual generation can definitely be a valid tradeoffambitious-actor-36781
05/13/2022, 1:51 AMinspect
and then enumerate through the functions, and then use inspect.getsource()
to flatten the class (no super()
supported.
And then spit out some functions that call the class w/ the global scope passed in.ambitious-actor-36781
05/13/2022, 1:53 AMambitious-actor-36781
05/13/2022, 2:00 AM