mirror of
				https://github.com/astral-sh/uv.git
				synced 2025-10-31 12:06:13 +00:00 
			
		
		
		
	Stylize Requires-Python consistently (#5304)
				
					
				
			This commit is contained in:
		
							parent
							
								
									07d038b90c
								
							
						
					
					
						commit
						3e067766de
					
				
					 8 changed files with 17 additions and 17 deletions
				
			
		|  | @ -173,7 +173,7 @@ impl SimpleHtml { | ||||||
|         let filename = urlencoding::decode(filename) |         let filename = urlencoding::decode(filename) | ||||||
|             .map_err(|_| Error::UnsupportedFilename(filename.to_string()))?; |             .map_err(|_| Error::UnsupportedFilename(filename.to_string()))?; | ||||||
| 
 | 
 | ||||||
|         // Extract the `requires-python` field, which should be set on the
 |         // Extract the `requires-python` value, which should be set on the
 | ||||||
|         // `data-requires-python` attribute.
 |         // `data-requires-python` attribute.
 | ||||||
|         let requires_python = if let Some(requires_python) = |         let requires_python = if let Some(requires_python) = | ||||||
|             link.attributes().get("data-requires-python").flatten() |             link.attributes().get("data-requires-python").flatten() | ||||||
|  |  | ||||||
|  | @ -829,7 +829,7 @@ impl std::fmt::Display for PubGrubHint { | ||||||
|             } => { |             } => { | ||||||
|                 write!( |                 write!( | ||||||
|                     f, |                     f, | ||||||
|                     "{}{} The `Requires-Python` requirement ({}) includes Python versions that are not supported by your dependencies (e.g., {} only supports {}). Consider using a more restrictive `Requires-Python` requirement (like {}).", |                     "{}{} The `requires-python` value ({}) includes Python versions that are not supported by your dependencies (e.g., {} only supports {}). Consider using a more restrictive `requires-python` value (like {}).", | ||||||
|                     "hint".bold().cyan(), |                     "hint".bold().cyan(), | ||||||
|                     ":".bold(), |                     ":".bold(), | ||||||
|                     requires_python.bold(), |                     requires_python.bold(), | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ pub struct RequiresPython { | ||||||
|     /// The supported Python versions as provides by the user, usually through the `requires-python`
 |     /// The supported Python versions as provides by the user, usually through the `requires-python`
 | ||||||
|     /// field in `pyproject.toml`.
 |     /// field in `pyproject.toml`.
 | ||||||
|     ///
 |     ///
 | ||||||
|     /// For a workspace, it's the union of all `requires-python` fields in the workspace. If no
 |     /// For a workspace, it's the union of all `requires-python` values in the workspace. If no
 | ||||||
|     /// bound was provided by the user, it's greater equal the current Python version.
 |     /// bound was provided by the user, it's greater equal the current Python version.
 | ||||||
|     specifiers: VersionSpecifiers, |     specifiers: VersionSpecifiers, | ||||||
|     /// The lower bound from the `specifiers` field, i.e. greater or greater equal the lowest
 |     /// The lower bound from the `specifiers` field, i.e. greater or greater equal the lowest
 | ||||||
|  |  | ||||||
|  | @ -224,13 +224,13 @@ pub(super) async fn do_lock( | ||||||
|         if requires_python.is_unbounded() { |         if requires_python.is_unbounded() { | ||||||
|             let default = |             let default = | ||||||
|                 RequiresPython::greater_than_equal_version(&interpreter.python_minor_version()); |                 RequiresPython::greater_than_equal_version(&interpreter.python_minor_version()); | ||||||
|             warn_user!("The workspace `requires-python` field does not contain a lower bound: `{requires_python}`. Set a lower bound to indicate the minimum compatible Python version (e.g., `{default}`)."); |             warn_user!("The workspace `requires-python` value does not contain a lower bound: `{requires_python}`. Set a lower bound to indicate the minimum compatible Python version (e.g., `{default}`)."); | ||||||
|         } |         } | ||||||
|         requires_python |         requires_python | ||||||
|     } else { |     } else { | ||||||
|         let default = |         let default = | ||||||
|             RequiresPython::greater_than_equal_version(&interpreter.python_minor_version()); |             RequiresPython::greater_than_equal_version(&interpreter.python_minor_version()); | ||||||
|         warn_user!("No `requires-python` field found in the workspace. Defaulting to `{default}`."); |         warn_user!("No `requires-python` value found in the workspace. Defaulting to `{default}`."); | ||||||
|         default |         default | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -274,7 +274,7 @@ fn assert_pin_compatible_with_project(pin: &Pin, virtual_project: &VirtualProjec | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     Err(anyhow::anyhow!( |     Err(anyhow::anyhow!( | ||||||
|         "The {given} Python version `{}`{resolved} is incompatible with the {} `Requires-Python` requirement of `{}`.", |         "The {given} Python version `{}`{resolved} is incompatible with the {} `requires-python` value of `{}`.", | ||||||
|         pin.request.to_canonical_string(), |         pin.request.to_canonical_string(), | ||||||
|         project_type, |         project_type, | ||||||
|         requires_python |         requires_python | ||||||
|  |  | ||||||
|  | @ -111,7 +111,7 @@ fn init_no_readme() -> Result<()> { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
| fn current_dir() -> Result<()> { | fn init_current_dir() -> Result<()> { | ||||||
|     let context = TestContext::new("3.12"); |     let context = TestContext::new("3.12"); | ||||||
| 
 | 
 | ||||||
|     let dir = context.temp_dir.join("foo"); |     let dir = context.temp_dir.join("foo"); | ||||||
|  |  | ||||||
|  | @ -2295,7 +2295,7 @@ fn lock_requires_python() -> Result<()> { | ||||||
|               And because project==0.1.0 depends on pygls>=1.1.0, we can conclude that project==0.1.0 cannot be used. |               And because project==0.1.0 depends on pygls>=1.1.0, we can conclude that project==0.1.0 cannot be used. | ||||||
|               And because only project==0.1.0 is available and you require project, we can conclude that the requirements are unsatisfiable. |               And because only project==0.1.0 is available and you require project, we can conclude that the requirements are unsatisfiable. | ||||||
| 
 | 
 | ||||||
|               hint: The `Requires-Python` requirement (>=3.7) includes Python versions that are not supported by your dependencies (e.g., pygls>=1.1.0,<=1.2.1 only supports >=3.7.9, <4). Consider using a more restrictive `Requires-Python` requirement (like >=3.7.9, <4). |               hint: The `requires-python` value (>=3.7) includes Python versions that are not supported by your dependencies (e.g., pygls>=1.1.0,<=1.2.1 only supports >=3.7.9, <4). Consider using a more restrictive `requires-python` value (like >=3.7.9, <4). | ||||||
|         "###);
 |         "###);
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -3119,7 +3119,7 @@ fn lock_requires_python_unbounded() -> Result<()> { | ||||||
| 
 | 
 | ||||||
|         ----- stderr ----- |         ----- stderr ----- | ||||||
|         warning: `uv lock` is experimental and may change without warning |         warning: `uv lock` is experimental and may change without warning | ||||||
|         warning: The workspace `requires-python` field does not contain a lower bound: `<=3.12`. Set a lower bound to indicate the minimum compatible Python version (e.g., `>=3.11`). |         warning: The workspace `requires-python` value does not contain a lower bound: `<=3.12`. Set a lower bound to indicate the minimum compatible Python version (e.g., `>=3.11`). | ||||||
|         Resolved 2 packages in [TIME] |         Resolved 2 packages in [TIME] | ||||||
|         "###);
 |         "###);
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -250,7 +250,7 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { | ||||||
|     ----- stdout ----- |     ----- stdout ----- | ||||||
| 
 | 
 | ||||||
|     ----- stderr ----- |     ----- stderr ----- | ||||||
|     error: The requested Python version `3.10` is incompatible with the project `Requires-Python` requirement of `>=3.11`. |     error: The requested Python version `3.10` is incompatible with the project `requires-python` value of `>=3.11`. | ||||||
|     "###);
 |     "###);
 | ||||||
| 
 | 
 | ||||||
|     // Request a implementation version that is incompatible
 |     // Request a implementation version that is incompatible
 | ||||||
|  | @ -260,7 +260,7 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { | ||||||
|     ----- stdout ----- |     ----- stdout ----- | ||||||
| 
 | 
 | ||||||
|     ----- stderr ----- |     ----- stderr ----- | ||||||
|     error: The requested Python version `cpython@3.10` is incompatible with the project `Requires-Python` requirement of `>=3.11`. |     error: The requested Python version `cpython@3.10` is incompatible with the project `requires-python` value of `>=3.11`. | ||||||
|     "###);
 |     "###);
 | ||||||
| 
 | 
 | ||||||
|     // Request a complex version range that resolves to an incompatible version
 |     // Request a complex version range that resolves to an incompatible version
 | ||||||
|  | @ -271,7 +271,7 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { | ||||||
|     Pinned `.python-version` to `>3.8, <3.11` |     Pinned `.python-version` to `>3.8, <3.11` | ||||||
| 
 | 
 | ||||||
|     ----- stderr ----- |     ----- stderr ----- | ||||||
|     warning: The requested Python version `>3.8, <3.11` resolves to `3.10.[X]` which  is incompatible with the project `Requires-Python` requirement of `>=3.11`. |     warning: The requested Python version `>3.8, <3.11` resolves to `3.10.[X]` which  is incompatible with the project `requires-python` value of `>=3.11`. | ||||||
|     "###);
 |     "###);
 | ||||||
| 
 | 
 | ||||||
|     uv_snapshot!(context.filters(), context.python_pin().arg("3.11"), @r###" |     uv_snapshot!(context.filters(), context.python_pin().arg("3.11"), @r###" | ||||||
|  | @ -321,7 +321,7 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { | ||||||
|     cpython@3.11 |     cpython@3.11 | ||||||
| 
 | 
 | ||||||
|     ----- stderr ----- |     ----- stderr ----- | ||||||
|     warning: The pinned Python version `cpython@3.11` is incompatible with the project `Requires-Python` requirement of `>=3.12`. |     warning: The pinned Python version `cpython@3.11` is incompatible with the project `requires-python` value of `>=3.12`. | ||||||
|     "###);
 |     "###);
 | ||||||
| 
 | 
 | ||||||
|     // Request a implementation that resolves to a compatible version
 |     // Request a implementation that resolves to a compatible version
 | ||||||
|  | @ -332,7 +332,7 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { | ||||||
|     Updated `.python-version` from `cpython@3.11` -> `cpython` |     Updated `.python-version` from `cpython@3.11` -> `cpython` | ||||||
| 
 | 
 | ||||||
|     ----- stderr ----- |     ----- stderr ----- | ||||||
|     warning: The requested Python version `cpython` resolves to `3.10.[X]` which  is incompatible with the project `Requires-Python` requirement of `>=3.12`. |     warning: The requested Python version `cpython` resolves to `3.10.[X]` which  is incompatible with the project `requires-python` value of `>=3.12`. | ||||||
|     "###);
 |     "###);
 | ||||||
| 
 | 
 | ||||||
|     uv_snapshot!(context.filters(), context.python_pin(), @r###" |     uv_snapshot!(context.filters(), context.python_pin(), @r###" | ||||||
|  | @ -342,7 +342,7 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { | ||||||
|     cpython |     cpython | ||||||
| 
 | 
 | ||||||
|     ----- stderr ----- |     ----- stderr ----- | ||||||
|     warning: The pinned Python version `cpython` resolves to `3.10.[X]` which  is incompatible with the project `Requires-Python` requirement of `>=3.12`. |     warning: The pinned Python version `cpython` resolves to `3.10.[X]` which  is incompatible with the project `requires-python` value of `>=3.12`. | ||||||
|     "###);
 |     "###);
 | ||||||
| 
 | 
 | ||||||
|     // Request a complex version range that resolves to a compatible version
 |     // Request a complex version range that resolves to a compatible version
 | ||||||
|  | @ -353,7 +353,7 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { | ||||||
|     Updated `.python-version` from `cpython` -> `>3.8, <3.12` |     Updated `.python-version` from `cpython` -> `>3.8, <3.12` | ||||||
| 
 | 
 | ||||||
|     ----- stderr ----- |     ----- stderr ----- | ||||||
|     warning: The requested Python version `>3.8, <3.12` resolves to `3.10.[X]` which  is incompatible with the project `Requires-Python` requirement of `>=3.12`. |     warning: The requested Python version `>3.8, <3.12` resolves to `3.10.[X]` which  is incompatible with the project `requires-python` value of `>=3.12`. | ||||||
|     "###);
 |     "###);
 | ||||||
| 
 | 
 | ||||||
|     uv_snapshot!(context.filters(), context.python_pin(), @r###" |     uv_snapshot!(context.filters(), context.python_pin(), @r###" | ||||||
|  | @ -363,7 +363,7 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { | ||||||
|     >3.8, <3.12 |     >3.8, <3.12 | ||||||
| 
 | 
 | ||||||
|     ----- stderr ----- |     ----- stderr ----- | ||||||
|     warning: The pinned Python version `>3.8, <3.12` resolves to `3.10.[X]` which  is incompatible with the project `Requires-Python` requirement of `>=3.12`. |     warning: The pinned Python version `>3.8, <3.12` resolves to `3.10.[X]` which  is incompatible with the project `requires-python` value of `>=3.12`. | ||||||
|     "###);
 |     "###);
 | ||||||
| 
 | 
 | ||||||
|     Ok(()) |     Ok(()) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zanie Blue
						Zanie Blue