astonishing-london-2419
09/15/2021, 7:25 PMwitty-crayon-22786
09/15/2021, 7:40 PMgoal
that does this, yeawitty-crayon-22786
09/15/2021, 7:42 PMbuild-dags
a bunch of timeswitty-crayon-22786
09/15/2021, 7:44 PM@rules
that invoke build-dags
, and then recurse on the discovered dependencieswitty-crayon-22786
09/15/2021, 7:46 PMawait Get(Targets, Addresses(stuff_discovered_by_running_the_build_dags_tool))
witty-crayon-22786
09/15/2021, 7:48 PM./pants package
: that might also be feasible…? assuming you’ve built the above code to invoke that tool, you can have another @rule
consume it, and install it as a generator of files
targets: https://www.pantsbuild.org/docs/plugins-codegenwitty-crayon-22786
09/15/2021, 7:49 PMairflow_library_dag
next to your pex_binary
which would generate a files
targetwitty-crayon-22786
09/15/2021, 7:52 PMairflow_binary
) which would always declare both underlying targets at once, and with a dependency between the binary and the dagastonishing-london-2419
09/16/2021, 3:27 AMastonishing-london-2419
09/16/2021, 3:29 AMwitty-crayon-22786
09/16/2021, 4:44 PMwitty-crayon-22786
09/16/2021, 4:44 PMairflow_library_dag
type depend on python code…?astonishing-london-2419
09/16/2021, 7:30 PMastonishing-london-2419
09/16/2021, 7:30 PMastonishing-london-2419
10/11/2021, 8:11 PMGenerateSourcesRequest
goes from PythonSources
to FilesGeneratorTarget
(if I understood correctly). However, in the rule
I need to import those python sources to run the correct function, get a dictionary and write it to disk. Does this even make sense? I could create a pex on the fly that calls the desired function, but I am not sure if this makes sense.witty-crayon-22786
10/12/2021, 4:02 PMmyprobably fromgoes fromGenerateSourcesRequest
toPythonSources
(if I understood correctly)FilesGeneratorTarget
PythonSources
to FilesSources
witty-crayon-22786
10/12/2021, 4:05 PMI need to import those python sources to run the correct function, get a dictionary and write it to disk. Does this even make sense?that’s correct: to get the python sources of your targets, you’d do something like:
sources = Get(
SourceFiles,
SourceFilesRequest(
sources_fields=[t.get(Sources) for t in targets],
for_sources_types=(PythonSources,),
),
)
witty-crayon-22786
10/12/2021, 4:05 PMProcess
, you’d do something like https://www.pantsbuild.org/docs/rules-api-process#processhundreds-father-404
10/12/2021, 4:06 PMwitty-crayon-22786
10/12/2021, 4:07 PM@rule
using https://www.pantsbuild.org/docs/rules-api-file-system#digestcontentsastonishing-london-2419
10/12/2021, 7:21 PMthen, to run aCan I avoid running a process? It’s just importing some python code and executing a function…, you’d do something like https://www.pantsbuild.org/docs/rules-api-process#processProcess
hundreds-father-404
10/12/2021, 7:30 PMastonishing-london-2419
10/12/2021, 7:38 PMastonishing-london-2419
10/12/2021, 7:38 PMhundreds-father-404
10/12/2021, 7:39 PMProcess
. You'll miss out on on-disk caching and only have in-memory memoization via Pantsd (daemon), but if it's a fast function, probably fine. And you avoid overhead of launching processesastonishing-london-2419
10/12/2021, 7:44 PMpants.engine
I don’t see how to transform these sources into something importable. Should I just use importlib and the file path?hundreds-father-404
10/12/2021, 7:50 PMastonishing-london-2419
10/12/2021, 7:51 PMhundreds-father-404
10/12/2021, 7:57 PMDigestContents
to load them in-memory: https://www.pantsbuild.org/docs/rules-api-file-system#digestcontents. It's the engine safe version of with open(): f.read()
, meaning it has things like file-watching to know when to invalidate all your rules because of changesastonishing-london-2419
10/12/2021, 7:57 PM