high-egg-2153
02/02/2021, 2:24 PM*python_library*(
name = "lib",
)
*resources*(
name = "translations",
sources = ["translations/**"],
)
*pex_binary*(
name = "bin",
entry_point = "<http://dash_campaign_status_report.app|dash_campaign_status_report.app>",
dependencies = [
":lib",
":translations",
"lib_dash:lib",
"lib_dash_security:lib",
]
)
If I run dependencies on the bin target I get:
dash_campaign_status_report/app.py:lib
dash_campaign_status_report/translations/en/LC_MESSAGES/messages.mo:../../../translations
dash_campaign_status_report/translations/en/LC_MESSAGES/messages.po:../../../translations
dash_campaign_status_report/translations/fr/LC_MESSAGES/messages.mo:../../../translations
dash_campaign_status_report/translations/fr/LC_MESSAGES/messages.po:../../../translations
dash_campaign_status_report/translations/messages.pot:../translation
hundreds-father-404
02/02/2021, 2:56 PMhigh-egg-2153
02/02/2021, 3:00 PMhundreds-father-404
02/02/2021, 3:02 PMhigh-egg-2153
02/02/2021, 3:04 PMhigh-egg-2153
02/02/2021, 3:05 PMhundreds-father-404
02/02/2021, 3:11 PMenough-analyst-54434
02/02/2021, 3:41 PMhigh-egg-2153
02/02/2021, 4:29 PMhigh-egg-2153
02/02/2021, 4:31 PMenough-analyst-54434
02/02/2021, 4:45 PMzip_safe=False
(https://www.pantsbuild.org/docs/python-target-types#pex_binary) or else unzip=True
if you're on Pants 2.3.0.dev1 or newer?hundreds-father-404
02/02/2021, 5:43 PMhigh-egg-2153
02/02/2021, 5:50 PMenough-analyst-54434
02/02/2021, 6:17 PMvenv
mode that can be applied to pex_binary
targets: https://github.com/pantsbuild/pants/pull/11510enough-analyst-54434
02/02/2021, 6:18 PMhigh-egg-2153
02/02/2021, 6:21 PMhigh-egg-2153
02/03/2021, 1:39 PMenough-analyst-54434
02/03/2021, 4:39 PMzip_safe=false
extracts the code portion of the pex under ~/.pex/code/<sha1>
The __main__,py
and the PEX `.bootstrap/`code still run from inside the zip. To get full extraction you need unzip=True
available in 2.3.0.dev2
. Even that may nt do the trick though dependening on how the translation code works. You may need to wait for execution_mode=venv
.high-egg-2153
02/03/2021, 6:18 PMcache/pants/named_caches/pex_root/unzipped_pexes/99f66b4789e43b1deae1ac4bbb0348a2be26a3c9/translations
high-egg-2153
02/03/2021, 6:19 PMhundreds-father-404
02/03/2021, 6:22 PMI thought it was self contained meaning all my code and all dependencies would in the pex.Hm, well, so, there is an interesting divergence between
./pants run
and ./pants package
. With ./pants run
, we do not put source files in the PEX file and they simply are in the chroot. This avoids an overhead where we need to keep rebuilding a PEX file every time you make a change to source files
But with ./pants package
, source files are included because you want a single archive file
For debugging, I recommend using the workflow of ./pants package
, followed by running via dist/path.to.module/app.pex
. There are fewer moving parts with that than ./pants run
. Once that's working, we can translate to ./pants run
high-egg-2153
02/03/2021, 6:28 PMfrom pkg_resources import get_distribution, parse_version
ModuleNotFoundError: No module named 'pkg_resources'
I do have:
*python_requirements*(
module_mapping = {
"setuptools": ["pkg_resources"],
},
)
in my root BUILD file.enough-analyst-54434
02/03/2021, 6:33 PMls -a
?hundreds-father-404
02/03/2021, 6:34 PM./pants dependencies --transitive path/to:pex_binary
? if not, you could force it to be included by adding something like //:setuptools
to the dependencies
of your pex_binary
targetenough-analyst-54434
02/03/2021, 6:34 PMhigh-egg-2153
02/03/2021, 6:37 PMenough-analyst-54434
02/03/2021, 6:38 PM./pants dependencies --transitive path/to:pex_binary
as a sanity check?high-egg-2153
02/03/2021, 6:42 PM./pants dependencies --transitive dash_campaign_status_report:bin
//:Flask-Babel
//:SQLAlchemy
//:boto3
//:dash
//:dash-core-components
//:dash-embedded
//:dash-html-components
//:dash-table
//:pandas
//:requirements.txt
dash_campaign_status_report/app.py:lib
dash_campaign_status_report/translations/en/LC_MESSAGES/messages.mo:../../../translations
dash_campaign_status_report/translations/en/LC_MESSAGES/messages.po:../../../translations
dash_campaign_status_report/translations/fr/LC_MESSAGES/messages.mo:../../../translations
dash_campaign_status_report/translations/fr/LC_MESSAGES/messages.po:../../../translations
dash_campaign_status_report/translations/messages.pot:../translations
lib_dash/dash_app.py:lib
lib_dash_security/security.py:lib
hundreds-father-404
02/03/2021, 6:43 PM//:setuptools
to the dependencies
field of dash_campaign_status_report:bin
. We'll want to figure out why dep inference isn't working, but in a separate threadhigh-egg-2153
02/03/2021, 6:55 PMhundreds-father-404
02/03/2021, 7:05 PM./pants package
, then running via dist/dash_campagin_status_report/bin.pex
? (Where unzip=True
)high-egg-2153
02/03/2021, 7:11 PM~/.pex/unzipped_pexes/56cdee2343fcaf3ef97c9aba8c74d6c1167141e9/translations
With the following change it works:
translations_path = os.path.join(app.root_path, 'dash_campaign_status_report/translations')
app.config['BABEL_TRANSLATION_DIRECTORIES'] = translations_path
babel = Babel(app)
However, this probably won't work in my case once deployed to production.hundreds-father-404
02/03/2021, 7:14 PMhigh-egg-2153
02/03/2021, 7:15 PM