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

ancient-vegetable-10556

01/09/2023, 9:07 PM
And now: End-to end codegen, generated by an ad-hoc JVM tool, imported by a Python source, which can be packaged in a Python distribution should you want to: https://github.com/pantsbuild/example-python/compare/main...chrisjrn:pantsbuild-example-python:chrisjrn/codegen_with_antlr?expand=1#diff-1[…]4c1ff2f I think we might be done here. 👀 (see: https://github.com/pantsbuild/pants/issues/17616)
p

proud-dentist-22844

01/09/2023, 11:46 PM
Wow. Now if there was a way to hook a
run_in_sandbox
target up to the
fmt
or
fix
goals, then I would be able to delete 3 plugins I wrote. I think I mentioned this before, and
lint
was feasible but `fmt`/`fix` was not…
a

ancient-vegetable-10556

01/10/2023, 4:08 PM
You’re right, `fmt`/`fix` aren’t feasible right now,
lint
would be feasible but weird to use. I have a back-of-the-envelope design for making all three possible, but I don’t think that’s in scope for 2.16
@proud-dentist-22844 If you want to write it: • A
generic-tool
subsystem, which accepts an option that points at the `esc`/`eris` target that does the linting • A new target called
matcher(filenames=["..."])
, filenames is a list of globs that match files that can be consumed by a given `esc`/`eris`. There would be a goal that can match source files from the targets specified at the command line against the
filenames
field, and treat those targets as transitive dependencies (which would get pulled into the `esc`’s execution sandbox) • your `esc`/`eris` targets depend on the
matcher
as
execution_dependencies
You’d then call
./pants lint --generic-tool-linter=path/to:linter_esc …
(the alternative to the
matcher
target here would be making a synthetic target called
command_line_args
that could be specified as a dependency)
p

proud-dentist-22844

01/10/2023, 4:34 PM
How would that work with
./pants lint ::
? I don't want to use
run
to avoid teaching people all the things they need to regularly do.
a

ancient-vegetable-10556

01/10/2023, 4:38 PM
So
./pants lint
would invoke the target specified by
--generic-tool-linter
(by way of
HydrateSources(enable_codegen=True)
). That target would have the
matcher
as a dependency. That goal would resolve the targets provided by the command line specs, and either synthesise those targets as its own dependencies (ideal), or (less ideal) use codegen to return a
GeneratedSources
containing all of the matched source files.
So there’s two new parts: • Rules that plug into the existing
lint
/`fmt`/`fix` subsystems to hydrate sources from an `esc`/`eris` • A target & rule to yoink sources from the specs provided at the command line, so the target can be specified as a dependency to `esc`/`eris`.
(I think you could theoretically have multiple targets specified by
--generic-tool-linter
too. There’d be some ambiguity arising in
fix
and
fmt
when multiple targets match the same files, but that’s not too hard to overcome, I don’t think)