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

[vscode installation] 1/n Python version validation #1262

Merged
merged 1 commit into from
Feb 21, 2024
Merged

Conversation

Ankush-lastmile
Copy link
Member

@Ankush-lastmile Ankush-lastmile commented Feb 20, 2024

[vscode installation] 1/n Python version validation

Add a helper method to validate the python interpreter version. Simply throws an error on a bad version. Notification dialog in diff on top.

Align's with Python AIConfig's version requirement of python3.10 and higher

Testplan

Select a python interpreter 3.9, which is less than aiconfig's requirement version of 3.10.

output.mp4

Stack created with Sapling. Best reviewed with ReviewStack.

vscode-extension/src/extension.ts Outdated Show resolved Hide resolved
vscode-extension/src/extension.ts Outdated Show resolved Hide resolved
vscode-extension/src/extension.ts Outdated Show resolved Hide resolved
* @returns A promise that resolves to a boolean indicating if the version is >= 3.10.
*/

export function isPythonVersionAtLeast310(pythonPath: string): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is ok to unblock but ideally if there's some way we can determine the required python version dynamically via pip or something that would be best

Copy link
Member Author

@Ankush-lastmile Ankush-lastmile Feb 21, 2024

Choose a reason for hiding this comment

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

what do you mean by dynamically?

also just noting that pip itself has versions, which is not the same as python's version

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, what I mean is our pyproject.toml defines requires-python = ">=3.10" and that shows up as metadata in pip. Ideally we could dynamically get that version in the code without having to hardcode it

export function isPythonVersionAtLeast310(pythonPath: string): boolean {
try {
// Use Python to check compatible version
const command = `${pythonPath} -c "import sys; print(sys.version_info >= (3, 10))"`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this command vs just doing --version check? IMO that would be cleaner so that we can do the comparison in code ourselves

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, we already should have that version from stdout above, right? I don't think we need to run any python here at all

Copy link
Member Author

@Ankush-lastmile Ankush-lastmile Feb 21, 2024

Choose a reason for hiding this comment

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

executing python --version returns a literal such as Python 3.11.7.

Felt like parsing this into a version number and then comparing added extra complexity than using python itself to validate version.

I can update if that would be easier to follow

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok. I guess there are some nuances with it as well (e.g. comparator of version numbers). I'm fine with keeping as-is using python to check

Copy link
Contributor

@rholinshead rholinshead left a comment

Choose a reason for hiding this comment

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

Can we just use the python version from stdout and compare it to a constant (with note to keep constant in sync with our aiconfig package and maybe a TODO to look into getting it dynamically from pip)

@rholinshead rholinshead self-requested a review February 21, 2024 23:18
@rholinshead
Copy link
Contributor

Ok, so let's keep the check logic as-is but please address the other comments:

  • prettier (newline, spacing)
  • remove stdout check in that else if not needed

On top of that, please update the comment to give more context on using python to check version (namely complexity of different version values and how they would need to be parsed and compared)

Copy link
Contributor

@rholinshead rholinshead left a comment

Choose a reason for hiding this comment

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

Accepting to unblock once latest comment is addressed

Add a helper method to validate the python interpreter version. Simply throws an error on a bad version. Notification dialog in diff on top.

Align's with Python AIConfig's version requirement of python3.10 and higher

## Testplan

Select a python interpreter 3.9, which is less than aiconfig's requirement version of 3.10.

https://github.com/lastmile-ai/aiconfig/assets/141073967/4cfcb153-50aa-40fb-9764-54e964d4b1b8
@Ankush-lastmile
Copy link
Member Author

Ankush-lastmile commented Feb 21, 2024

  • rebase
  • fixed formatting
  • updated comment to be clearer
  • removed stdout check (not needed)

Can revisit the hardcoded dependency of python 3.10 (see above)

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.

2 participants