@@ -52,6 +52,7 @@ pub use crate::any::*;
52
52
pub use crate :: buildable:: * ;
53
53
pub use crate :: cached:: * ;
54
54
pub use crate :: dependency_metadata:: * ;
55
+ pub use crate :: derivation:: * ;
55
56
pub use crate :: diagnostic:: * ;
56
57
pub use crate :: error:: * ;
57
58
pub use crate :: file:: * ;
@@ -74,6 +75,7 @@ mod any;
74
75
mod buildable;
75
76
mod cached;
76
77
mod dependency_metadata;
78
+ mod derivation;
77
79
mod diagnostic;
78
80
mod error;
79
81
mod file;
@@ -166,14 +168,21 @@ impl std::fmt::Display for InstalledVersion<'_> {
166
168
/// Either a built distribution, a wheel, or a source distribution that exists at some location.
167
169
///
168
170
/// The location can be an index, URL or path (wheel), or index, URL, path or Git repository (source distribution).
169
- #[ derive( Debug , Clone , Hash ) ]
171
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
170
172
pub enum Dist {
171
173
Built ( BuiltDist ) ,
172
174
Source ( SourceDist ) ,
173
175
}
174
176
177
+ /// A reference to a built or source distribution.
178
+ #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
179
+ pub enum DistRef < ' a > {
180
+ Built ( & ' a BuiltDist ) ,
181
+ Source ( & ' a SourceDist ) ,
182
+ }
183
+
175
184
/// A wheel, with its three possible origins (index, url, path)
176
- #[ derive( Debug , Clone , Hash ) ]
185
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
177
186
#[ allow( clippy:: large_enum_variant) ]
178
187
pub enum BuiltDist {
179
188
Registry ( RegistryBuiltDist ) ,
@@ -182,7 +191,7 @@ pub enum BuiltDist {
182
191
}
183
192
184
193
/// A source distribution, with its possible origins (index, url, path, git)
185
- #[ derive( Debug , Clone , Hash ) ]
194
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
186
195
#[ allow( clippy:: large_enum_variant) ]
187
196
pub enum SourceDist {
188
197
Registry ( RegistrySourceDist ) ,
@@ -193,15 +202,15 @@ pub enum SourceDist {
193
202
}
194
203
195
204
/// A built distribution (wheel) that exists in a registry, like `PyPI`.
196
- #[ derive( Debug , Clone , Hash ) ]
205
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
197
206
pub struct RegistryBuiltWheel {
198
207
pub filename : WheelFilename ,
199
208
pub file : Box < File > ,
200
209
pub index : IndexUrl ,
201
210
}
202
211
203
212
/// A built distribution (wheel) that exists in a registry, like `PyPI`.
204
- #[ derive( Debug , Clone , Hash ) ]
213
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
205
214
pub struct RegistryBuiltDist {
206
215
/// All wheels associated with this distribution. It is guaranteed
207
216
/// that there is at least one wheel.
@@ -231,7 +240,7 @@ pub struct RegistryBuiltDist {
231
240
}
232
241
233
242
/// A built distribution (wheel) that exists at an arbitrary URL.
234
- #[ derive( Debug , Clone , Hash ) ]
243
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
235
244
pub struct DirectUrlBuiltDist {
236
245
/// We require that wheel urls end in the full wheel filename, e.g.
237
246
/// `https://example.org/packages/flask-3.0.0-py3-none-any.whl`
@@ -243,7 +252,7 @@ pub struct DirectUrlBuiltDist {
243
252
}
244
253
245
254
/// A built distribution (wheel) that exists in a local directory.
246
- #[ derive( Debug , Clone , Hash ) ]
255
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
247
256
pub struct PathBuiltDist {
248
257
pub filename : WheelFilename ,
249
258
/// The absolute path to the wheel which we use for installing.
@@ -253,7 +262,7 @@ pub struct PathBuiltDist {
253
262
}
254
263
255
264
/// A source distribution that exists in a registry, like `PyPI`.
256
- #[ derive( Debug , Clone , Hash ) ]
265
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
257
266
pub struct RegistrySourceDist {
258
267
pub name : PackageName ,
259
268
pub version : Version ,
@@ -272,7 +281,7 @@ pub struct RegistrySourceDist {
272
281
}
273
282
274
283
/// A source distribution that exists at an arbitrary URL.
275
- #[ derive( Debug , Clone , Hash ) ]
284
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
276
285
pub struct DirectUrlSourceDist {
277
286
/// Unlike [`DirectUrlBuiltDist`], we can't require a full filename with a version here, people
278
287
/// like using e.g. `foo @ https://github.com/org/repo/archive/master.zip`
@@ -288,7 +297,7 @@ pub struct DirectUrlSourceDist {
288
297
}
289
298
290
299
/// A source distribution that exists in a Git repository.
291
- #[ derive( Debug , Clone , Hash ) ]
300
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
292
301
pub struct GitSourceDist {
293
302
pub name : PackageName ,
294
303
/// The URL without the revision and subdirectory fragment.
@@ -300,7 +309,7 @@ pub struct GitSourceDist {
300
309
}
301
310
302
311
/// A source distribution that exists in a local archive (e.g., a `.tar.gz` file).
303
- #[ derive( Debug , Clone , Hash ) ]
312
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
304
313
pub struct PathSourceDist {
305
314
pub name : PackageName ,
306
315
/// The absolute path to the distribution which we use for installing.
@@ -312,7 +321,7 @@ pub struct PathSourceDist {
312
321
}
313
322
314
323
/// A source distribution that exists in a local directory.
315
- #[ derive( Debug , Clone , Hash ) ]
324
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
316
325
pub struct DirectorySourceDist {
317
326
pub name : PackageName ,
318
327
/// The absolute path to the distribution which we use for installing.
@@ -512,12 +521,33 @@ impl Dist {
512
521
}
513
522
}
514
523
524
+ /// Returns the version of the distribution, if it is known.
515
525
pub fn version ( & self ) -> Option < & Version > {
516
526
match self {
517
527
Self :: Built ( wheel) => Some ( wheel. version ( ) ) ,
518
528
Self :: Source ( source_dist) => source_dist. version ( ) ,
519
529
}
520
530
}
531
+
532
+ /// Convert this distribution into a reference.
533
+ pub fn as_ref ( & self ) -> DistRef {
534
+ match self {
535
+ Self :: Built ( dist) => DistRef :: Built ( dist) ,
536
+ Self :: Source ( dist) => DistRef :: Source ( dist) ,
537
+ }
538
+ }
539
+ }
540
+
541
+ impl < ' a > From < & ' a SourceDist > for DistRef < ' a > {
542
+ fn from ( dist : & ' a SourceDist ) -> Self {
543
+ DistRef :: Source ( dist)
544
+ }
545
+ }
546
+
547
+ impl < ' a > From < & ' a BuiltDist > for DistRef < ' a > {
548
+ fn from ( dist : & ' a BuiltDist ) -> Self {
549
+ DistRef :: Built ( dist)
550
+ }
521
551
}
522
552
523
553
impl BuiltDist {
0 commit comments