high-egg-2153
02/09/2021, 1:03 AMhappy-kitchen-89482
02/09/2021, 2:01 AMhigh-egg-2153
02/09/2021, 2:32 AM*files*(
name = "common_assets",
sources = [
"assets/**",
],
)
In my application folder (/dash_campaign_status_report/BUILD) I have:
*resources*(
name = "assets",
sources = [
"assets/**",
],
)
*relocated_files*(
name="common",
files_targets=['//:common_assets'],
src='',
dest='dash_campaign_status_report',
)
*pex_binary*(
name = "bin",
dependencies = [
":assets",
":common",
],
entry_point = "<http://dash_campaign_status_report.app|dash_campaign_status_report.app>",
)
When I package :bin I see the assets from the application folder but not the common ones.happy-kitchen-89482
02/09/2021, 5:01 PMhigh-egg-2153
02/09/2021, 7:58 PMdash_campaign_status_report/assets/dash-campaign-status-report.css:../assets
dash_campaign_status_report/assets/dash.css:../assets
dash_campaign_status_report:common_assets
high-egg-2153
02/09/2021, 7:59 PMhigh-egg-2153
02/09/2021, 8:01 PMhundreds-father-404
02/09/2021, 8:50 PMarchive
type? https://www.pantsbuild.org/docs/resources#archive-create-a-zip-or-tar-file
You'd keep the pex_binary
still, and only be adding the new archive
target. You don't necessarily need to use archive
at the end of the day, now the goal is solely to verify those files are showing up where you expect in the archive. It will allow us to narrow down the problemhigh-egg-2153
02/09/2021, 8:55 PM*archive*(
name = "archive",
files = [
":assets",
":common_assets",
],
format="tar",
)
high-egg-2153
02/09/2021, 8:56 PMhundreds-father-404
02/09/2021, 8:58 PMhigh-egg-2153
02/09/2021, 9:00 PMhigh-egg-2153
02/09/2021, 9:07 PMhundreds-father-404
02/09/2021, 10:37 PMarchive(
name = "archive",
files = [
":assets",
":common_assets",
],
format="tar",
)
You can get all the CSS files to show up correctly in the same folder iff :assets
is files
, and :common_assets
is relocated_files
. This is expected. Note that the files
field expects file targets, not resources targets. So the resources targets get ignored. That's pretty subtle - we should add a warning
--
For the pex_binary
, you're right that I can't get the relocated_files
to show up. I can get :assets
if it's a resources
target, but not if it's a files
target. So there's something going on there.
It looks like this is actually intentional. And now I'm remembering that it has to do with source roots. In a PEX, we strip source roots, so src/python/myorg/app.py
becomes myorg/app.py
in the final binary. But source roots are never stripped with a `files`/`relocated_files()` target, and it would be incorrect to put src/assets/data.json
with that prefix iiuc
Instead, this is why the archive
target type exists. You'll create an archive with a PEX file in it, and then the loose CSS files also accompanying the PEX. Then, when you run your PEX, it can access those loose files
It will look something like this:
relocated_files(
name="common_assets",
files_targets=['assets:common'],
src='',
dest='dash_campaign_status_report',
)
files(
name = "assets",
sources = [
"assets/**",
],
)
archive(
name = "archive",
files = [
":assets",
":common_assets",
],
packages=[":bin"],
format="tar",
)
pex_binary(
name = "bin",
entry_point = "main.py",
)
Does that make sense?high-egg-2153
02/09/2021, 11:22 PMhundreds-father-404
02/09/2021, 11:26 PM./pants roots
say?high-egg-2153
02/10/2021, 12:03 AM.
plugins
happy-kitchen-89482
02/10/2021, 12:52 AMpex
no? Just by having them as resource
dependencieshappy-kitchen-89482
02/10/2021, 12:53 AM.
, so that would be a noophappy-kitchen-89482
02/10/2021, 12:53 AMhigh-egg-2153
02/10/2021, 3:00 AM.
|ββ BUILD
|ββ assets
|Β βββ common.css
βββ dash_campaign_status_report
βββ BUILD
βββ assets
Β Β βββ dash-campaign-status-report.css
Β Β βββ dash.css
If I add a resource target to the root BUILD like this:
resources(
name = "common_assets",
sources = [
"assets/common.css",
],
)
And then I add the resources to the pex_binary target in dash_campaign_status_report/BUILD like this:
pex_binary(
name = "bin",
dependencies = [
...
"//:common_assets",
...
],
entry_point = ...,
)
I get a pex layout that looks more or less the same as the repository layout:
.
|ββ assets
|Β βββ common.css
βββ dash_campaign_status_report
βββ assets
Β Β βββ dash-campaign-status-report.css
Β Β βββ dash.css
What I want is:
.
βββ dash_campaign_status_report
βββ assets
βββ common.css
Β Β βββ dash-campaign-status-report.css
Β Β βββ dash.css
hundreds-father-404
02/10/2021, 5:18 PMpex_binary
to work with files targets @happy-kitchen-89482?
I'm actually not certain why it would be problematic to have an unstripped file like src/assets/img.png
in the PEX? I think it wouldn't work to load via pgkutil.get_data()
, but maybe open()
would still work? If you don't recall, I can play around with thishappy-kitchen-89482
02/10/2021, 5:40 PMhundreds-father-404
02/10/2021, 5:42 PMhappy-kitchen-89482
02/10/2021, 5:44 PMpkgutil
if you happened to know that the file fell into a package, and open()
would only work if you were running unzippedhappy-kitchen-89482
02/10/2021, 5:44 PMhundreds-father-404
02/10/2021, 5:45 PMresources
because it Just Works more easily, but agreed.
And better than the confusing alternative of adding relocated_resources
high-egg-2153
02/10/2021, 5:45 PMhundreds-father-404
02/10/2021, 11:54 PMhundreds-father-404
02/11/2021, 7:35 PMhundreds-father-404
02/12/2021, 2:27 AMfiles()
does not play nice with PEX.
I'm thinking we do actually want relocated_resources
. @happy-kitchen-89482 thoughts? https://github.com/pantsbuild/pants/pull/11551#issuecomment-777926798hundreds-father-404
02/12/2021, 2:28 AMhundreds-father-404
02/12/2021, 7:04 PMwith open()
or pkgutil.get_data()
?
https://github.com/pantsbuild/pants/pull/11551#issuecomment-778388738hundreds-father-404
02/12/2021, 7:09 PMhigh-egg-2153
02/12/2021, 7:33 PMwitty-crayon-22786
02/12/2021, 8:04 PMwitty-crayon-22786
02/12/2021, 8:06 PMhundreds-father-404
02/12/2021, 8:10 PMhundreds-father-404
02/12/2021, 8:17 PMwitty-crayon-22786
02/12/2021, 8:19 PMhundreds-father-404
02/12/2021, 8:20 PMwitty-crayon-22786
02/12/2021, 8:21 PMsrc/resources/assets
hundreds-father-404
02/12/2021, 8:22 PMhigh-egg-2153
02/12/2021, 8:31 PMwitty-crayon-22786
02/12/2021, 8:31 PMenough-analyst-54434
02/12/2021, 8:31 PMhundreds-father-404
02/12/2021, 8:35 PMwitty-crayon-22786
02/12/2021, 8:37 PM${project}/assets/common.css
, rather than assets/common.css
β¦?hundreds-father-404
02/12/2021, 8:37 PMwitty-crayon-22786
02/12/2021, 8:38 PMhundreds-father-404
02/12/2021, 8:39 PMwitty-crayon-22786
02/12/2021, 8:41 PMrun
and package
diverging seems like a separate (related) problem, perhaps.witty-crayon-22786
02/12/2021, 8:42 PMtest
hundreds-father-404
02/12/2021, 8:43 PMhundreds-father-404
02/16/2021, 7:02 PMhigh-egg-2153
02/16/2021, 7:07 PMhundreds-father-404
02/16/2021, 7:09 PMrelocated_resources
- Dash is loading these things as resources, not as files. And the use case you have is an advanced one easy to mess up, but it's a legit use case