Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add parsed URL fields to Dist variants #3429

Merged
charliermarsh merged 7 commits into
mainfrom
konsti/add-parsed-information-to-dist
May 14, 2024
Merged

Add parsed URL fields to Dist variants #3429
charliermarsh merged 7 commits into
mainfrom
konsti/add-parsed-information-to-dist

Conversation

@konstin

@konstin konstin commented May 7, 2024

Copy link
Copy Markdown
Member

Avoid reparsing urls by storing the parsed parts across resolution on Dist.

Part 2 of #3408 and part of #3409

Closes #3408

@konstin konstin added the internal A refactor or improvement that is not user-facing label May 7, 2024
@konstin konstin marked this pull request as draft May 7, 2024 16:13
@konstin konstin force-pushed the konsti/add-parsed-url-to-pubgrub branch from 031e457 to 18ac8e9 Compare May 7, 2024 16:15
@konstin konstin force-pushed the konsti/add-parsed-information-to-dist branch from 1e35e0a to b6832d2 Compare May 7, 2024 16:15
@konstin konstin force-pushed the konsti/add-parsed-url-to-pubgrub branch from 18ac8e9 to d907037 Compare May 8, 2024 11:06
@konstin konstin force-pushed the konsti/add-parsed-information-to-dist branch from b6832d2 to 9b79279 Compare May 8, 2024 11:06
@konstin konstin force-pushed the konsti/add-parsed-url-to-pubgrub branch from a014c75 to 7a1d730 Compare May 8, 2024 13:09
@konstin konstin force-pushed the konsti/add-parsed-information-to-dist branch from 9b79279 to 4b85300 Compare May 8, 2024 13:09
@konstin konstin force-pushed the konsti/add-parsed-url-to-pubgrub branch from 7a1d730 to cd59a38 Compare May 8, 2024 13:10
@konstin konstin force-pushed the konsti/add-parsed-information-to-dist branch from 4b85300 to 136f6b5 Compare May 8, 2024 13:11
@konstin konstin changed the title Store parsed url fields in Dist variants Add parsed url fields to Dist variants May 8, 2024
@konstin konstin force-pushed the konsti/add-parsed-information-to-dist branch from 136f6b5 to 669ace4 Compare May 8, 2024 13:41
@konstin konstin marked this pull request as ready for review May 8, 2024 13:41
Comment thread crates/distribution-types/src/lib.rs Outdated
/// The url without subdirectory fragment.
pub location: Url,
pub subdirectory: Option<PathBuf>,
/// The url with subdirectory fragment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention is to eventually remove the VerbatimUrl, leaving only given: String, for now we just eliminate the fallible re-parsing of urls

pub struct GitSourceDist {
pub name: PackageName,
/// The url without revision and subdirectory fragment.
pub git: Box<GitUrl>,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without boxing, this would increase the size of the entire Dist

// At time of writing, Unix is at 240, Windows is at 248.
assert!(
std::mem::size_of::<Dist>() <= 248,
std::mem::size_of::<Dist>() <= 336,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a branch boxing the entire Dist struct, but it didn't help with the windows debug stack overflows.

Comment thread crates/uv-dev/src/wheel_metadata.rs Outdated
)?;

let ParsedUrl::Archive(archive) = ParsedUrl::try_from(args.url.to_url())? else {
bail!("Only https is supported");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the dev script

path: _,
path,
url,
// TODO(konsti): Figure out why we lose the editable here (does it matter?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was introduced with cf30932#diff-49326157b193e4affae1b7a1c56c7c7e1ea2039168e33948b6c30a4fe7f4ef9eR76, where the Dist::from_url dropped the information. Is there an argument that the lookahead should or shouldn't consider editables?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's because we currently assume editables can't be transitive deps.

@konstin konstin force-pushed the konsti/add-parsed-url-to-pubgrub branch from 54fd266 to 9e653c3 Compare May 8, 2024 18:13
@konstin konstin force-pushed the konsti/add-parsed-information-to-dist branch from 669ace4 to 33dbaa2 Compare May 8, 2024 18:13
@konstin konstin force-pushed the konsti/add-parsed-url-to-pubgrub branch from 8cd479e to 8de4b2d Compare May 9, 2024 19:50
@konstin konstin force-pushed the konsti/add-parsed-information-to-dist branch from 33dbaa2 to 49ea7cd Compare May 9, 2024 19:53
Base automatically changed from konsti/add-parsed-url-to-pubgrub to main May 14, 2024 00:55
@charliermarsh charliermarsh changed the title Add parsed url fields to Dist variants Add parsed URL fields to Dist variants May 14, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) May 14, 2024 01:15
@charliermarsh charliermarsh merged commit c22c7ca into main May 14, 2024
@charliermarsh charliermarsh deleted the konsti/add-parsed-information-to-dist branch May 14, 2024 01:23
konstin added a commit that referenced this pull request Feb 14, 2025
Initially, we were limiting Git schemes to HTTPS and SSH as only supported schemes. We lost this validation in #3429. This incidentally allow file schemes, which apparently work with Git out of the box.

A caveat for this is that in `tool.uv.sources`, we parse the `git` field always as URL. This caused a problem with #11425: `repo = { git = 'c:\path\to\repo', rev = "xxxxx" }` was parsed as a URL where `c:` is the scheme, causing a bad error message down the line.

This PR:
* Puts Git URL validation back in place
* Allows `file:` URL in Git: This seems to be supported by Git and we were supporting it albeit unintentionally, so it's reasonable to continue to support it.
* It does _not_ allow relative paths in the `git` field in `tool.uv.sources`. Absolute file URLs are supported, whether we want relative file URLs for Git too should be discussed separately.

Closes #3429: We reject the input with a proper error message, while hinting the user towards `file:`. If there's still desire for a relative path, we can reopen.
konstin added a commit that referenced this pull request Feb 14, 2025
Initially, we were limiting Git schemes to HTTPS and SSH as only supported schemes. We lost this validation in #3429. This incidentally allow file schemes, which apparently work with Git out of the box.

A caveat for this is that in `tool.uv.sources`, we parse the `git` field always as URL. This caused a problem with #11425: `repo = { git = 'c:\path\to\repo', rev = "xxxxx" }` was parsed as a URL where `c:` is the scheme, causing a bad error message down the line.

This PR:
* Puts Git URL validation back in place
* Allows `file:` URL in Git: This seems to be supported by Git and we were supporting it albeit unintentionally, so it's reasonable to continue to support it.
* It does _not_ allow relative paths in the `git` field in `tool.uv.sources`. Absolute file URLs are supported, whether we want relative file URLs for Git too should be discussed separately.

Closes #3429: We reject the input with a proper error message, while hinting the user towards `file:`. If there's still desire for a relative path, we can reopen.
konstin added a commit that referenced this pull request Feb 14, 2025
Initially, we were limiting Git schemes to HTTPS and SSH as only supported schemes. We lost this validation in #3429. This incidentally allow file schemes, which apparently work with Git out of the box.

A caveat for this is that in `tool.uv.sources`, we parse the `git` field always as URL. This caused a problem with #11425: `repo = { git = 'c:\path\to\repo', rev = "xxxxx" }` was parsed as a URL where `c:` is the scheme, causing a bad error message down the line.

This PR:
* Puts Git URL validation back in place
* Allows `file:` URL in Git: This seems to be supported by Git and we were supporting it albeit unintentionally, so it's reasonable to continue to support it.
* It does _not_ allow relative paths in the `git` field in `tool.uv.sources`. Absolute file URLs are supported, whether we want relative file URLs for Git too should be discussed separately.

Closes #3429: We reject the input with a proper error message, while hinting the user towards `file:`. If there's still desire for a relative path, we can reopen.
konstin added a commit that referenced this pull request Feb 17, 2025
Initially, we were limiting Git schemes to HTTPS and SSH as only supported schemes. We lost this validation in #3429. This incidentally allow file schemes, which apparently work with Git out of the box.

A caveat for this is that in `tool.uv.sources`, we parse the `git` field always as URL. This caused a problem with #11425: `repo = { git = 'c:\path\to\repo', rev = "xxxxx" }` was parsed as a URL where `c:` is the scheme, causing a bad error message down the line.

This PR:
* Puts Git URL validation back in place
* Allows `file:` URL in Git: This seems to be supported by Git and we were supporting it albeit unintentionally, so it's reasonable to continue to support it.
* It does _not_ allow relative paths in the `git` field in `tool.uv.sources`. Absolute file URLs are supported, whether we want relative file URLs for Git too should be discussed separately.

Closes #3429: We reject the input with a proper error message, while hinting the user towards `file:`. If there's still desire for a relative path, we can reopen.
konstin added a commit that referenced this pull request Feb 17, 2025
Initially, we were limiting Git schemes to HTTPS and SSH as only supported schemes. We lost this validation in #3429. This incidentally allow file schemes, which apparently work with Git out of the box.

A caveat for this is that in `tool.uv.sources`, we parse the `git` field always as URL. This caused a problem with #11425: `repo = { git = 'c:\path\to\repo', rev = "xxxxx" }` was parsed as a URL where `c:` is the scheme, causing a bad error message down the line.

This PR:
* Puts Git URL validation back in place
* Allows `file:` URL in Git: This seems to be supported by Git and we were supporting it albeit unintentionally, so it's reasonable to continue to support it.
* It does _not_ allow relative paths in the `git` field in `tool.uv.sources`. Absolute file URLs are supported, whether we want relative file URLs for Git too should be discussed separately.

Closes #3429: We reject the input with a proper error message, while hinting the user towards `file:`. If there's still desire for a relative path, we can reopen.
charliermarsh added a commit that referenced this pull request Feb 18, 2025
Initially, we were limiting Git schemes to HTTPS and SSH as only
supported schemes. We lost this validation in #3429. This incidentally
allowed file schemes, which apparently work with Git out of the box.

A caveat for this is that in tool.uv.sources, we parse the git field
always as URL. This caused a problem with #11425: repo = { git =
'c:\path\to\repo', rev = "xxxxx" } was parsed as a URL where c: is the
scheme, causing a bad error message down the line.

This PR:

* Puts Git URL validation back in place. It bans everything but HTTPS,
SSH, and file URLs. This could be a breaking change, if users were using
a git transport protocol were not aware of, even though never
intentionally supported.
* Allows file: URL in Git: This seems to be supported by Git and we were
supporting it albeit unintentionally, so it's reasonable to continue to
support it.
* It does not allow relative paths in the git field in tool.uv.sources.
Absolute file URLs are supported, whether we want relative file URLs for
Git too should be discussed separately.

Closes #3429: We reject the input with a proper error message, while
hinting the user towards file:. If there's still desire for relative
path support, we can keep it open.

---------

Co-authored-by: Charlie Marsh <[email protected]>
loic-lescoat pushed a commit to loic-lescoat/uv that referenced this pull request Mar 2, 2025
Initially, we were limiting Git schemes to HTTPS and SSH as only
supported schemes. We lost this validation in astral-sh#3429. This incidentally
allowed file schemes, which apparently work with Git out of the box.

A caveat for this is that in tool.uv.sources, we parse the git field
always as URL. This caused a problem with astral-sh#11425: repo = { git =
'c:\path\to\repo', rev = "xxxxx" } was parsed as a URL where c: is the
scheme, causing a bad error message down the line.

This PR:

* Puts Git URL validation back in place. It bans everything but HTTPS,
SSH, and file URLs. This could be a breaking change, if users were using
a git transport protocol were not aware of, even though never
intentionally supported.
* Allows file: URL in Git: This seems to be supported by Git and we were
supporting it albeit unintentionally, so it's reasonable to continue to
support it.
* It does not allow relative paths in the git field in tool.uv.sources.
Absolute file URLs are supported, whether we want relative file URLs for
Git too should be discussed separately.

Closes astral-sh#3429: We reject the input with a proper error message, while
hinting the user towards file:. If there's still desire for relative
path support, we can keep it open.

---------

Co-authored-by: Charlie Marsh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user-facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve url parsing from Requirement parsing to Dist

2 participants