wooden-thailand-8386
09/29/2020, 8:14 PMpython_app target when using bundle it can get files from a different folder by using rel_path right? I mean, that’s basically what I’m doing… my BUILD file is inside projects/projectA and I need to have files under libs/3rdparty/mydata to be packaged together.wooden-thailand-8386
09/29/2020, 8:16 PMrel_path as long as the new target archive can reproduce the files structure.. I’m not really changing the dest folder name. That’s probably a good idea to implement using maybe what @witty-crayon-22786 mentioned.. about those intermediate steps…wooden-thailand-8386
09/29/2020, 8:17 PMfiles and resources and when to use on over the other. Maybe if we could simplify this…wooden-thailand-8386
09/29/2020, 8:21 PMprojects/projectA/BUILD that defines resources and two of those resources lives under folders..:
projects/projectA/data/
projects/projectA/deploy/
by defining the resources target at the source root of projectA and pointing to data/***/** I expect (and imagine) that the result will be that the folder structure data and whatever is inside of it are kept.
I’m not sure if that’s the “right” way of doing this.. Idk if I should have a BUILD file inside data that defines that resource target or not.. but that’s kinda how I managed to solve my issue. Again, it was trial and error.hundreds-father-404
09/29/2020, 8:21 PMas long as the new target archive can reproduce the files structure.Yes, this is the default behavior. It would copy the path exactly as it is.
libs/3rdparty/mydata would keep that same path
That PR is about a feature to allow you to relocate the path at runtime, so that libs/3rdparty/mydata can become something you want like my_custom_prefix/mydata. This is helpful if you, for example, want to convert src/python/myorg/myteam/project/pyproject.toml to simply be pyproject.toml in your final archive or in your testwooden-thailand-8386
09/29/2020, 8:22 PMwooden-thailand-8386
09/29/2020, 8:24 PMresource but it does if it’s a filehundreds-father-404
09/29/2020, 8:24 PMone other thing that I already asked and it still gives me a hard time is the difference between files and resources and when to use on over the otherSorry about the confusion. I started drafting a page explaining how to use both features, but was waiting to finish this new PR until then For
files, you will always have the full path as it is in your actual project layout.
In contrast, resources are loaded like you would load normal code in your language. If you have the file src/python/myorg/f.py, then you would say import myorg.f, not import src.python.myorg.f. It’s the same with resources, you would say pkg_resources.get_data("my_<http://org.my|org.my>_data"), rather than pkg_resources.get_data("<http://src.python.my|src.python.my>_<http://org.my|org.my>_data")hundreds-father-404
09/29/2020, 8:24 PMOh so that’s the tricky part (at least to me) it would recreate the full path?Ah, oops. By full path, I mean the relative path from the build root. It won’t be an absolute path
wooden-thailand-8386
09/29/2020, 8:24 PMwooden-thailand-8386
09/29/2020, 8:26 PMhundreds-father-404
09/29/2020, 8:28 PMsrc/python/myorg/myteam/project/pyproject.toml to pyproject.toml, but have Pants do it for you, rather than needing to do it in your test code or modifying the archive that Pants had created for youhundreds-father-404
09/29/2020, 8:28 PMwooden-thailand-8386
09/29/2020, 8:29 PMwooden-thailand-8386
09/29/2020, 8:30 PMfiles=[] either files or relocated_files no? I’m trying to simplify it from a user standpoint.wooden-thailand-8386
09/29/2020, 8:30 PMhundreds-father-404
09/29/2020, 8:32 PMStill can’t RustOh, about 80% of our contributions are in typed Python 3 btw! We only use Rust when changing the internals of the engine, like optimizing how the engine reads from the filesystem. That all gets abstracted away though; where all the logic of Pants gets written is in Python
so forgive meAnd not at all, this type of feedback is extremely useful. There are lots of ways of contributing to an open source project
wooden-thailand-8386
09/29/2020, 8:34 PMtyped Python 3that I can do
wooden-thailand-8386
09/29/2020, 8:35 PMper-consumer solution lol, done that in my startup before and didnt go well on the long termwooden-thailand-8386
09/29/2020, 8:36 PMfiles and resources as dependencies? If so it can be very interestinghundreds-father-404
09/29/2020, 8:37 PMfiles() target has a sources_prefix_mapping field. This is the current PR. But an issue is that it means if someone unintentionally updates that one files() target, they may end up breaking a bunch of consumers without realizing it.
2. The information lives entirely at consumers, such as your archive() target or your python_tests target. This likely has the benefit of being easier to understand because all the magical remapping is centralized to one place. But it could result in lots of duplication; it’s not composable. You can’t define a remapping and then reuse it somewhere else.
3. Keep files() the same as before, and add a new target type called relocated_files. You could have multiple relocated_files() targets describing the same files() target, but mapping them in different ways. Your archive and python_tests targets could either depend on the original files(), or on the relocated_files() targethundreds-father-404
09/29/2020, 8:39 PMsources_prefix_mapping for the original files target, and they break a ton of consumers without realizing it.
#3 still has the risk of updating one target resulting in breaking multiple consumers, but it makes things much more explicit than #1.wooden-thailand-8386
09/29/2020, 8:54 PMwitty-crayon-22786
09/29/2020, 9:35 PMtest and deploy: to minimize the amount of custom code that can’t be tested, because they can each expect files to live in the same placehundreds-father-404
09/29/2020, 9:43 PMrelocated_files target mapping 1-1 with a files target? Vs. allowing relocated_files to aggregate multiple targets and having complex branching mapping, like “if this prefix, use this; otherwise, rewrite like this”
That is,
relocated_files(
name="tgt1",
files_target="//:json",
from="original_prefix",
to="new_prefix",
)
relocated_files(
name="tgt2",
files_target="3rdparty/json",
from="3rdparty/json",
to="json",
)
vs.
relocated_files(
files_targets=["//:json", "3rdparty/json"],
mapping={"": "json", "3rdparty": ""},
)
Even if 1-1 results in much more verbosity, I think it’s going to be worth it. files and resources already confuses people. This could be a very confusing new feature as well. Keeping it simple will be valuable, even it results in some duplicationwitty-crayon-22786
09/29/2020, 9:45 PMhundreds-father-404
09/29/2020, 9:46 PMif the simple thing can grow into a more complicated thingWhat do you mean?
witty-crayon-22786
09/29/2020, 9:47 PMrelocated_files(files_target=..) (note, singular) growing into relocated_files(files_targets=..) (note, plural)… that’s an easy deprecationhundreds-father-404
09/29/2020, 9:48 PMfrom and to field. It’s the complex mapping in a single target that I want to avoid, e.g. the dictionarywitty-crayon-22786
09/29/2020, 9:49 PMtgt1 and tgt2 sketch is that that also requires two files targets behind them, so four total. not a huge deal, but the mapping dict is more growable, because you can eventually remove the restriction(s)hundreds-father-404
09/29/2020, 9:49 PMbut the mapping dict is more scalableYeah, but harder to reason about
witty-crayon-22786
09/29/2020, 9:50 PMhundreds-father-404
09/29/2020, 9:51 PM{"": "json", "3rdparty": ""}, what do you think it would do? Note that "" matches both files, but 3rdparty only matches one file. Should both transformations be applied? Only one of them?witty-crayon-22786
09/29/2020, 9:53 PMwitty-crayon-22786
09/29/2020, 9:53 PMhundreds-father-404
09/29/2020, 9:54 PMfrom and one to by them being proper fields. For a given relocated_files target, there can only be a single mapping defined. And that gets applied to every single filewitty-crayon-22786
09/29/2020, 9:54 PMwitty-crayon-22786
09/29/2020, 9:54 PMAnd that gets applied to every single file
from still needs to match though.witty-crayon-22786
09/29/2020, 9:55 PMhundreds-father-404
09/29/2020, 9:55 PMwitty-crayon-22786
09/29/2020, 9:56 PMwitty-crayon-22786
09/29/2020, 9:56 PMhundreds-father-404
09/29/2020, 10:29 PMrelocated_files(..., from=..). Python claims it as a keyword
Any ideas for alternatives to from and to? before and after perhaps?hundreds-father-404
09/29/2020, 10:29 PMoriginal and new?witty-crayon-22786
09/29/2020, 10:36 PMjolly-midnight-72759
10/01/2020, 5:01 PMfiles and relocated_files targets that are OUTSIDE the python backend. And resources is really python_resources since it focuses on packaging the files similar to how setup.py does it?jolly-midnight-72759
10/01/2020, 5:03 PMfiles that are used by multiple projects, the target can manage a map that the software can use to find the absolute path to the file.jolly-midnight-72759
10/01/2020, 5:04 PMfiles(
target="ec2_settings",
sources=["*.yaml"],
dst="/opt/example/ec2_settings/",
map="/opt/example/ec2_settings/map.yaml",
)hundreds-father-404
10/01/2020, 5:05 PMresources used to be a field on the python_library target. And I think we used to have a field for jvm_library etc
I’m going to try to write some docs on this today or tomorrow. It’s definitely a common point of confusion, understandably so.witty-crayon-22786
10/01/2020, 5:06 PMresources concept applies to a few different languages which support packaging files to be loaded in a runtime-specific waywitty-crayon-22786
10/01/2020, 5:06 PMwitty-crayon-22786
10/01/2020, 5:07 PMwitty-crayon-22786
10/01/2020, 5:09 PMjolly-midnight-72759
10/01/2020, 5:09 PMjolly-midnight-72759
10/01/2020, 5:09 PMjolly-midnight-72759
10/01/2020, 5:10 PMjolly-midnight-72759
10/01/2020, 5:12 PMjolly-midnight-72759
10/01/2020, 5:13 PMjolly-midnight-72759
10/01/2020, 5:13 PM