Reputation: 165
I have uploaded a python package to Artifact registry. The package is present in the registry:
I have then tried to use the package in a cloud function but I am getting the following error:
Build failed: *** Error compiling './main.py'...
File "./main.py", line 1
import test-package.add as a
^
SyntaxError: invalid syntax; Error ID: 49c34848
Code:
Main.py
import test-package.add as a
def run(event, context):
"""Triggered from a message on a Cloud Pub/Sub topic.
Args:
event (dict): Event payload.
context (google.cloud.functions.Context): Metadata for the event.
"""
print(a.add_one(2))
Requirements.txt
# Function dependencies, for example:
# package>=version
--extra-index-url https://europe-west2-python.pkg.dev/<<PROJECT ID>>/innovation/simple
test-package
Everything seems ok. Seems to be imported correctly and doesnt appear to be an indentation issue. and from reading the documentation Cloud Functions are automatically authorised to access artifact registry, as long as in the same project (which they are), so I think the package has been successfully installed into the function environment.
What could be the reason for the error?
Upvotes: 1
Views: 664
Reputation: 279
Python packages and modules can not use hyphens, only underscores. This section of PEP-8 gives us guidance:
Package and Module Names: Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.
Upvotes: 2