-
Notifications
You must be signed in to change notification settings - Fork 135
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 function project layout #1970
Comments
@qubitron @kulkarnisonia16 what are your thoughts on the file structure for Python projects? Fwiw, users can create this file structure on their own today if they "Browse..." to a subfolder called "app" when creating their project |
Sure, users can create the function app in a sub folder, but I think the setup goes deeper than that. Assuming there's a For any non-trivial Functions app in Python, this would also require changes to the tasks and launch settings in vscode. I'm proposing that we have layout that just give this them right away. |
@brettcannon thoughts? VS Code requires that the virtual environment be in the root folder of the workspace for it to be found |
https://github.com/microsoft/pvscbot is my suggested workspace layout (and it's the one that led to the docs being updated with their current recommendation 😄 ). There original discussion and further responses from the community can be found in Azure/azure-functions-python-worker#469. |
I just want to make sure we're not re-inventing the wheel here. I'm fine changing the folder structure if we base it on common patterns in the Python community. If we can find other sample projects, guidelines, etc. that would be very helpful. A few problems I have with the docs linked above:
|
@EricJizbaMSFT the As for leaving out a |
@brettcannon is the |
@EricJizbaMSFT could it be an opt (yes/no) to add tests. I would imagine this would do more than create an empty folder. You'd probably want to add the associated task/launch settings for vscode as well a separate requirements.txt file. We should guide users to be successful without having to spend too much time configuring where stuff goes. |
@qubitron I believe it's significant from an Azure Functions perspective (or so the team as told me 😉 ). I believe the runtime makes an |
It seems this is something that the Functions team is working toward, but haven't gotten to yet. I'd say it make sense for the extension to start following this pattern as the other tools also adopt it. Related to: Azure/azure-functions-core-tools#1546 and Azure/azure-functions-core-tools#1547 |
@brettcannon Can you share the folder structure that you think should look like when we stamp out a new empty function app from VS Code and Core Tools? It would be great to see where the .vscode folder lives and whether files like dev-requirements.txt should me there. @fiveisprime I agree that we should implement this in Core Tools first. Will need to consider what happens if someone runs A longer term question to think about is should we consider an alternate structure for all languages? For instance we can ask if they want tests and if yes, we’ll generate nested folders for their language (probably an empty tests folder makes sense here). We can experiment with the Python experience first. |
I think fixing this issue should be top priority in terms of getting a better file structure for all languages: Azure/azure-functions-host#5373 My main concern with adding tests is the complexity. For example, the hello-world projects for VS Code extensions include tests by default and overall I'm a fan, but there's been several cases where the dev dependencies needed for those tests lead to npm security alerts which is not what you want from a clean new project IMO. There's also a lot of different ways to run tests so I wouldn't want us to be too opinionated. Finally, I really dislike the name |
@anthonychu https://github.com/microsoft/pvscbot is the layout. Just stick a |
Based on layout suggested by Brett in https://github.com/microsoft/pvscbot I am able to get this layout below working, sort of. I ended up here because I wanted to create two HttpTrigger functions that use some shared function/code and had some pytests. The existing example layouts did not quite work.
The test is as follows:
I am able to publish these functions to production, from terminal, with: When using VS-Code I am unable to use the F5 (or Ctrl+F5) to run the functions. If I run the following If you can advise me what I need to do the get that working in VS-Code please do so.
|
All the functions related files (host.json, local.settings.json, .funcignore, etc) should be in the Everything else looks good. In the VS Code tasks.json and settings.json you need to configure the folders correctly. It's working for me here: https://github.com/anthonychu/functions-python-durable-image-classifier |
@anthonychu Thanks for the tips. I also needed to update my settings.json Changed
and tasks.json need to ensure that the current working directory was specified for each of the tasks with
|
@rnwolf I noticed in your list of files you have "host.json" twice. We (the VS Code extension team) use that file to identify where the function app is so you might want to delete the extra one. On a separate note, "azureFunctions.pythonVenv" is supposed to automatically work without you guys having to change the path. Here's an issue to track fixing that: #2041 |
Thanks for the feedback @EricJizbaMSFT I will still need to see what happens if I use the repo. as a starter template, but I've learnt a lot in the process of getting this far. Hopefully I can now get down to the business of incorporating some of the other backend Azure services in the function application. |
Creating a new function project for Python in VS Code produces a flat folder structure. This doesn't match the recommended structure in docs.
Is there anyway we can apply that guidance to Python projects created via VS Code?
The text was updated successfully, but these errors were encountered: