little-train-28371
11/02/2022, 4:13 PMlittle-train-28371
11/02/2022, 4:14 PMpkg_resources.get_distribution
to retrieve the version.enough-analyst-54434
11/02/2022, 4:58 PMlittle-train-28371
11/02/2022, 9:58 PM./pants package ::
, the issues comes when I try to deploy the .zip package to cloud functions.little-train-28371
11/02/2022, 9:58 PMFile "/layers/google.python.pip/pip/lib/python3.9/site-packages/functions_framework/__init__.py", line 288, in create_app
spec.loader.exec_module(source_module)
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/workspace/main.py", line 54, in <module>
__RUNNER = __EntryPoint.parse("run = %s" % __lambdex_entry_point).resolve()
File "/workspace/.bootstrap/pex/vendor/_vendored/setuptools/pkg_resources/__init__.py", line 2481, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/workspace/generic_file_processing_function/main.py", line 9, in <module>
from common.audit_service_client import BigqueryAuditServiceClient
File "/workspace/common/audit_service_client.py", line 8, in <module>
from google.cloud import bigquery
File "/workspace/.deps/google_cloud_bigquery-3.3.3-py2.py3-none-any.whl/google/cloud/bigquery/__init__.py", line 35, in <module>
from google.cloud.bigquery.client import Client
File "/workspace/.deps/google_cloud_bigquery-3.3.3-py2.py3-none-any.whl/google/cloud/bigquery/client.py", line 59, in <module>
from google.cloud.bigquery_storage_v1.services.big_query_read.client import (
File "/workspace/.deps/google_cloud_bigquery_storage-2.16.0-py2.py3-none-any.whl/google/cloud/bigquery_storage_v1/__init__.py", line 21, in <module>
__version__ = pkg_resources.get_distribution(
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/pkg_resources/__init__.py", line 471, in get_distribution
dist = get_provider(dist)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/pkg_resources/__init__.py", line 347, in get_provider
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/pkg_resources/__init__.py", line 891, in require
needed = self.resolve(parse_requirements(requirements))
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/pkg_resources/__init__.py", line 777, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'google-cloud-bigquery-storage' distribution was not found and is required by the application"
enough-analyst-54434
11/03/2022, 11:46 PMpex_binary
target instead of your current `python_google_cloud_function`target. For example:
pex_binary(
name=...same...
platform="linux_x86_64-cp-39-cp39",
resolve_local_platforms=True,
execution_mode="venv",
dependencies=[...same...]
)
The key difference from your current python_google_cloud_function
target is the execution_mode="venv"
- that should get rid of namespace package issues, maybe.
The only other difference is that instead of specifying your handler in Google Cloud as handler
as noted here: https://www.pantsbuild.org/docs/google-cloud-function-python#step-4-upload-to-google-cloud you just specify the actual entrypoint in your code. but prefixed with __pex__.
. That allows the PEX to install itself in a venv out on Google Cloud when the GCF infrastructure tries to import your handler.enough-analyst-54434
11/03/2022, 11:48 PMlittle-train-28371
11/03/2022, 11:51 PMlittle-train-28371
11/24/2022, 11:51 PM__pex__.
is that in pex_binary(entry_point="__pex__.myfunction.main:main")
?little-train-28371
11/24/2022, 11:54 PMmyfunction/main.py
… where i would do something like __entry__.main = main
enough-analyst-54434
11/25/2022, 12:05 AMpex_binary
entry point. I'm just referring to the AWS lambda configuration out on AWS. It's there you need to tell AWS to load __pex__.yourpackage.yourmodule.yourfunction
.little-train-28371
11/25/2022, 12:13 AMImportError: Error while finding loader for '__pex__.generic_file_processing_function.main.generic_file_processing' (<class 'ModuleNotFoundError'>: No module named '__pex__')
enough-analyst-54434
11/25/2022, 3:35 PM__pex__
magic as a bare import before any other 3rdparty import, like so:
$ cat src/main.py
import __pex__
import functions_framework
import cowsay
@functions_framework.http
def my_http_function(request):
return cowsay.main.get_output_string("tux", "Hello Pex!")
$ pex --python python3.10 "functions-framework==3.*" cowsay==5.0 -D src -o gcf-example.zip
$ curl -D- <https://gcf-example-yktwqotlra-wl.a.run.app>
HTTP/2 200
content-type: text/html; charset=utf-8
x-cloud-trace-context: 949a3c86088d4c760779eb166538b455;o=1
date: Fri, 25 Nov 2022 15:33:12 GMT
server: Google Frontend
content-length: 268
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
__________
| Hello Pex! |
==========
\
\
\
.--.
|o_o |
|:_/ |
// \ \
(| | )
/'\_ _/`\
\___)=(___/
little-train-28371
11/25/2022, 3:51 PMenough-analyst-54434
11/25/2022, 3:55 PMenough-analyst-54434
11/25/2022, 3:55 PMlittle-train-28371
11/25/2022, 3:56 PMlittle-train-28371
11/26/2022, 12:13 AMlittle-train-28371
11/26/2022, 12:18 AMFile "/layers/google.python.pip/pip/bin/functions-framework", line 8, in <module>
sys.exit(_cli())
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/functions_framework/_cli.py", line 43, in _cli
create_server(app, debug).run(host, port)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/functions_framework/_http/__init__.py", line 38, in run
http_server.run()
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/functions_framework/_http/flask.py", line 25, in run
self.app.run(self.host, self.port, debug=self.debug, **self.options)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 920, in run
run_simple(t.cast(str, host), port, self, **options)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/werkzeug/serving.py", line 1010, in run_simple
inner()
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/werkzeug/serving.py", line 950, in inner
srv = make_server(
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/werkzeug/serving.py", line 782, in make_server
return ThreadedWSGIServer(
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/werkzeug/serving.py", line 679, in __init__
server_address = get_sockaddr(host, int(port), self.address_family)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/werkzeug/serving.py", line 626, in get_sockaddr
res = socket.getaddrinfo(
File "/layers/google.python.runtime/python/lib/python3.9/socket.py", line 954, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
LookupError: unknown encoding: idna
enough-analyst-54434
11/26/2022, 12:39 AMlittle-train-28371
11/26/2022, 12:41 AMenough-analyst-54434
11/26/2022, 12:49 AMpex_binary(..., execution_mode="venv")
. I just want to make sure you've done that or will be doing that. If you do end up using that but running into issues, you may want to upgrade to Pants 2.15.x and also enable `venv_site_packages_copies=True`: https://www.pantsbuild.org/v2.15/docs/reference-pex_binary#codevenv_site_packages_copiescodelittle-train-28371
11/26/2022, 12:50 AMvenv
modelittle-train-28371
11/26/2022, 12:51 AMenough-analyst-54434
11/26/2022, 1:00 AMlittle-train-28371
11/26/2022, 1:19 AM