Hi team, I would like to ask your comments and adv...
# general
g
Hi team, I would like to ask your comments and advices on a potential Pants use case. In our CI/CD pipeline, we build our docker image using OpenShift (e.g. oc build) and running some system level test against the image. We are wondering if we can use Pants to avoid unnecessary image build and system test. For example, if the changes are only in the scope of READMEs or some unit tests, we dont necessary need to spend any resource on building new images, running system test or even deploying the new image. I wonder if Pants can be useful here, if yes, how? One approach (not sure if it is working) in my mind is to have something like
pants run project/build_and_system_test.py
which we can put the build and system test logic in the script and also (manually) specify the dependencies in the corresponding BUILD file? Not sure if pants run has any cache? Probably not. Will it work?
g
Yes to all of those! Pants by default will cache a lot of tests and lint runs; and you can further customize this by filtering what gets run based on your Git history or which type of files it affected. I don't think you need any special logic to start with unless you absolutely want to:
pants test ::
will rerun tests that have changed since
test
was last ran, for example.
pants package
and
pants publish
do require filtering if you want to do no work, but the build step themselves will be cached as long as they are reproducible -- the side-effects are not. Dependencies are auto-inferred in a lot of situations as well; for "in-repo" dependencies. For external dependencies, they are inferred once you've told Pants about them using
python_requirements
- see Third-party dependencies for more info.
g
@gorgeous-winter-99296 thanks for comment. I guess I may not explain my problem clearly. We have been use Pants in our CI for code linting/mypy/unittest/etc. We are exploring more use cases of Pants. One of that is the following. Suppose I have a command (oc build, or whatever shell command) I would like to run during the CI only when any (transitive) dependencies of a file go modified during the CI. I am wondering if Pants can be utilized in this case?
h
You can probably use the
--changed
flags to get the effect you want: https://www.pantsbuild.org/docs/reference-changed