astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
25.88k stars 755 forks source link

"uv --preview lock" does not read uv.toml or pyproject.toml settings #5022

Closed dsully closed 4 months ago

dsully commented 4 months ago

The uv --preview lock command does not find/respect settings in either a pyproject.toml or a uv.toml file, and thus resolution fails for internal Pypi repositories:

[pip]
extra-index-url = [
  "https://artifactory/artifactory/api/pypi/pypi-internal/simple",
  "https://artifactory/artifactory/api/pypi/pypi-external/simple",
]
index-url = "https://server/pypi/simple"

Or in pyproject.toml:

[tool.uv.pip]
extra-index-url = [
  "https://artifactory/artifactory/api/pypi/pypi-internal/simple",
  "https://artifactory/artifactory/api/pypi/pypi-external/simple",
]
index-url = "https://server/pypi/simple"
$ uv --preview lock --show-settings
...
LockSettings {
    python: None,
    refresh: None(
        Timestamp(
            SystemTime {
                tv_sec: 1720813419,
                tv_nsec: 61301000,
            },
        ),
    ),
    settings: ResolverSettings {
        index_locations: IndexLocations {
            index: None,
            extra_index: [],
            flat_index: [],
            no_index: false,
        },
        index_strategy: FirstIndex,
        keyring_provider: Disabled,
        resolution: Highest,
        prerelease: IfNecessaryOrExplicit,
        config_setting: ConfigSettings(
            {},
        ),
        exclude_newer: None,
        link_mode: Clone,
        upgrade: None,
        build_options: BuildOptions {
            no_binary: None,
            no_build: None,
        },
    },
}

Passing --index-url and --extra-index-url on the command line does work.

zanieb commented 4 months ago

Hi! We don't read the tool.uv.pip settings outside the uv pip CLI — instead use the top-level tool.uv options that correspond to their pip-specific counterparts.

dsully commented 4 months ago

That doesn't appear to work with pyproject.toml:

[tool.uv]     ■ Additional properties are not allowed ('extra-index-url', 'index-url' were unexpected)
extra-index-url =

And emits a schema validation error.

In uv.toml if I remove any section wrapper and just have the raw key/value assignments, that works, but emits the same schema validation error.

Will uv pip inherit these settings? Otherwise there will need to be duplication.

zanieb commented 4 months ago

Both of the following work for me?

[tool.uv]
index-url = "https://test.pypi.org/simple"
extra-index-url = ["https://test.pypi.org/simple"]

Are you on the latest version?

Yeah uv pip will inherit these settings. If you set them in [tool.uv.pip] that will take precedence over the top-level one.

dsully commented 4 months ago

Yes - uv 0.2.24 (527b711bc 2024-07-10)

I think I found the issue. If there is an empty or commented out uv.toml then the values in pyproject.toml won't be read.

There's also the need to update the schema JSON file as well.

charliermarsh commented 4 months ago

Do you mean, the JSON Schema on SchemaStore? Definitely need to update that.

We should probably warn if you have both a uv.toml and a pyproject.toml with a [tool.uv] table in the same directory.

dsully commented 4 months ago

Yes - the JSON Schema on SchemaStore.

charliermarsh commented 4 months ago

https://github.com/SchemaStore/schemastore/pull/3919

charliermarsh commented 4 months ago

I'll use this issue to track adding a warning.