mirror of
				https://github.com/astral-sh/uv.git
				synced 2025-10-31 12:06:13 +00:00 
			
		
		
		
	Use nanoid instead of uuid (#1074)
## Summary Gives us equivalent randomness with ~half as many characters.
This commit is contained in:
		
							parent
							
								
									eebc2f340a
								
							
						
					
					
						commit
						63f3434b21
					
				
					 9 changed files with 32 additions and 33 deletions
				
			
		
							
								
								
									
										23
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										23
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							|  | @ -1831,6 +1831,15 @@ dependencies = [ | ||||||
|  "windows-sys 0.48.0", |  "windows-sys 0.48.0", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "nanoid" | ||||||
|  | version = "0.4.0" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "3ffa00dec017b5b1a8b7cf5e2c008bfda1aa7e0697ac1508b491fdf2622fb4d8" | ||||||
|  | dependencies = [ | ||||||
|  |  "rand", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "normalize-line-endings" | name = "normalize-line-endings" | ||||||
| version = "0.3.0" | version = "0.3.0" | ||||||
|  | @ -2358,6 +2367,7 @@ dependencies = [ | ||||||
|  "directories", |  "directories", | ||||||
|  "distribution-types", |  "distribution-types", | ||||||
|  "fs-err", |  "fs-err", | ||||||
|  |  "nanoid", | ||||||
|  "puffin-fs", |  "puffin-fs", | ||||||
|  "puffin-normalize", |  "puffin-normalize", | ||||||
|  "pypi-types", |  "pypi-types", | ||||||
|  | @ -2365,7 +2375,6 @@ dependencies = [ | ||||||
|  "tempfile", |  "tempfile", | ||||||
|  "tracing", |  "tracing", | ||||||
|  "url", |  "url", | ||||||
|  "uuid", |  | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| [[package]] | [[package]] | ||||||
|  | @ -2495,6 +2504,7 @@ dependencies = [ | ||||||
|  "fs-err", |  "fs-err", | ||||||
|  "futures", |  "futures", | ||||||
|  "install-wheel-rs", |  "install-wheel-rs", | ||||||
|  |  "nanoid", | ||||||
|  "pep440_rs 0.3.12", |  "pep440_rs 0.3.12", | ||||||
|  "pep508_rs", |  "pep508_rs", | ||||||
|  "platform-tags", |  "platform-tags", | ||||||
|  | @ -2516,7 +2526,6 @@ dependencies = [ | ||||||
|  "tokio-util", |  "tokio-util", | ||||||
|  "tracing", |  "tracing", | ||||||
|  "url", |  "url", | ||||||
|  "uuid", |  | ||||||
|  "zip", |  "zip", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | @ -4010,16 +4019,6 @@ version = "0.2.1" | ||||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
| checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" | checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" | ||||||
| 
 | 
 | ||||||
| [[package]] |  | ||||||
| name = "uuid" |  | ||||||
| version = "1.7.0" |  | ||||||
| source = "registry+https://github.com/rust-lang/crates.io-index" |  | ||||||
| checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" |  | ||||||
| dependencies = [ |  | ||||||
|  "getrandom", |  | ||||||
|  "serde", |  | ||||||
| ] |  | ||||||
| 
 |  | ||||||
| [[package]] | [[package]] | ||||||
| name = "valuable" | name = "valuable" | ||||||
| version = "0.1.0" | version = "0.1.0" | ||||||
|  |  | ||||||
|  | @ -49,6 +49,7 @@ itertools = { version = "0.12.0" } | ||||||
| mailparse = { version = "0.14.0" } | mailparse = { version = "0.14.0" } | ||||||
| # For additional textwrap options: https://github.com/zkat/miette/pull/321, https://github.com/zkat/miette/pull/328 | # For additional textwrap options: https://github.com/zkat/miette/pull/321, https://github.com/zkat/miette/pull/328 | ||||||
| miette =  { git = "https://github.com/zkat/miette.git", rev = "b0744462adbbfbb6d845f382db36be883c7f3c45" } | miette =  { git = "https://github.com/zkat/miette.git", rev = "b0744462adbbfbb6d845f382db36be883c7f3c45" } | ||||||
|  | nanoid = { version = "0.4.0" } | ||||||
| once_cell = { version = "1.19.0" } | once_cell = { version = "1.19.0" } | ||||||
| owo-colors = { version = "3.5.0" } | owo-colors = { version = "3.5.0" } | ||||||
| petgraph = { version = "0.6.4" } | petgraph = { version = "0.6.4" } | ||||||
|  |  | ||||||
|  | @ -24,8 +24,8 @@ cachedir = { workspace = true } | ||||||
| clap = { workspace = true, features = ["derive"], optional = true } | clap = { workspace = true, features = ["derive"], optional = true } | ||||||
| directories = { workspace = true } | directories = { workspace = true } | ||||||
| fs-err = { workspace = true, features = ["tokio"] } | fs-err = { workspace = true, features = ["tokio"] } | ||||||
|  | nanoid = { workspace = true } | ||||||
| serde = { workspace = true, features = ["derive"] } | serde = { workspace = true, features = ["derive"] } | ||||||
| tempfile = { workspace = true } | tempfile = { workspace = true } | ||||||
| tracing = { workspace = true } | tracing = { workspace = true } | ||||||
| url = { workspace = true } | url = { workspace = true } | ||||||
| uuid = { workspace = true , default-features = false, features = ["v4"] } |  | ||||||
|  |  | ||||||
|  | @ -195,10 +195,10 @@ impl Cache { | ||||||
|     pub fn persist(&self, temp_dir: impl AsRef<Path>, path: impl AsRef<Path>) -> io::Result<()> { |     pub fn persist(&self, temp_dir: impl AsRef<Path>, path: impl AsRef<Path>) -> io::Result<()> { | ||||||
|         // Create a unique ID for the artifact.
 |         // Create a unique ID for the artifact.
 | ||||||
|         // TODO(charlie): Support content-addressed persistence via SHAs.
 |         // TODO(charlie): Support content-addressed persistence via SHAs.
 | ||||||
|         let id = uuid::Uuid::new_v4(); |         let id = nanoid::nanoid!(); | ||||||
| 
 | 
 | ||||||
|         // Move the temporary directory into the directory store.
 |         // Move the temporary directory into the directory store.
 | ||||||
|         let archive_entry = self.entry(CacheBucket::Archive, "", id.to_string()); |         let archive_entry = self.entry(CacheBucket::Archive, "", id); | ||||||
|         fs_err::create_dir_all(archive_entry.dir())?; |         fs_err::create_dir_all(archive_entry.dir())?; | ||||||
|         fs_err::rename(temp_dir.as_ref(), archive_entry.path())?; |         fs_err::rename(temp_dir.as_ref(), archive_entry.path())?; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -33,6 +33,7 @@ anyhow = { workspace = true } | ||||||
| bytesize = { workspace = true } | bytesize = { workspace = true } | ||||||
| fs-err = { workspace = true } | fs-err = { workspace = true } | ||||||
| futures = { workspace = true } | futures = { workspace = true } | ||||||
|  | nanoid = { workspace = true } | ||||||
| reqwest = { workspace = true } | reqwest = { workspace = true } | ||||||
| rmp-serde = { workspace = true } | rmp-serde = { workspace = true } | ||||||
| rustc-hash = { workspace = true } | rustc-hash = { workspace = true } | ||||||
|  | @ -43,5 +44,4 @@ tokio = { workspace = true } | ||||||
| tokio-util = { workspace = true, features = ["compat"] } | tokio-util = { workspace = true, features = ["compat"] } | ||||||
| tracing = { workspace = true } | tracing = { workspace = true } | ||||||
| url = { workspace = true } | url = { workspace = true } | ||||||
| uuid = { workspace = true, default-features = false, features = ["v4", "serde"] } |  | ||||||
| zip = { workspace = true } | zip = { workspace = true } | ||||||
|  |  | ||||||
|  | @ -35,7 +35,7 @@ impl BuiltWheelIndex { | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         Ok(Self::find( |         Ok(Self::find( | ||||||
|             &cache_shard.shard(manifest.digest()), |             &cache_shard.shard(manifest.id()), | ||||||
|             source_dist.name(), |             source_dist.name(), | ||||||
|             cache, |             cache, | ||||||
|             tags, |             tags, | ||||||
|  | @ -66,7 +66,7 @@ impl BuiltWheelIndex { | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         Ok(Self::find( |         Ok(Self::find( | ||||||
|             &cache_shard.shard(manifest.digest()), |             &cache_shard.shard(manifest.id()), | ||||||
|             source_dist.name(), |             source_dist.name(), | ||||||
|             cache, |             cache, | ||||||
|             tags, |             tags, | ||||||
|  |  | ||||||
|  | @ -110,7 +110,7 @@ impl<'a> RegistryWheelIndex<'a> { | ||||||
|                 let manifest_entry = cache_shard.entry(MANIFEST); |                 let manifest_entry = cache_shard.entry(MANIFEST); | ||||||
|                 if let Ok(Some(manifest)) = read_http_manifest(&manifest_entry) { |                 if let Ok(Some(manifest)) = read_http_manifest(&manifest_entry) { | ||||||
|                     Self::add_directory( |                     Self::add_directory( | ||||||
|                         cache_shard.join(manifest.digest()), |                         cache_shard.join(manifest.id()), | ||||||
|                         package, |                         package, | ||||||
|                         cache, |                         cache, | ||||||
|                         tags, |                         tags, | ||||||
|  |  | ||||||
|  | @ -1,18 +1,17 @@ | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
| /// The [`Manifest`] is a thin wrapper around a unique identifier for the source distribution.
 | /// The [`Manifest`] is a thin wrapper around a unique identifier for the source distribution.
 | ||||||
| #[derive(Debug, Copy, Clone, Serialize, Deserialize)] | #[derive(Debug, Clone, Serialize, Deserialize)] | ||||||
| pub(crate) struct Manifest(uuid::Uuid); | pub(crate) struct Manifest(String); | ||||||
| 
 | 
 | ||||||
| impl Manifest { | impl Manifest { | ||||||
|     /// Initialize a new [`Manifest`] with a random UUID.
 |     /// Initialize a new [`Manifest`] with a random UUID.
 | ||||||
|     pub(crate) fn new() -> Self { |     pub(crate) fn new() -> Self { | ||||||
|         Self(uuid::Uuid::new_v4()) |         Self(nanoid::nanoid!()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Return the digest of the manifest. At present, the digest is the first 8 bytes of the
 |     /// Return the unique ID of the manifest.
 | ||||||
|     /// [`uuid::Uuid`] as a string.
 |     pub(crate) fn id(&self) -> &str { | ||||||
|     pub(crate) fn digest(&self) -> String { |         &self.0 | ||||||
|         self.0.to_string()[..8].to_string() |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -263,7 +263,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { | ||||||
| 
 | 
 | ||||||
|                 // Download the source distribution.
 |                 // Download the source distribution.
 | ||||||
|                 debug!("Downloading source distribution: {source_dist}"); |                 debug!("Downloading source distribution: {source_dist}"); | ||||||
|                 let source_dist_entry = cache_shard.shard(manifest.digest()).entry(filename); |                 let source_dist_entry = cache_shard.shard(manifest.id()).entry(filename); | ||||||
|                 self.persist_source_dist_url(response, source_dist, filename, &source_dist_entry) |                 self.persist_source_dist_url(response, source_dist, filename, &source_dist_entry) | ||||||
|                     .await?; |                     .await?; | ||||||
| 
 | 
 | ||||||
|  | @ -284,7 +284,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { | ||||||
|         // From here on, scope all operations to the current build. Within the manifest shard,
 |         // From here on, scope all operations to the current build. Within the manifest shard,
 | ||||||
|         // there's no need to check for freshness, since entries have to be fresher than the
 |         // there's no need to check for freshness, since entries have to be fresher than the
 | ||||||
|         // manifest itself.
 |         // manifest itself.
 | ||||||
|         let cache_shard = cache_shard.shard(manifest.digest()); |         let cache_shard = cache_shard.shard(manifest.id()); | ||||||
| 
 | 
 | ||||||
|         // If the cache contains a compatible wheel, return it.
 |         // If the cache contains a compatible wheel, return it.
 | ||||||
|         if let Some(built_wheel) = BuiltWheelMetadata::find_in_cache(self.tags, &cache_shard) { |         if let Some(built_wheel) = BuiltWheelMetadata::find_in_cache(self.tags, &cache_shard) { | ||||||
|  | @ -352,7 +352,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { | ||||||
| 
 | 
 | ||||||
|                 // Download the source distribution.
 |                 // Download the source distribution.
 | ||||||
|                 debug!("Downloading source distribution: {source_dist}"); |                 debug!("Downloading source distribution: {source_dist}"); | ||||||
|                 let source_dist_entry = cache_shard.shard(manifest.digest()).entry(filename); |                 let source_dist_entry = cache_shard.shard(manifest.id()).entry(filename); | ||||||
|                 self.persist_source_dist_url(response, source_dist, filename, &source_dist_entry) |                 self.persist_source_dist_url(response, source_dist, filename, &source_dist_entry) | ||||||
|                     .await?; |                     .await?; | ||||||
| 
 | 
 | ||||||
|  | @ -373,7 +373,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { | ||||||
|         // From here on, scope all operations to the current build. Within the manifest shard,
 |         // From here on, scope all operations to the current build. Within the manifest shard,
 | ||||||
|         // there's no need to check for freshness, since entries have to be fresher than the
 |         // there's no need to check for freshness, since entries have to be fresher than the
 | ||||||
|         // manifest itself.
 |         // manifest itself.
 | ||||||
|         let cache_shard = cache_shard.shard(manifest.digest()); |         let cache_shard = cache_shard.shard(manifest.id()); | ||||||
| 
 | 
 | ||||||
|         // If the cache contains compatible metadata, return it.
 |         // If the cache contains compatible metadata, return it.
 | ||||||
|         let metadata_entry = cache_shard.entry(METADATA); |         let metadata_entry = cache_shard.entry(METADATA); | ||||||
|  | @ -456,7 +456,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { | ||||||
|         // From here on, scope all operations to the current build. Within the manifest shard,
 |         // From here on, scope all operations to the current build. Within the manifest shard,
 | ||||||
|         // there's no need to check for freshness, since entries have to be fresher than the
 |         // there's no need to check for freshness, since entries have to be fresher than the
 | ||||||
|         // manifest itself.
 |         // manifest itself.
 | ||||||
|         let cache_shard = cache_shard.shard(manifest.digest()); |         let cache_shard = cache_shard.shard(manifest.id()); | ||||||
| 
 | 
 | ||||||
|         // If the cache contains a compatible wheel, return it.
 |         // If the cache contains a compatible wheel, return it.
 | ||||||
|         if let Some(built_wheel) = BuiltWheelMetadata::find_in_cache(self.tags, &cache_shard) { |         if let Some(built_wheel) = BuiltWheelMetadata::find_in_cache(self.tags, &cache_shard) { | ||||||
|  | @ -522,7 +522,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { | ||||||
|         // From here on, scope all operations to the current build. Within the manifest shard,
 |         // From here on, scope all operations to the current build. Within the manifest shard,
 | ||||||
|         // there's no need to check for freshness, since entries have to be fresher than the
 |         // there's no need to check for freshness, since entries have to be fresher than the
 | ||||||
|         // manifest itself.
 |         // manifest itself.
 | ||||||
|         let cache_shard = cache_shard.shard(manifest.digest()); |         let cache_shard = cache_shard.shard(manifest.id()); | ||||||
| 
 | 
 | ||||||
|         // If the cache contains compatible metadata, return it.
 |         // If the cache contains compatible metadata, return it.
 | ||||||
|         let metadata_entry = cache_shard.entry(METADATA); |         let metadata_entry = cache_shard.entry(METADATA); | ||||||
|  | @ -983,7 +983,7 @@ pub(crate) async fn refresh_timestamp_manifest( | ||||||
|         cache_entry.path(), |         cache_entry.path(), | ||||||
|         rmp_serde::to_vec(&CachedByTimestamp { |         rmp_serde::to_vec(&CachedByTimestamp { | ||||||
|             timestamp: modified.timestamp(), |             timestamp: modified.timestamp(), | ||||||
|             data: manifest, |             data: manifest.clone(), | ||||||
|         })?, |         })?, | ||||||
|     ) |     ) | ||||||
|     .await?; |     .await?; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Charlie Marsh
						Charlie Marsh