From ef37cb4f0959a6be6f74ca22c6ef32518674bbfe Mon Sep 17 00:00:00 2001 From: Daniel Young Lee Date: Thu, 4 May 2023 13:16:41 -0700 Subject: [PATCH 1/7] Update readme. --- README.md | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 01260251..b6b82a81 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,35 @@ -# Firebase Functions Python SDK +# Cloud Functions for Firebase Python SDK -Welcome GitHub lurker! This repository is a work in progress. It will eventually let users create Cloud Functions for Firebase in Python. This feature is under very early development and not ready for testing. When it is ready, you can get first access by signing up for the [Firebase Alpha Program](https://services.google.cn/fb/forms/firebasealphaprogram/). +The [`firebase-functions`](https://pypi.org/project/firebase-functions/) package provides an SDK for defining Cloud Functions for Firebase in Python. -While you wait for us to get this feature ready for the public, we'd really appreciate you not blowing this up. Let's keep things on the down low for now. 🤫 +Cloud Functions provides hosted, private, and scalable environment where you can run server code. The Firebase SDK for Cloud Functions integrates the Firebase platform by letting you write code that responds to events and invokes functionality exposed by other Firebase features. + +## Learn more + +Learn more about the Firebase SDK for Cloud Functions in the [Firebase documentation](https://firebase.google.com/docs/functions/) or [check out our samples](https://github.com/firebase/functions-samples). + +Here are some resources to get help: + +- Start with the quickstart: https://firebase.google.com/docs/functions/write-firebase-functions +- Go through the guide: https://firebase.google.com/docs/functions/ +- Read the full API reference: https://firebase.google.com/docs/reference/functions/ +- Browse some examples: https://github.com/firebase/functions-samples + +If the official documentation doesn't help, try asking through our official support channels: https://firebase.google.com/support/ + +## Usage + +```python +// functions/index.js +from firebase_functions import db_fn +from notify_users import api + +@db_fn.on_value_created(reference="/posts/{post_id}") +def new_post(event): + print(f"Received new post with ID: {event.params.get('post_id')}") + return notifyUsers(event.data) +``` + +## License + +© Google, 2023. Licensed under [Apache License](LICENSE). \ No newline at end of file From 0f696c97b738555e5532e99c374ecf13f6e100e0 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Thu, 4 May 2023 13:31:59 -0700 Subject: [PATCH 2/7] Add contributing guide, set preview status. --- .github/CONTRIBUTING.md | 24 ++++++++++++++++++++++++ README.md | 6 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .github/CONTRIBUTING.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 00000000..d675d5fb --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,24 @@ +# How to contribute + +We'd love to accept your patches and contributions to this project. There are +just a few small guidelines you need to follow. + +## Contributor License Agreement + +Contributions to this project must be accompanied by a Contributor License +Agreement. You (or your employer) retain the copyright to your contribution, +this simply gives us permission to use and redistribute your contributions as +part of the project. Head over to to see +your current agreements on file or to sign a new one. + +You generally only need to submit a CLA once, so if you've already submitted one +(even if it was for a different project), you probably don't need to do it +again. + +## Code reviews + +All submissions, including submissions by project members, require review. We +use GitHub pull requests for this purpose. Consult [GitHub Help] for more +information on using pull requests. + +[github help]: https://help.github.com/articles/about-pull-requests/ \ No newline at end of file diff --git a/README.md b/README.md index b6b82a81..21447c83 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Cloud Functions for Firebase Python SDK +# Cloud Functions for Firebase Python SDK (Public Preview) The [`firebase-functions`](https://pypi.org/project/firebase-functions/) package provides an SDK for defining Cloud Functions for Firebase in Python. @@ -30,6 +30,10 @@ def new_post(event): return notifyUsers(event.data) ``` +## Contributing + +To contribute a change, [check out the contributing guide](.github/CONTRIBUTING.md). + ## License © Google, 2023. Licensed under [Apache License](LICENSE). \ No newline at end of file From 97fb1a801175dd9a73450450ae9ee694ae087095 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Thu, 4 May 2023 13:32:55 -0700 Subject: [PATCH 3/7] Fix code sample. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 21447c83..8145bb2f 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If the official documentation doesn't help, try asking through our official supp ## Usage ```python -// functions/index.js +# functions/main.py from firebase_functions import db_fn from notify_users import api From 586436ef8d2c33ea69cc6e9cbee6bd3d3ee8a6ef Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Thu, 4 May 2023 13:55:45 -0700 Subject: [PATCH 4/7] Update links. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8145bb2f..c3cbedb7 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Learn more about the Firebase SDK for Cloud Functions in the [Firebase documenta Here are some resources to get help: -- Start with the quickstart: https://firebase.google.com/docs/functions/write-firebase-functions +- Start with the quickstart: https://firebase.google.com/docs/functions/get-started - Go through the guide: https://firebase.google.com/docs/functions/ -- Read the full API reference: https://firebase.google.com/docs/reference/functions/ +- Read the full API reference: https://firebase.google.com/docs/reference/functions/2nd-gen/python - Browse some examples: https://github.com/firebase/functions-samples If the official documentation doesn't help, try asking through our official support channels: https://firebase.google.com/support/ From 70a336d0609b11167575256681804b73a3703612 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Fri, 5 May 2023 10:04:00 -0700 Subject: [PATCH 5/7] Add dev setup guide. --- .github/CONTRIBUTING.md | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d675d5fb..9ebb2e07 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -21,4 +21,69 @@ All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult [GitHub Help] for more information on using pull requests. +## Setup local environment + +Clone the project and run the following commands to setup your environment + +```sh +python3.11 -m venv venv +source venv/bin/activate +pip3 install --upgrade pip +python3.11 -m pip install -e ".[dev]" +``` + +(this also applies to setting up samples environment for each sample) + +### Running tests + +Without coverage: +```bash +python3.11 -m pytest +``` + +With coverage: +```bash +python3.11 -m pytest --cov=src --cov-report term --cov-report html --cov-report xml -vv +``` + +### Formatting code + +```bash +yapf -i -r -p . +``` + +### Running lints & type checking + +```bash +# Type checking +python3.11 -m mypy . +# Linting +python3.11 -m pylint $(git ls-files '*.py') +``` + +### Generating Docs + +Prerequisites: + - On OSX, install getopt: + - `brew install gnu-getopt` + +```sh +./docs/generate.sh --out=./docs/build/ --pypath=src/ +``` + +## Deploying a sample for testing + +Example: + +```sh +cd samples/basic_https +firebase deploy --only=functions +``` + +Note to test your local changes of `firebase-functions` when deploying you sohuld push your changes to a branch on GitHub and then locally in the `sample/*/requirements.txt` change `firebase-functions` dependency line to instead come from git, e.g. : + +``` +git+https://github.com/YOUR_USERNAME/firebase-functions-python.git@YOURBRANCH#egg=firebase-functions +``` + [github help]: https://help.github.com/articles/about-pull-requests/ \ No newline at end of file From 0e55d1b7ddac6c03489e595bf62139cd542246d8 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Fri, 5 May 2023 10:04:40 -0700 Subject: [PATCH 6/7] Fix heading. --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 9ebb2e07..52d52118 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -71,7 +71,7 @@ Prerequisites: ./docs/generate.sh --out=./docs/build/ --pypath=src/ ``` -## Deploying a sample for testing +### Deploying a sample for testing Example: From e2a76911c66dd743c8f2f7fc401a053d3419ee86 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Fri, 5 May 2023 10:13:22 -0700 Subject: [PATCH 7/7] Fix typo. Co-authored-by: Mike Diarmid --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 52d52118..6a3c3c48 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -80,7 +80,7 @@ cd samples/basic_https firebase deploy --only=functions ``` -Note to test your local changes of `firebase-functions` when deploying you sohuld push your changes to a branch on GitHub and then locally in the `sample/*/requirements.txt` change `firebase-functions` dependency line to instead come from git, e.g. : +Note to test your local changes of `firebase-functions` when deploying you should push your changes to a branch on GitHub and then locally in the `sample/*/requirements.txt` change `firebase-functions` dependency line to instead come from git, e.g. : ``` git+https://github.com/YOUR_USERNAME/firebase-functions-python.git@YOURBRANCH#egg=firebase-functions