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

Support for new Python language model #3235

Merged
merged 52 commits into from Aug 19, 2022
Merged

Conversation

philliphoff
Copy link
Contributor

Adds support for the new Python language model, where bindings are attributes within the application code rather than in separate JSON files.

package-lock.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
{ label: ProjectLanguage.Python },
{ label: ProjectLanguage.TypeScript },
{ label: ProjectLanguage.Custom }
const languagePicks: IAzureQuickPickItem<{ language: ProjectLanguage, model?: number }>[] = [
Copy link
Contributor

Choose a reason for hiding this comment

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

This { language: ProjectLanguage, model?: number } "type" is used in a couple places; it might benefit from a proper type definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about, if I see it in one more place, I promise to do so. :-)

src/commands/createNewProject/NewProjectLanguageStep.ts Outdated Show resolved Hide resolved
src/commands/createFunction/FunctionListStep.ts Outdated Show resolved Hide resolved
@philliphoff philliphoff marked this pull request as ready for review August 18, 2022 16:39
@philliphoff philliphoff requested a review from a team as a code owner August 18, 2022 16:39
@alexweininger
Copy link
Member

I like the auto open markdown feature, really cool (and tricky to implement IIRC) that it grabs the markdown file from the template and displays it rendered.

I wish we could do something similar with walkthroughs, ex: spawn a walkthrough from a markdown file, or maybe a special walkthrough.json file. Could be really useful for templates, samples, etc.

@alexweininger
Copy link
Member

When I append a new function to a file, it's not smart about making sure the new function name is unique. Sounds like it's out of scope for the time being. But something we might revisit later.

@philliphoff
Copy link
Contributor Author

When I append a new function to a file, it's not smart about making sure the new function name is unique. Sounds like it's out of scope for the time being. But something we might revisit later.

Yes, it is exactly things of that sort that require a robust language service in order to solve, but which take time we didn't think we had for this initial preview. Even then it's likely to result in a long tail of possible code structure to try to cover.

@philliphoff
Copy link
Contributor Author

I like the auto open markdown feature, really cool (and tricky to implement IIRC) that it grabs the markdown file from the template and displays it rendered.

It's admittedly a hack (in particular, to support VS Code's need to reopen the document on a new file) to avoid having to manage a local disk cache), but I think it will work well enough for most cases.

Copy link
Member

@nturinski nturinski left a comment

Choose a reason for hiding this comment

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

There is no way to pass an argument to change the default trigger names right now since everything is static content in the backupTemplates, right?

I was surprised by the lack of prompt steps, but I'm assuming when the template feed is actually serving the templates, that there will be a way to pass in parameters for starting names and other properties similar to the other templates?

NOTE: I left a comment in the templates.json but it might be annoying to view due to the size of that file so I'll leave it here as well:

Alex mentioned that the host.json can't contain the extensionBundle property in order to debug (and you have denoted as such in the code.) I noticed that all the templates have host.jsons that include it by default, so whenever you create a new trigger, it automatically updates the host.json to include the property again.

src/debug/validatePreDebug.ts Outdated Show resolved Hide resolved
src/templates/script/PysteinTemplateProvider.ts Outdated Show resolved Hide resolved
src/templates/script/parseScriptTemplates.ts Show resolved Hide resolved

export class PythonScriptStep extends AzureWizardPromptStep<IPythonFunctionWizardContext> {
public async prompt(wizardContext: IPythonFunctionWizardContext): Promise<void> {
const entries = await vscode.workspace.fs.readDirectory(vscode.Uri.file(wizardContext.projectPath));
Copy link
Member

Choose a reason for hiding this comment

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

AzExtFsExtra does have a readDirectory() command though the return types are a little bit different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, though I'd prefer to use the VS Code APIs when available (and reasonably convenient). If anything, it makes it easier for the extension to support their new remote host/filesystem scenarios. (Yes, there are lots of other things that wouldn't work for Functions in those scenarios, but still...)

Copy link
Member

Choose a reason for hiding this comment

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

Well, under the hood, AzExtFsExtra is using all VS Code APIs which was the whole point of this PR.

https://github.com/microsoft/vscode-azuretools/blob/main/utils/src/utils/AzExtFsExtra.ts#L94-L100

It just offers some QOL, like not having to wrap projectPath with vscode.Uri.file(), but definitely not a ship blocker or anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, ok, I see, then forget everything I said! For some reason I thought AzExtFsExtra was still using fs under the hood. :-) Eh, in this particular case I find direct use of the VS Code API easier to read than using the wrapper. I could go either way.

nturinski
nturinski previously approved these changes Aug 19, 2022
Copy link
Member

@nturinski nturinski left a comment

Choose a reason for hiding this comment

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

I'm good to approve this. I kind of want to merge this sooner so we can start to get CTI doing test passes on it, but I'd understand wanting to wait for Brandon to rise from the dead to give it a thorough review. 🧟

@philliphoff
Copy link
Contributor Author

There is no way to pass an argument to change the default trigger names right now since everything is static content in the backupTemplates, right?

I was surprised by the lack of prompt steps, but I'm assuming when the template feed is actually serving the templates, that there will be a way to pass in parameters for starting names and other properties similar to the other templates?

@nturinski Agreed that this initial preview is limited in scope with respect to customization of the template (i.e. there effectively is none). To do it properly requires more than just token replacement in the added function source, as there may be other changes needed elsewhere (e.g. new imports, validation against existing function names, etc., and, in particular, when they introduce PyStein's "blueprints"). We really need a robust language service that allows source manipulation a la Roslyn, and I'm not sure we have that now (and our time frame didn't really allow it in any case). This is one reason we're trying to lean on the "inline" documentation in the function templates, to help users understand what needs to change in order to add new functions.

@@ -19,6 +20,16 @@ import { showMarkdownPreviewFile } from '../../../utils/textUtils';

const gettingStartedFileName = 'getting_started.md';

async function fileExists(uri: vscode.Uri): Promise<boolean> {
Copy link
Member

Choose a reason for hiding this comment

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

You could use this to save some lines, though I will go back and add a fileExists utility function later.

Copy link
Member

Choose a reason for hiding this comment

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

You would also not have to wrap the file paths with Uri.file() as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't stat() throw if the file doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, wait, never mind, I see what you mean now.

@philliphoff
Copy link
Contributor Author

I'm good to approve this. I kind of want to merge this sooner so we can start to get CTI doing test passes on it, but I'd understand wanting to wait for Brandon to rise from the dead to give it a thorough review. 🧟

Agree that I'd like CTI taking a look and making sure I didn't horribly break the existing scenarios. @bwateratmsft did an early review of the draft PR, but I'm happy for him to tear it apart further when he's back next week (and I'm out). I can then clean up when I get back.

@philliphoff philliphoff merged commit 925796c into main Aug 19, 2022
@philliphoff philliphoff deleted the philliphoff-new-python-model branch August 19, 2022 20:54
@bwateratmsft
Copy link
Contributor

I took a brief look at the changes since my review and didn't see anything that concerned me. Agree, getting it in sooner than later is a good idea so CTI can take a look. Thanks!

@microsoft microsoft locked and limited conversation to collaborators Oct 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants