proud-dentist-22844
05/10/2023, 4:16 AMpython_sources expands sources => source on python_source
• shell_sources expands sources => source on shell_source
• files expands sources => source on file
• resources expands sources => source on resource
• pex_binaries expands entry_points => entry_point on pex_binary
A target generator that expands along multiple fields by pulling info from a file and using other fields to refine the details:
• python_requirements expands source (a file) and *module_mapping => requirements and modules on python_requirement
But, that pattern is only useful if you are pulling details from another file.
What if I wanted to create a target generator that expands 2 fields (without pulling anything from another file)?
Looking through the targets, the closest I see to what I'm trying to do is relocated_files, but that's not actually a target generator. It has 3 key fields: files_targets, src, dest.
Basically, I'm creating several targets where people define src and dest, where dest is the path that a system package (rpm/deb/...) would install the file. But there are several other fields that will probably be the same across many of the targets: file_mode, file_owner, file_group, file_mtime, so a target generator seems like a great way to have, say, one target generator for all of the executable files, and another for many non-executable files, and another for the config files that should be owned by root, etc. But, I'm not sure about the UX of having several src/dest field pairs defined on the generator. Any ideas?bitter-ability-32190
05/10/2023, 10:45 AMcurved-television-6568
05/10/2023, 11:10 AMpython_requirements example is just another example like the previous ones:
python_requirements expands source => requirements on python_requirement one target per requirement line from the source file. The module mapping is just configuration on top of that, it doesn’t affect what targets are generated.
But, I’m not sure about the UX of having several src/dest field pairs defined on the generator.Do you have a brief example of what this could look like? To me I don’t directly see an issue with having a target generator use multiple fields.
proud-dentist-22844
05/10/2023, 3:06 PMWould a macro be a better choice?This is for a plugin that will go in pants, so an actual target is preferable I think. Though I suppose it could be implemented as a macro instead. 🤔
bitter-ability-32190
05/10/2023, 3:07 PMproud-dentist-22844
05/10/2023, 3:11 PMnfpm_content_symlink
target generator: nfpm_content_symlinks
This one is does not have any source files in the workspace - the list of symlinks gets embedded in the rpm, deb, etc so that the packager creates the symlink when the nfpm-generated-package is installed.
nfpm_content_symlinks(
symlinks=[
("/actual/path/src1", "/symlink/path/dest1"),
("/actual/path/src2", "/symlink/path/dest2"),
("/actual/path/src3", "/symlink/path/dest3"),
],
file_owner="root",
file_group="root",
file_mtime="...", # a timestamp string
)curved-television-6568
05/10/2023, 3:15 PMfile_ fields seems like they could be in that category.proud-dentist-22844
05/10/2023, 3:16 PMsymlinks field as a list of tuples confusing?curved-television-6568
05/10/2023, 3:17 PMcurved-television-6568
05/10/2023, 3:19 PMnfpm_content_symlinks(
symlinks={
"/actual/path/src1": "/symlink/path/dest1",
"/actual/path/src2": "/symlink/path/dest2",
"/actual/path/src3": "/symlink/path/dest3",
},
file_owner="root",
file_group="root",
file_mtime="...", # a timestamp string
)curved-television-6568
05/10/2023, 3:19 PMdict(symlinks) of the formerproud-dentist-22844
05/10/2023, 3:20 PMcurved-television-6568
05/10/2023, 3:21 PMproud-dentist-22844
05/10/2023, 3:21 PMnfpm_content_symlinks(
symlink_srcs={
"/symlink/path/src1": "/actual/path/dest1",
"/symlink/path/src2": "/actual/path/dest2",
"/symlink/path/src3": "/actual/path/dest3",
},
file_owner="root",
file_group="root",
file_mtime="...", # a timestamp string
)curved-television-6568
05/10/2023, 3:22 PMcurved-television-6568
05/10/2023, 3:23 PMproud-dentist-22844
05/10/2023, 3:23 PMproud-dentist-22844
05/10/2023, 3:24 PMproud-dentist-22844
05/10/2023, 3:52 PMnfpm_content_config
target generator: nfpm_content_configs
nfpm_content_configs(
configs=[
("src1.conf", "/etc/dest1.conf"),
("sysconfig/src2.conf", "/etc/sysconfig/dest2.conf"),
(":src3", "/etc/foo/dest3.conf"),
],
noreplace=True, # bool only used for rpm
file_owner="root",
file_group="root",
file_mode=0700,
file_mtime="...", # a timestamp string
)
nfpm_content_config(
src="src1.conf", # an address or path
dest="/etc/dest1.conf",
noreplace=True, # bool only used for rpm
file_owner="root",
file_group="root",
file_mode=0700,
file_mtime="...", # a timestamp string
)proud-dentist-22844
05/10/2023, 3:57 PMsrc is working as a combined source and dependency field. Either it owns the source files or it depends on the target that provides it. How confusing is that? (Is that going to be difficult to implement?)curved-television-6568
05/10/2023, 4:16 PMsrc value could be either a source glob or a target address?curved-television-6568
05/10/2023, 4:18 PMnfpm_content_config(
source="src1.conf", # a path
dest="/etc/dest1.conf",
...
)
nfpm_content_config(
dependencies=[":src3"], # an address
dest="/etc/foo/dest3.conf",
...
)proud-dentist-22844
05/10/2023, 4:20 PMnfpm_content_configs could generate 2 targets for each file, a file target and the nfpm_content_config with a dependency on it. Or if a target address is provided, skip the file target.
That would mean something like this:
nfpm_content_config(
src=":src_file", # or call this "dependency"instead of "src"
dest="/etc/foo.conf,
...
)proud-dentist-22844
05/10/2023, 4:21 PMcurved-television-6568
05/10/2023, 4:22 PMdependencies though..curved-television-6568
05/10/2023, 4:22 PMcurved-television-6568
05/10/2023, 4:23 PMproud-dentist-22844
05/10/2023, 4:23 PMdependencies with an assertion that there can only be one and it must be a file target?curved-television-6568
05/10/2023, 4:23 PMfile dependency as the source for the configcurved-television-6568
05/10/2023, 4:24 PMfile dependencyproud-dentist-22844
05/10/2023, 4:25 PMalso if there’s ever a need to infer more dependencies in the future, it would be weird to have many single valued fields for it
Hmm. Would I need to do something like the
relocated_files target then with dependencies and a src field? Because dest would be a single file, so if dependencies pulls in additional files, how do I know which one is the config file?proud-dentist-22844
05/10/2023, 4:25 PMcurved-television-6568
05/10/2023, 4:26 PMproud-dentist-22844
05/10/2023, 4:26 PMcurved-television-6568
05/10/2023, 4:28 PMcurved-television-6568
05/10/2023, 4:29 PMcurved-television-6568
05/10/2023, 4:29 PM