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 PEP 723 when detecting python interpreter & virtualenv #24916

Open
NorthIsUp opened this issue Mar 18, 2025 · 1 comment
Open

Support PEP 723 when detecting python interpreter & virtualenv #24916

NorthIsUp opened this issue Mar 18, 2025 · 1 comment
Labels
feature-request Request for new features or functionality needs proposal Need to make some design decisions

Comments

@NorthIsUp
Copy link

https://peps.python.org/pep-0723/

Python has adopted a format for putting dependencies into a script header and python tooling has implemented ways to run it!

here is an example of uv being used to run a script. It will parse the /// script header, use the specified version of python, create a virtual environment, install dependencies, and then execute the script.

#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = [
#   "requests", "pydantic",
# ]
# ///
# (note, this is tested on macOS, I don't know if env -S works on gnu systems)

import requests

print(requests.get("example.org"))

right now vscode-python doesn't really know how to handle several aspects of this.

first is language detection. scripts often don't have a file extension so it would be nice to detect uv or pipx in the shabang line to mean "probably python". you could also do more advanced parsing of the entire /// script block.

next is code intelligence, without pythonInterpreter detection there are red squiggles everywhere. when run scripts get their own venv created in a temp location, unfortunately this behavior is tool specific. maybe vscode could create/manage its own!

thanks!

@NorthIsUp NorthIsUp added the feature-request Request for new features or functionality label Mar 18, 2025
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Mar 18, 2025
@karthiknadig karthiknadig added needs proposal Need to make some design decisions and removed triage-needed Needs assignment to the proper sub-team labels Mar 19, 2025
@karthiknadig
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality needs proposal Need to make some design decisions
Projects
None yet
Development

No branches or pull requests

2 participants