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

Version check crashes with ValueError: invalid literal for int() with base 10: '0a0' for ipykernel 7.0.0a0 #827

Open
pllim opened this issue Oct 22, 2024 · 5 comments

Comments

@pllim
Copy link
Collaborator

pllim commented Oct 22, 2024

This line broke when pre-release is available (e.g., ipykernel==7.0.0a0):

ipykernel_version = tuple(map(int, ipykernel.__version__.split(".")))

>   ipykernel_version = tuple(map(int, ipykernel.__version__.split(".")))
E   ValueError: invalid literal for int() with base 10: '0a0'

If you switch to, say, packaging.version.Version check and take account of pre- or dev releases, then it would guard against such breakage.

Thanks.

@maartenbreddels
Copy link
Contributor

Thanks, I didn't realize that was not a good pattern. I refrained from using any Python tooling because it was never clear to me what the best solution is. packaging seems to be a very large package that does more than providing packages.

importlib.metadata now seems to be the standard way (says chatgpt), but that is Python >= 3.8.

I do think we can make this more robust, thanks for the issue!

@pllim
Copy link
Collaborator Author

pllim commented Oct 22, 2024

packaging or not, as long as you try to go for the officially supported pattern at https://peps.python.org/pep-0440/ , you should be good on the Python side.

@paddymul
Copy link

paddymul commented Oct 22, 2024

FWIW, packaging isn't available in jupyterlite xeus (maybe pyodide too).

My bug about this jupyterlite/pyodide-kernel#140

@pllim
Copy link
Collaborator Author

pllim commented Nov 11, 2024

Anyways, can you please fix this. I really don't care if you use packaging or not, so I will modify the title. Thanks!

@pllim pllim changed the title Use packaging.version for package version checks Version check crashes with ValueError: invalid literal for int() with base 10: '0a0' for ipykernel 7.0.0a0 Nov 11, 2024
@kecnry
Copy link
Collaborator

kecnry commented Nov 11, 2024

Maybe this can be as easy as ipykernel_version = tuple(map(int, re.split(r'\D+', ipykernel.__version__)[:3]))?

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

No branches or pull requests

4 participants