Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python_google_cloud_function includes requirements themselves instead of requirements.txt #21682

Open
ahyatt-continua opened this issue Nov 22, 2024 · 2 comments
Labels
backend: Python Python backend-related issues bug

Comments

@ahyatt-continua
Copy link

Describe the bug
The way that Pants installs into a Google Cloud function is incorrect, and leads to versioning issues. Specifically, Pants does its normal thing of packaging up all of the dependencies into a package in the dist directory, which can then be uploaded to gcloud and used in the deploy. However, what should be done is only package first-party dependencies, and for everything else, create a requirements.txt and put it into the same directory as the one holding the function, and let GCF manage the dependencies (see their docs).

Because this isn't done, other dependencies that are installed by default into the pip environment are used instead of Pants dependencies, so for the set of packages that GCF install automatically, the wrong version will be used. This results in bugs ranging in severity up to not being able to start the GCF function due to unexpected incompatibilities.

Pants version
Which version of Pants are you using?

2.21.0

OS
Are you encountering the bug on MacOS, Linux, or both?

Mac OS

Additional info
Add any other information about the problem here, such as attachments or links to gists, if relevant.

@huonw huonw added the backend: Python Python backend-related issues label Nov 22, 2024
@huonw
Copy link
Contributor

huonw commented Nov 22, 2024

Thanks for calling this out.

Some thoughts:

  • it is frustrating/confusing to me that the system libraries would take precedence over the user-supplied ones 😦
  • for supply chain assurance, it'd be good to include --hashes in the requirements file... but this may interfere with some types of dependencies (eg git repos)
  • I think, unfortunately, always putting all third party dependencies into a requirements file, may inhibit some use cases, like private repositories (git or PyPI-indices), where someone can't (or doesn't want to) get GCF configured with secrets to read them... so we may need customisation and control about what goes into the requirements file.

Note: I only have direct experience with Lambda, not GCF, so these thoughts could easily be wrong.

@ahyatt-continua
Copy link
Author

ahyatt-continua commented Nov 22, 2024

I did manage to workaround this by setting PYTHONPATH="." in my GCF. That should work with how Pants does things, but let me know if I'm missing something.

gcloud functions deploy $NAME --set-env-vars=PYTHONPATH="."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Python Python backend-related issues bug
Projects
None yet
Development

No branches or pull requests

2 participants