uv icon indicating copy to clipboard operation
uv copied to clipboard

Make `python-install-mirror` configurable in single-file scripts

Open l1xnan opened this issue 8 months ago • 2 comments

Summary

Constrained by the network environment, I hope that the single-file script I distribute includes python-install-mirror configuration. In this way, when users execute the script, Python and its dependencies can be automatically installed without being restricted by the network, and the configuration can be completed. There is no need to specifically emphasize to the script users that they need to configure the UV_PYTHON_INSTALL_MIRROR environment variable, which will provide a smoother user experience.

# /// script
# requires-python = ">=3.10,<3.11"
# dependencies = [
#     "requests<3",
#     "rich",
# ]
# [[tool.uv.index]]
# url = "https://pypi.tuna.tsinghua.edu.cn/simple"

# [tool.uv]
# python-install-mirror = "https://<mirror-url>/indygreg/python-build-standalone/releases/download"
# ///
import requests

However, currently, the metadata of the single-file script and the command line uv run script.py --python-install-mirror="https://<python-install-mirror>" do not support the python-install-mirror configuration. I hope this configuration can be supported.

Example

No response

l1xnan avatar Mar 28 '25 03:03 l1xnan

We've previously considered this a user-setting, not a project or script setting. I would be surprised if I ran a script and it transparently fetched Python versions from a mirror.

zanieb avatar Apr 01 '25 19:04 zanieb

We've previously considered this a user-setting, not a project or script setting. I would be surprised if I ran a script and it transparently fetched Python versions from a mirror.

I agree that in the vast majority of cases, it is a user setting, and for most people, configuring it using environment variables is a better choice. My usage scenario is rather special. I need to share running scripts with people who are not familiar with programming in an environment with network limitations, and I hope to minimize the communication costs related to network issues. In addition, it can make the configurations in the single-file script as consistent as possible with the available configurations in pyproject.toml. If it is finally considered that it is better to only place it in the user settings, I am also very willing to accept that. In that case, I will specifically emphasize the configuration of the environment variables during the stage of guiding the installation of uv. Thank you for your explanation!

l1xnan avatar Apr 02 '25 01:04 l1xnan

We've previously considered this a user-setting, not a project or script setting. I would be surprised if I ran a script and it transparently fetched Python versions from a mirror.

I agree that in the vast majority of cases, it is a user setting, and for most people, configuring it using environment variables is a better choice. My usage scenario is rather special. I need to share running scripts with people who are not familiar with programming in an environment with network limitations, and I hope to minimize the communication costs related to network issues. In addition, it can make the configurations in the single-file script as consistent as possible with the available configurations in pyproject.toml. If it is finally considered that it is better to only place it in the user settings, I am also very willing to accept that. In that case, I will specifically emphasize the configuration of the environment variables during the stage of guiding the installation of uv. Thank you for your explanation!

Agree

fengzhao avatar Jul 31 '25 06:07 fengzhao