Skip to content

Conversation

Salakar
Copy link
Member

@Salakar Salakar commented Jun 15, 2022

Description

A first pass at adding Python functions runtime support for init and deploy.

cc @inlined @taeold

Scenarios Tested

Sample Commands

  • firebase experiments:enable pythonfunctions
  • firebase init functions (choose python)
  • firebase deploy --only functions

Copy link
Member

@inlined inlined left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't yet see the full picture, but I'll have faith ^_^

@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2022

Codecov Report

Base: 56.32% // Head: 56.15% // Decreases project coverage by -0.18% ⚠️

Coverage data is based on head (3cf0c20) compared to base (1756213).
Patch coverage: 21.38% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4653      +/-   ##
==========================================
- Coverage   56.32%   56.15%   -0.18%     
==========================================
  Files         315      315              
  Lines       21324    21331       +7     
  Branches     4349     4350       +1     
==========================================
- Hits        12011    11978      -33     
- Misses       8272     8312      +40     
  Partials     1041     1041              
Impacted Files Coverage Δ
src/emulator/controller.ts 12.70% <0.00%> (-0.24%) ⬇️
src/emulator/extensionsEmulator.ts 35.25% <ø> (ø)
src/emulator/functionsRuntimeWorker.ts 64.63% <0.00%> (-0.40%) ⬇️
src/deploy/functions/runtimes/node/index.ts 19.14% <4.34%> (-5.51%) ⬇️
src/emulator/functionsEmulator.ts 8.12% <16.66%> (+1.18%) ⬆️
src/deploy/functions/runtimes/python/index.ts 17.39% <17.39%> (ø)
src/init/features/functions/index.ts 80.76% <33.33%> (-1.90%) ⬇️
src/functions/python.ts 41.66% <41.66%> (ø)
src/extensions/emulator/specHelper.ts 46.15% <46.15%> (-3.85%) ⬇️
src/extensions/emulator/optionsHelper.ts 42.47% <50.00%> (ø)
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

*/
export async function setup(_setup: unknown, config: Config): Promise<void> {
await config.askWriteProjectFile(
`${Config.DEFAULT_FUNCTIONS_SOURCE}/requirements.txt`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use setup.functions.source rather than default here & in other spots

import { FirebaseError } from "../../../../error";
import { Build } from "../../build";

export const LATEST_VERSION: runtimes.Runtime = "python310";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI latest is now python311

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it supported in GCF? Per https://cloud.google.com/functions/docs/concepts/python-runtime, I dont see python311.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe I jumped the gun I was looking a cs

...envs,
ADMIN_PORT: port.toString(),
};
const args = ["python3.10", path.join(modulesDir, "private", "serving.py")];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably best not to hardcode here, maybe make an const

config.set("functions.ignore", ["venv", "__pycache__"]);
// Setup VENV.
await runWithVirtualEnv(
["python3.10", "-m", "venv", "venv"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, best not to hardcode python3.10, use a shared const

taeold added a commit that referenced this pull request Jan 25, 2023
Add support for loading and serving functions written using the Firebase Functions Python SDK (WIP: https://github.com/firebase/firebase-functions-python)

This PR is a fork of #4653 extended with support for emulating Python functions.

Python Runtime Delegate implementation is unsurprising but does include some additional wrapper code to make sure all commands (e.g. spinning up the admin server) runs within the virtualenv environment. For now, we hardcode virtual environment `venv` directory exists on the developer's laptop, but we'll later add support for specifying arbitrary directory for specifying virtualenv directory via firebase.json configuration.

Another note is that each emulated Python function will bind to a Port instead of Unix Domain Socket (UDS) as done when emulating Node.js function. This is because there is no straightfoward, platform-neutral way to bind python webserver to UDS. Finding large number of open port might have a bit more performance penalty and cause bugs due to race condition (similar to #5418) but it seems that we have no other choice atm.
taeold added a commit that referenced this pull request Jan 31, 2023
Add Python as an option for `firebase init functions`.

The python choice is guarded behind the `pythonfunctions` experiment. You can enable the experiment with `firebase experiments:enable pythonfunctions`.

This PR is a fork of #4653. With this PR, #4653 is now obsolete.
@Salakar Salakar closed this Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants