4 ms·
uv add --script wordlookup.py httpx # /// script # requires-python = ">=3.13" # dependencies = [ # "httpx", # ] # /// import httpx That seems pretty redu
by singularity2001 2y ago
uv add --script wordlookup.py httpx
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "httpx",
# ]
# ///
import httpx
That seems pretty redundant. Why can't UV just infer the dependencies from the import statements?
- csunbird 2y agowhich version of httpx?
- singularity2001 2y agosame as in dependencies = [ # "httpx", # ] the current one by default
- chippiewill 2y agoThere's a few things: - uv won't necessarily know which modules aren't already present, because they can load from modules being developed in the current directory - It's not easy to determine what imports will happen in a Python script due to transitive dependencies and dynamic loading - The names of python modules are not always the same as the packages that contain them - for example the yaml module comes from the pyyaml package Also the second line of the Zen of Python is "explicit is better than implicit": https://peps.python.org/pep-0020/ https://peps.python.org/pep-0020/
- singularity2001 2y ago- It's not easy to determine what imports will happen fair enough, but adding option to auto import from the main file would solve 97% of use cases - uv won't necessarily know which modules aren't already present easy to check - The names of python modules are not always the same great opportunity to add convenient simple mapping / name resolution - Zen Should DRY don't repeat yourself be higher up?
- sorenjan 2y agoThis is covered in the Pep 723 document, it's not a uv invention. https://peps.python.org/pep-0723/#why-not-infer-the-requirements-from-import-statements https://peps.python.org/pep-0723/#why-not-infer-the-requirem...
- deleted 2y ago[deleted]