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

Question about reducing code duplication in [tool.uv.sources] #8415

Open
zmeir opened this issue Oct 21, 2024 · 1 comment
Open

Question about reducing code duplication in [tool.uv.sources] #8415

zmeir opened this issue Oct 21, 2024 · 1 comment
Labels
enhancement New feature or request wish Not on the immediate roadmap

Comments

@zmeir
Copy link

zmeir commented Oct 21, 2024

I'll start by saying this is probably not a very common use-case, but I wanted to ask this in case there is some better way of doing what I'm doing that I couldn't find in the documentation.

I have a project with some internal packages as dependencies. These packages are published to a private index, which is then mirrored to 2 different locations. One of these locations is on the same network segment as our development environments, so for development purposes is it faster to download packages from this index. The second one is faster for our ci/automation/production environments. I can differentiate between the environments with the sys_platform marker (we develop on mac and windows, but deploy on linux).

I thought about setting up the [tool.uv.sources] table in pyproject.toml like this:

[tool.uv.sources]
internal-package-1 = [
    { index = "private-index-dev", marker = "sys_platform == 'darwin' or sys_platform == 'win32'" },
    { index = "private-index-prd", marker = "sys_platform != 'darwin' and sys_platform != 'win32'" },
]
internal-package-2 = [
    { index = "private-index-dev", marker = "sys_platform == 'darwin' or sys_platform == 'win32'" },
    { index = "private-index-prd", marker = "sys_platform != 'darwin' and sys_platform != 'win32'" },
]
internal-package-3 = [
    { index = "private-index-dev", marker = "sys_platform == 'darwin' or sys_platform == 'win32'" },
    { index = "private-index-prd", marker = "sys_platform != 'darwin' and sys_platform != 'win32'" },
]

The same 2 lines for private-index-dev and private-index-prd are repeated for each internal package.

Is there any way to prevent this duplication?

As far as I know TOML doesn't support variable substitution, so I can't do something like this:

[tool.uv.sources]
internal-package-settings = [
    { index = "private-index-dev", marker = "sys_platform == 'darwin' or sys_platform == 'win32'" },
    { index = "private-index-prd", marker = "sys_platform != 'darwin' and sys_platform != 'win32'" },
]
internal-package-1 = {internal-package-settings}
internal-package-2 = {internal-package-settings}
internal-package-3 = {internal-package-settings}
@zanieb
Copy link
Member

zanieb commented Oct 21, 2024

Interesting. Thanks for sharing. I guess we could add something like [tool.uv.source-definitions] then allow tool.uv.sources.<package> = { definition = ... }

It certainly adds some complexity though, so I'm hesitant to pursue it without more requests.

@zanieb zanieb added enhancement New feature or request wish Not on the immediate roadmap labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wish Not on the immediate roadmap
Projects
None yet
Development

No branches or pull requests

2 participants