cold-soccer-63228
05/02/2022, 8:56 PMBUILD
files via Git?
I noticed that if I have */**/BUILD
in the .gitignore
, then Pants commands will complain that a BUILD
file doesn't exist, even though it does exist in the local filesystem.hundreds-father-404
05/02/2022, 8:58 PMhigh-yak-85899
05/02/2022, 8:58 PMhundreds-father-404
05/02/2022, 8:59 PMcold-soccer-63228
05/02/2022, 8:59 PMBUILD
files using _package_config.py
files, where engineers can define other things as well. We want those to be the source of truth.
BUILD
files are to be generated locally (since it doesn't take long), and we want one single source of truthcold-soccer-63228
05/02/2022, 9:09 PMBUILD
files, and add headers telling people to not touch them or edit them manuallyhundreds-father-404
05/02/2022, 9:10 PMcold-soccer-63228
05/02/2022, 9:10 PMwitty-crayon-22786
05/02/2022, 9:11 PMWe want to generate custom logic in ourif this is meant to be a long term strategy, you might also be able to define a target generator to do this automatically.files usingBUILD
files, where engineers can define other things as well. We want those to be the source of truth._package_config.py
hundreds-father-404
05/02/2022, 9:11 PM[tailor].build_file_header
hundreds-father-404
05/02/2022, 9:11 PMyou might also be able to define a target generator to do this automatically
tailor
is also extensiblecold-soccer-63228
05/02/2022, 9:12 PMif this is meant to be a long term strategy, you might also be able to define a target generator to do this automatically.
There are currently no examples of anyone extendingis also extensibletailor
tailor
at the moment, right? We would ideally have a custom generator that does all of the basic stuff and some additional things we want to dowitty-crayon-22786
05/02/2022, 9:13 PMtailor
in https://github.com/pantsbuild/pants/ can be used as examples for extension in your own repowitty-crayon-22786
05/02/2022, 9:14 PMwitty-crayon-22786
05/02/2022, 9:15 PMtailor
can only create a target type which already exists: if you want to create a new target type, and then declare those with tailor
, you’d do that using https://www.pantsbuild.org/docs/target-apicold-soccer-63228
05/02/2022, 9:18 PM./pants tailor
, for all Python files, correct?
What would make the most sense if I wanted to extend this? For each BUILD
file generated, I would like to also look at its sibling _package_config.py
file in the same directory, and generate dependencies conditional on that _package_config.py
file.hundreds-father-404
05/02/2022, 9:22 PMcold-soccer-63228
05/02/2022, 9:22 PMBUILD
files that are generatedhundreds-father-404
05/02/2022, 9:23 PM_package_config.py
, then rerun your <insert mechanism to regenerate the BUILD file>, it might change existing content, right? If so, tailor
won't be the right fithundreds-father-404
05/02/2022, 9:23 PMmy_org_package(
some_data_that_will_be_transformed=["a", "b"]
)
witty-crayon-22786
05/02/2022, 9:24 PMgenerate dependencies conditional on thatthis sounds like a dependency inference plugin then maybe. that would allow you to add dependencies automatically to afile._package_config.py
python_sources
target in the same directoryhundreds-father-404
05/02/2022, 9:24 PMcold-soccer-63228
05/02/2022, 9:25 PMthis sounds like a dependency inference plugin then maybe. that would allow you to add dependencies automatically to aYes, that's exactly what we want to do!target in the same directorypython_sources
cold-soccer-63228
05/02/2022, 9:25 PMTaking a step back, what is your motivation here with generating the BUILD flies?We want to generate
BUILD
files so that we can construct a dependency tree and run tests only for code that has changed in the current branch or most recent commit, to reduce the number of tests that need to run on CI/CDhundreds-father-404
05/02/2022, 9:28 PMso that we can construct a dependency tree and run tests only for code that has changed in the current branch or most recent commit, to reduce the number of tests that need to run on CI/CDThat is the crux of what Pants is designed for. For example: https://www.pantsbuild.org/docs/using-pants-in-ci#approach-1-only-run-over-changed-files Are you envisioning using Pants for that project introspection, or you are going to create the dependency graph yourself?
cold-soccer-63228
05/02/2022, 9:33 PMhundreds-father-404
05/02/2022, 9:36 PM_package_config.py
would be adding a new layer of indirection. For example, your teammates will have a harder time following along with the Pants docs when they have questions like "How do I change the timeout of a test?"cold-soccer-63228
05/02/2022, 10:32 PM_package_config.py
everywhere in our code already to specify things like owners, code reviews, etc.
We specify some other things in here like dependencies for asynchronous code. We define these in Python because we import them in our codebase in middleware implementation. Ideally, we would like to add some additional logic, perhaps in a dependency inference plugin that would allow us to add dependencies automatically to a python_sources
target in the same directory.
Is something like this possible, and are there examples?hundreds-father-404
05/02/2022, 10:36 PM__init__.py
files: https://github.com/pantsbuild/pants/blob/03401d7ab539c341024cb549134cbf146f9be4c4/src/python/pants/backend/python/dependency_inference/rules.py#L348
• our python import parser https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/dependency_inference/parse_python_dependencies.pycold-soccer-63228
05/02/2022, 10:37 PMhundreds-father-404
05/02/2022, 10:37 PM_package_config.py
? I'm curious how you're definining the dependencies now: might help us to give you more specific guidancecold-soccer-63228
05/02/2022, 10:37 PMhundreds-father-404
05/02/2022, 10:38 PMI'll take a read—I think this may accomplish exactly what I'm looking forCool! It does sound like this is the idiomatic way to achieve this We are definitely happy to help if you have questions along the way. Plugins can have a bit of a learning curve - we're wanting to improve our examples and docs
cold-soccer-63228
05/02/2022, 10:39 PM_pacakge_config.py
.
from front_porch.modules.common.modules.types import (
MessagingConfig,
OwnerValues,
PackageConfig,
PubSubConfig,
SubscriptionConfig,
)
package_config = PackageConfig(
owner=OwnerValues.PLATFORM,
package_name="some_package_name",
messaging=MessagingConfig(
pubsub=PubSubConfig(
subscriptions=[
SubscriptionConfig(
subscription_id="SOME_PUBSUB_SUBSCRIPTION_ID",
filepath="path/to/some_handler.py",
)
]
)
),
)
cold-soccer-63228
05/02/2022, 10:40 PMBUILD
file, we would like to add the filepath
specified in the messaging dependencies as dependencies in the BUILD
filehundreds-father-404
05/02/2022, 10:44 PMtokenize
or ast
to extract the filepath="path/to/some_handler.py",
line
Then add a dependency on Address(os.path.dir(path_to_file), relative_file_path=os.path.basename(path_to_file))
, which translates to the address path/to/some_handler.py
.
This is a little fragile and wonky that it assumes your python_sources
is leaving off the name=
field, which is the default behavior with `tailor`; otherwise the address would be path/to/some_handler.py:tgt_name
. That seems fine to me to assume for now, and make more robust laterhundreds-father-404
05/02/2022, 10:45 PMfilepath
? For example, every single thing underneath the directory?cold-soccer-63228
05/02/2022, 10:46 PMWhat files depend on theFor now, yes. In the future, we would like it to be a bit more granular, but for now we could have everything underneath the directory have dependencies on it? For example, every single thing underneath the directory?filepath
cold-soccer-63228
05/02/2022, 10:47 PMOkay cool. So the simplest—but fragile—way to do this will be to parse the file usingWould I need to add a new target as well, after creating a new rule? Or could I tellortokenize
to extract theast
linefilepath="path/to/some_handler.py",
tailor
to use this rule afterwards?hundreds-father-404
05/02/2022, 10:50 PMtailor
to create all your python_sources
and python_tests
etc, no need for new targets. Your dep inference rule will enhance those targetscold-soccer-63228
05/02/2022, 10:51 PMhundreds-father-404
05/02/2022, 10:51 PM_package_config.py
files do you have? I wonder if it would be feasible to start w/ simply hardcoding the filepath
in the dependencies
file, at least to start while you're iterating
I was expecting there to be a lot more entries in _package_config.py
hundreds-father-404
05/02/2022, 10:53 PMHow do I reference my rule?You are going to be adding a new entry into the dep inference plugin hook. Which gets registered with something like
UnionRule(InferDependenciesRequest, InferInitDependencies),
at the bottom of python/dependency_inference/rules.py
Sorry we don't have a dedicated guide for this - a few people have been asking about this plugin hook this month and I'm itching to write a guidecold-soccer-63228
05/02/2022, 10:59 PMQuestion: how many of theseWe have one for every root-level directory.files do you have?_package_config.py
I was expecting there to be a lot more entries inSome of these files have a many entries. I wanted to send a simple one so it'd be easy to understand what it looks like_package_config.py
cold-soccer-63228
05/02/2022, 10:59 PMYou are going to be adding a new entry into the dep inference plugin hook. Which gets registered with something likeDoes this mean I'll be contributing to the source code itself, as opposed to adding the rule in my own repository?at the bottom ofUnionRule(InferDependenciesRequest, InferInitDependencies),
python/dependency_inference/rules.py
hundreds-father-404
05/02/2022, 11:01 PMcold-soccer-63228
05/02/2022, 11:01 PM