File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,27 @@ impl FromStr for PythonVersion {
31
31
if version. epoch ( ) != 0 {
32
32
return Err ( format ! ( "Python version `{s}` has a non-zero epoch" ) ) ;
33
33
}
34
+ if let Some ( major) = version. release ( ) . first ( ) {
35
+ if u8:: try_from ( * major) . is_err ( ) {
36
+ return Err ( format ! (
37
+ "Python version `{s}` has an invalid major version ({major})"
38
+ ) ) ;
39
+ }
40
+ }
41
+ if let Some ( minor) = version. release ( ) . get ( 1 ) {
42
+ if u8:: try_from ( * minor) . is_err ( ) {
43
+ return Err ( format ! (
44
+ "Python version `{s}` has an invalid minor version ({minor})"
45
+ ) ) ;
46
+ }
47
+ }
48
+ if let Some ( patch) = version. release ( ) . get ( 2 ) {
49
+ if u8:: try_from ( * patch) . is_err ( ) {
50
+ return Err ( format ! (
51
+ "Python version `{s}` has an invalid patch version ({patch})"
52
+ ) ) ;
53
+ }
54
+ }
34
55
35
56
Ok ( Self ( version) )
36
57
}
Original file line number Diff line number Diff line change @@ -364,6 +364,26 @@ dependencies = ["flask==1.0.x"]
364
364
Ok ( ( ) )
365
365
}
366
366
367
+ #[ test]
368
+ fn invalid_python_version ( ) {
369
+ let context = TestContext :: new ( "3.12" ) ;
370
+
371
+ uv_snapshot ! ( context. filters( ) , context. pip_install( )
372
+ . arg( "flask" )
373
+ . arg( "--python-version" )
374
+ . arg( "311" ) , @r"
375
+ success: false
376
+ exit_code: 2
377
+ ----- stdout -----
378
+
379
+ ----- stderr -----
380
+ error: invalid value '311' for '--python-version <PYTHON_VERSION>': Python version `311` has an invalid major version (311)
381
+
382
+ For more information, try '--help'.
383
+ "
384
+ ) ;
385
+ }
386
+
367
387
#[ test]
368
388
fn missing_pip ( ) {
369
389
uv_snapshot ! ( Command :: new( get_bin( ) ) . arg( "install" ) , @r###"
You can’t perform that action at this time.
0 commit comments