alert-boots-15052
04/23/2020, 9:14 AMhundreds-father-404
04/23/2020, 2:45 PMalert-boots-15052
04/24/2020, 2:08 AMgenrule
(is it prep_command
?), I guess I can write up a plugin for this pretty easily thoughhundreds-father-404
04/24/2020, 2:08 AMalert-boots-15052
04/24/2020, 2:09 AMalert-boots-15052
04/24/2020, 2:10 AMhundreds-father-404
04/24/2020, 2:11 AMalert-boots-15052
04/24/2020, 2:12 AMalert-boots-15052
04/24/2020, 2:16 AMhappy-kitchen-89482
04/24/2020, 2:17 AMalert-boots-15052
04/24/2020, 2:18 AMgrunt build-js-files
. I would love to just specify a Pants ... target? That just calls that command (but I specify the files that are needed to run that)alert-boots-15052
04/24/2020, 2:19 AMhundreds-father-404
04/24/2020, 2:20 AM./pants grunt-build '**/*.js'
, for example
You specifically need to run grunt build-js-files
, right? Any other commands?alert-boots-15052
04/24/2020, 2:20 AMpy_test
target so that ./pants test
reruns that build if I have input changes?alert-boots-15052
04/24/2020, 2:21 AMmanage.py compilemessages
(for translation files), I could write up wrapper files for this probably?hundreds-father-404
04/24/2020, 2:22 AMgrunt build-js-files
or something similar on some targets. An explicit focus of the V2 version of Pants is to make it highly extensible and easy to add new functionality.
We’ll be adding docs on how to write plugins next month, and I’d be happy to pair on it too if you think the plugin would do the job.hundreds-father-404
04/24/2020, 2:23 AM./pants --changed-since=HEAD test
, which will find all the changed files sine that commit and only run thosealert-boots-15052
04/24/2020, 2:25 AMpython_tests
could only be python_library
-like targetshundreds-father-404
04/24/2020, 2:27 AMfiles()
or resources()
target. For example, you could do this:
files(
name="static_assets",
sources=["*.css", "*.html", "*.js"]
)
python_library(
name="app"
dependencies=[
":static_assets",
]
)
alert-boots-15052
04/24/2020, 2:28 AMgrunt build-js-files
takes src/***/**.js
and generates dist/main.js
and dist/assets/*.png
• manage.py compilemessages
generates some <http://messages.mo|messages.mo>
file for translations in the app
• py.test app/tests
runs tests (including selenium tests, which requires the above built files to be present)alert-boots-15052
04/24/2020, 2:28 AMalert-boots-15052
04/24/2020, 2:29 AMhundreds-father-404
04/24/2020, 2:32 AMdeclaration for stuff that is generated from some other commandGood timing with this question! We’re actually actively working on support for codegen the next two weeks, meaning for example that you can convert Thrift files into Python code and depend on that in your
python_library
targets, for example.
We could possibly leverage that, but I think we might be able to circumvent it for something simpler.
Generally, a V2 goal can indeed create files in your build root. You could create a grunt-build
goal that will write files to any location in the build root, like dist/
.
Question, do you check in dist/
to version control?alert-boots-15052
04/24/2020, 2:32 AMhundreds-father-404
04/24/2020, 2:32 AMsorry for spamming on this, it’s very nice to be able to get help on this kind of stuff thoughNo need to apologize! Happy to help 🙂 our goal is to solve problems exactly like you’re encountering!
hundreds-father-404
04/24/2020, 2:37 AMno, we don’t commit itOkay, then codegen would likely be more idiomatic, but in the meantime, I think we could still make it work. The semi-unidiomatic thing is that you will want to check in your BUILD file to VCS, so you will want your BUILD file defined one level above
dist
, like at the root level. Then, you could use a sources
glob, like this:
files(
name="static_assets",
sources=["dist/main.js", "dist/assets/*.png"],
)
Your targets can then depend on //:static_assets
, where the //
clarifies this target is at the build root.alert-boots-15052
04/24/2020, 2:45 AMhundreds-father-404
04/24/2020, 2:47 AMalert-boots-15052
04/24/2020, 2:55 AMalert-boots-15052
04/24/2020, 2:55 AMhundreds-father-404
04/24/2020, 2:59 AMAnd maybe an example file that’s already in the project? I’m pretty good at back-solving from an existing implementationI’ll look for some good examples right now. Generally I’m the same with being good at back-solving, although warning that there are a fair amount of new concepts with writing V2 “rules” that might be confusing without a little bit of explanation. All the concepts are sound and inspired by functional programming, and once you know the basics it’s pretty simple to throw together new functionality, but it might be a little confusing without some orientation (whether that be the upcoming docs or someone talking it through). Of course, we’re happy to answer any questions along the way
hundreds-father-404
04/24/2020, 3:12 AMsrc/python/pants/core/project_info/cloc.py
is a good example of a stand-alone goal that does something similar to what you’ll want for the Grunt goal.
Ignore lines 26-46.
First step to your new goal: create a subclass of GoalSubsystem
and Goal
, very similar to this file. GoalSubsystem
is the public api, like any options and the name of the goal.
Then, the @goal_rule
is where the interesting logic happens. High level flow of what’s going on:
1) We’re asking for a couple things to be given to us by the V2 engine. These will be given via dependency injection; we don’t care how Pants gets us these things.
2) One of the things we’re asking for in the function signature is SourcesSnapshots
. This is a way to ask for source files, where we don’t care at all about the metadata in targets. All we care about is the raw source files. If a user runs ./pants cloc :example
, we get all the source files belonging to the target example
. If they say ./pants cloc example.js
, we’ll get that JS file.
3) We set up a Process
, which is very similar to Python’s subprocess.Popen
but is a way the Pants engine understands it and does things like safe caching. Note that we run /usr/bin/perl
. For an initial prototype, it will be easiest if you can use an absolute path like /usr/bin/grunt
. We can help you to generify this once it works. Also, note the input_files
to populate the chroot with the files we need, and output_files
to “capture” the result.
4) await Get[ProcessResult](Process, req)
actually runs the process
--
The other relevant file is src/python/pants/core/goals/binary.py
, lines 69-71. It shows how to materialize files from a tmpdir into the actual build root so that you write to dist/
alert-boots-15052
04/24/2020, 5:26 AMhundreds-father-404
04/24/2020, 5:35 AM