Transcrypt transpiles Python file but Wrangler is unable to publish

I assumed that importing google-cloud-bigquery would not be something that could be transpiled, but Transcrypt handled it just fine. However, whenever I try to publish, wrangler throws this error:

Error while compiling (offending file last):
	File '/Users/username/cdnperf/index.py', line 6, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/cloud/bigquery/__init__.py', line 153, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/cloud/bigquery/magics.py', line 617, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/gapic_v1/client_info.py', line None, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/__init__.py', line None, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/pkg_resources/__init__.py', line 617, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/gapic_v1/__init__.py', line 26, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/gapic_v1/method_async.py', line 22, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py', line 23, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/timeout.py', line 61, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/general_helpers.py', line 19, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/six.py', line 60, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/datetime_helpers.py', line 23, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/protobuf/timestamp_pb2.py', line 20, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/grpc_helpers_async.py', line 25, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/gapic_v1/config_async.py', line 22, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/gapic_v1/config.py', line 27, at import of:
	File '/Users/username/cdnperf/env/lib/python3.7/site-packages/google/api_core/retry.py', line 60, at import of:
	File 'functools', line 6, namely:
	
	Import error, can't find any of:
		/Users/username/cdnperf/google/cloud/bigquery_storage_v1.py
		/Users/username/cdnperf/google/cloud/bigquery_storage_v1.js
		/Users/username/cdnperf/env/lib/python3.7/site-packages/transcrypt/modules/google/cloud/bigquery_storage_v1.py
		/Users/username/cdnperf/env/lib/python3.7/site-packages/transcrypt/modules/google/cloud/bigquery_storage_v1.js
		/Users/username/cdnperf/google/cloud/bigquery_storage_v1.py
		/Users/username/cdnperf/google/cloud/bigquery_storage_v1.js
		/Users/username/opt/anaconda3/lib/python3.7/google/cloud/bigquery_storage_v1.py
		/Users/username/opt/anaconda3/lib/python3.7/google/cloud/bigquery_storage_v1.js
		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/google/cloud/bigquery_storage_v1.py
		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/google/cloud/bigquery_storage_v1.js
		/Users/username/cdnperf/env/lib/python3.7/site-packages/google/cloud/bigquery_storage_v1.py
		/Users/username/cdnperf/env/lib/python3.7/site-packages/google/cloud/bigquery_storage_v1.js
		/Users/username/cdnperf/google/cloud.py
		/Users/username/cdnperf/google/cloud.js
		/Users/username/cdnperf/env/lib/python3.7/site-packages/transcrypt/modules/google/cloud.py
		/Users/username/cdnperf/env/lib/python3.7/site-packages/transcrypt/modules/google/cloud.js
		/Users/username/cdnperf/google/cloud.py
		/Users/username/cdnperf/google/cloud.js
		/Users/username/opt/anaconda3/lib/python3.7/google/cloud.py
		/Users/username/opt/anaconda3/lib/python3.7/google/cloud.js
		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/google/cloud.py
		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/google/cloud.js
		/Users/username/cdnperf/env/lib/python3.7/site-packages/google/cloud/__init__.py
		/Users/username/cdnperf/env/lib/python3.7/site-packages/google/cloud/__init__.js
		/Users/username/cdnperf/google/cloud.py
		/Users/username/cdnperf/google/cloud.js
		/Users/username/cdnperf/env/lib/python3.7/site-packages/transcrypt/modules/google/cloud.py
		/Users/username/cdnperf/env/lib/python3.7/site-packages/transcrypt/modules/google/cloud.js
		/Users/username/cdnperf/google/cloud.py
		/Users/username/cdnperf/google/cloud.js
		/Users/username/opt/anaconda3/lib/python3.7/google/cloud.py
		/Users/username/opt/anaconda3/lib/python3.7/google/cloud.js
		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/google/cloud.py
		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/google/cloud.js
		/Users/username/cdnperf/env/lib/python3.7/site-packages/google/cloud/__init__.py
		/Users/username/cdnperf/env/lib/python3.7/site-packages/google/cloud/__init__.js


Aborted


👀  ./index.py
Module build failed (from ./node_modules/transcrypt-loader/__target_es5__/index.js):
Error: Command failed: python3 -m transcrypt --nomin --map --verbose "index"
    at checkExecSyncError (child_process.js:630:11)
    at Object.execSync (child_process.js:666:15)
    at Object.main (/Users/username/cdnperf/node_modules/transcrypt-loader/__target_es5__/index.js:56:67)
Error: webpack returned an error. Try configuring `entry` in your webpack config relative to the current working directory, or setting `context = __dirname` in your webpack config.

I’d be fine knowing that Transcrypt simply can’t handle this, but the fact that it runs fine and Wrangler instead fails makes me think that the error is correctable. Any thoughts? I’ve pip installed google-cloud-bigquery in the virtual environment that I’m working in but that doesn’t seem to matter.

As an alternative, Google Cloud can be imported into JavaScript, but I’m just unsure as to how I do that in a Python Worker since I can’t just edit the final file. Any ideas here?

Wrangler is running webpack transcrypt-loader (https://www.npmjs.com/package/transcrypt-loader) which is in turn running python3 -m transcrypt --nomin --map --verbose "index" and looks to be failing during compile.

I’m not sure what you saw to indicate that transcrypt handled the import, because that error looks like it’s coming from transcrypt, not anything wrangler specific.

Have you read http://www.transcrypt.org/docs/html/special_facilities.html#transcrypt-s-module-mechanism ?

You’ll likely have to use the JavaScript version of the Google library with Transcrypt.

If you are using Webpack, you should be able to just use the Node.js require() function in your Python file and assign it to a Python variable like:

BigQuery = require('@google-cloud/bigquery')

From there you can just use the BigQuery object and import into other Python modules like any other Python library.