ambitious-actor-36781
11/15/2022, 3:45 AMeverything_else...
/|\
|
python_sources()
/|\ /|\
| |
| hash_generator()
| /|\
| |
package_target()
(a dependency of) my python_sources()
provides a set_hash(hash)
and get_hash()
function.
my hash_generator()
does a codgen, and outputs some code that calls set_hash(12345)
then the package_target()
imports both at runtime and magically gets its hash set.
This then means the tests don't depend on the hash_generator()
target to be included, and they can just call set_hash()
if they need to.
But it doesn't feel right, and I'm considering maybe just having get_hash(): return None
return, and then the hash_generator
can overwrite the file with get_hash(): return 12345
gorgeous-winter-99296
11/19/2022, 8:06 PM.pyt
template file, and then you've got a backend that converts that to a python_source(). That means you're not modifying - it's the same flow as any other code-generation target. And in my experience so far; being same-y with something that exists means you can do less work and get more.ambitious-actor-36781
11/19/2022, 8:09 PMgorgeous-winter-99296
11/19/2022, 8:09 PMfoo.bar
, or generate it fully from code.gorgeous-winter-99296
11/19/2022, 8:14 PMfoocorp_hash_generator
that uses a target like hash_generator(input="file.pyt", output="file.py")
which implements the flow from here: https://www.pantsbuild.org/docs/plugins-codegen 🙂ambitious-actor-36781
11/19/2022, 8:15 PMambitious-actor-36781
11/19/2022, 8:18 PMambitious-actor-36781
11/19/2022, 8:21 PMgorgeous-winter-99296
11/19/2022, 8:23 PMambitious-actor-36781
11/19/2022, 8:24 PMgorgeous-winter-99296
11/19/2022, 8:26 PM