astral-sh/uv · error · anyhow::Error

Failed to convert path to URL

Error message

Failed to convert path to URL

What it means

Error "Failed to convert path to URL" thrown in astral-sh/uv.

Source

Thrown at crates/uv-requirements/src/source_tree.rs:198

            anyhow::anyhow!(
                "The file `{}` appears to be a `pyproject.toml`, `setup.py`, or `setup.cfg` file, which must be in a directory",
                path.user_display()
            )
        })?;

        // If the path is a `pyproject.toml`, attempt to extract the requirements statically. The
        // distribution database will do this too, but we can be even more aggressive here since we
        // _only_ need the requirements. So, for example, even if the version is dynamic, we can
        // still extract the requirements without performing a build, unlike in the database where
        // we typically construct a "complete" metadata object.
        if let Some(pyproject_toml) = source_tree.pyproject_toml() {
            if let Some(metadata) = self.database.requires_dist(path, pyproject_toml).await? {
                return Ok(metadata);
            }
        }

        let Ok(url) = Url::from_directory_path(path).map(DisplaySafeUrl::from_url) else {
            return Err(anyhow::anyhow!("Failed to convert path to URL"));
        };
        let source = SourceUrl::Directory(DirectorySourceUrl {
            url: &url,
            install_path: path,
            editable: None,
        });

        // Determine the hash policy. Since we don't have a package name, we perform a
        // manual match.
        let hashes = match self.hasher {
            HashStrategy::None => HashPolicy::None,
            HashStrategy::Generate(mode) => HashPolicy::Generate(*mode),
            HashStrategy::Verify(_) => HashPolicy::Generate(HashGeneration::All),
            HashStrategy::Require(_) => {
                return Err(anyhow::anyhow!(
                    "Hash-checking is not supported for local directories: {}",
                    path.user_display()
                ));

View on GitHub (pinned to f1a42680ff)

When it happens

Trigger: Thrown at crates/uv-requirements/src/source_tree.rs:198 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of astral-sh/uv@f1a42680ff (2026-08-16). Data as JSON: /api/errors/ed3468392c1515a6. Report an issue: GitHub.